Skip to content

Instantly share code, notes, and snippets.

@beefchimi
Last active November 6, 2017 20:50
Show Gist options
  • Save beefchimi/dae0fa17761a7c19deb1fdcfcee3a4bc to your computer and use it in GitHub Desktop.
Save beefchimi/dae0fa17761a7c19deb1fdcfcee3a4bc to your computer and use it in GitHub Desktop.
Vibrato method
const defaultLFO = {
type: 'sine',
freq: 12,
volume: 40,
};
// Uses same `duration` as "source" oscillator
vibrato(duration, options = {}) {
const config = Object.assign(defaultLFO, options);
this.lfo = this.context.createOscillator();
this.lfoGainNode = this.context.createGain();
this.lfo.type = config.type;
this.lfo.frequency.value = config.freq;
// Volume will control the intensity of the effect
this.lfoGainNode.gain.value = config.volume;
// Instead of connecting the LFO to the AudioContext.destination,
// we connect it to the "source" oscillator's frequency instead
this.lfo.connect(this.lfoGainNode);
this.lfoGainNode.connect(this.oscillator.frequency);
this.lfo.start();
this.lfo.stop(duration);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment