Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Web Audio API Tone Generator With Gain Control

This is a basic Tone Generator wrapped in a class. It uses the Oscillator node from the Web Audio API.

- Some examples show using :

gainNode.gain.value = ###

Doing that can cause popping/crackling sounds on every change. It's especially bad using an input range slider.

The [TODO: Code shorthand span ] show above prevents that. It's sent the target gain, a startTime, and a timeConstant. By setting the startTime to .currentTime() the change starts to take place immediately. The timeConstant defines an "exponential approach" to the target gain. Using a low value like "0.01" make it happen fast enough that it feels instant.

Footnotes And References