h1jnmg
Last Updated: February 25, 2016
·
3.761K
· mattdiamond
85c9c2cf9e82e4be7663df11da6f16f2

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
sine.connect(sineGain);
sineGain.connect(saw.frequency);
Say Thanks
Respond

2 Responses
Add your response

7069
Ab3ada15fcb862a4558a56e245c2bf71

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

over 1 year ago ·
17887
None

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 ·