Low frequency oscillator for automating Web Audio API AudioParams.
Low frequency oscillator for automating Web Audio API AudioParams.
$ npm install lfo
var LFO = require('lfo')
Returns an LFO AudioNode instance.
Modulate this base value
based on operation specified by node.mode
.
Oscillation rate in cycles per second (Hz).
Amplitude of the oscillation.
The operation to apply to node.value
. Defaults to `'multiply'.
The waveform shape: 'sine', 'triangle', 'sawtooth', 'sawtooth_i' or 'square'
When true
, the oscillation rate is multiplied by node.tempo / 60
to allow beat sync.
Set the tempo (BPM) for use when node.sync
is true
.
Connect the modulator to the desired destination audio param.
Disconnect from any target AudioParams.
Starts the LFO at specified time. This method can only be called once. Create new instances of LFO for each scheduled events.
Stops the LFO at specified time.
Create tremolo effect
var LFO = require('lfo')
var audioContext = new AudioContext()
var oscillator = audioContext.createOscillator()
var gain = audioContext.createGain()
oscillator.connect(gain)
gain.connect(audioContext.destination)
var lfoModulator = LFO(audioContext)
gain.value = 2 // set oscillation centre value
lfoModulator.rate = 4 // hz
lfoModulator.shape = 'sine'
lfoModulator.connect(gain.gain)
lfoModulator.start(audioContext.currentTime)
oscillator.start(audioContext.currentTime)
lfoModulator.stop(audioContext.currentTime + 1)
oscillator.stop(audioContext.currentTime + 1)