mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-26 03:23:11 +00:00
feat: sampler no longer quantizes to nearest semitone but can work between pitches
fixes #447
This commit is contained in:
parent
de95b27af0
commit
4435329b03
1 changed files with 5 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
import { ToneAudioBuffer } from "../core/context/ToneAudioBuffer";
|
||||
import { ToneAudioBuffers } from "../core/context/ToneAudioBuffers";
|
||||
import { intervalToFrequencyRatio } from "../core/type/Conversions";
|
||||
import { ftomf, intervalToFrequencyRatio } from "../core/type/Conversions";
|
||||
import { FrequencyClass } from "../core/type/Frequency";
|
||||
import { Frequency, Interval, MidiNote, NormalRange, Note, Time } from "../core/type/Units";
|
||||
import { optionsFromArguments } from "../core/util/Defaults";
|
||||
|
@ -176,12 +176,14 @@ export class Sampler extends Instrument<SamplerOptions> {
|
|||
notes = [notes];
|
||||
}
|
||||
notes.forEach(note => {
|
||||
const midi = new FrequencyClass(this.context, note).toMidi();
|
||||
const midiFloat = ftomf(new FrequencyClass(this.context, note).toFrequency());
|
||||
const midi = Math.round(midiFloat) as MidiNote;
|
||||
const remainder = midiFloat - midi;
|
||||
// find the closest note pitch
|
||||
const difference = this._findClosest(midi);
|
||||
const closestNote = midi - difference;
|
||||
const buffer = this._buffers.get(closestNote);
|
||||
const playbackRate = intervalToFrequencyRatio(difference);
|
||||
const playbackRate = intervalToFrequencyRatio(difference + remainder);
|
||||
// play that note
|
||||
const source = new ToneBufferSource({
|
||||
url: buffer,
|
||||
|
|
Loading…
Reference in a new issue