Last Updated: February 25, 2016
· mattdiamond

Web Audio API - Modulating AudioParams with other nodes

Using the output of one audio node to modulate the value of an AudioParam is super easy... just use .connect to connect the node to the AudioParam!

For example, to create a sawtooth wave with vibrato:

var saw = context.createOscillator(),
      sine = context.createOscillator(),
      sineGain = context.createGainNode();

//set up our oscillator types
saw.type = saw.SAWTOOTH;
sine.type = sine.SINE;

//set the amplitude of the modulation
sineGain.gain.value = 10;

//connect the dots

2 Responses
Add your response

hi! and which one you connect to the audioContext.destination?

over 1 year ago ·

Thanks for this I was struggling to get vibrato until you demonstrated that gain (AKA depth) could be greater than one.

One thing to note is that you probably want to connect to saw.detune not saw.frequency so that the vibrato is consistent across the frequency range (which is nonlinear, e.g., a few Hz difference on the low notes is much more perceivable than high notes).

@alfonsofonso you want to connect the saw to the destination (erm no date on these comments so you may have already figured it out :-) )

over 1 year ago ·