Skip to content

Commit

Permalink
Merge pull request #706 from Bubobubobubobubo/global-vibrato
Browse files Browse the repository at this point in the history
Adding vibrato to Superdough sampler
  • Loading branch information
felixroos authored Nov 9, 2023
2 parents 9dbd073 + 2a09f9e commit 400b210
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/superdough/sampler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const getSampleBufferSource = async (s, n, note, speed, freq, bank, resol
const bufferSource = ac.createBufferSource();
bufferSource.buffer = buffer;
const playbackRate = 1.0 * Math.pow(2, transpose / 12);
// bufferSource.playbackRate.value = Math.pow(2, transpose / 12);
bufferSource.playbackRate.value = playbackRate;
return bufferSource;
};
Expand Down Expand Up @@ -240,6 +239,8 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
begin = 0,
loopEnd = 1,
end = 1,
vib,
vibmod = 0.5,
} = value;
// load sample
if (speed === 0) {
Expand All @@ -255,6 +256,19 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {

const bufferSource = await getSampleBufferSource(s, n, note, speed, freq, bank, resolveUrl);

// vibrato
let vibratoOscillator;
if (vib > 0) {
vibratoOscillator = getAudioContext().createOscillator();
vibratoOscillator.frequency.value = vib;
const gain = getAudioContext().createGain();
// Vibmod is the amount of vibrato, in semitones
gain.gain.value = vibmod * 100;
vibratoOscillator.connect(gain);
gain.connect(bufferSource.detune);
vibratoOscillator.start(0);
}

// asny stuff above took too long?
if (ac.currentTime > t) {
logger(`[sampler] still loading sound "${s}:${n}"`, 'highlight');
Expand Down Expand Up @@ -286,6 +300,7 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
envelope.connect(out);
bufferSource.onended = function () {
bufferSource.disconnect();
vibratoOscillator?.stop();
envelope.disconnect();
out.disconnect();
onended();
Expand Down

0 comments on commit 400b210

Please sign in to comment.