Home

Awesome

smoothfade

npm version

Smooth fading of volume (gain) in WebAudio is possible with parameter automation on the GainNode.

However, currently, there is no easy way to stop and change (for eg. reverse) an automation smoothly. Once an AudioParam is automated, there is no easy way to know it's value at a given point of time except for calculating it manually using the automation equations. Hence stopping and reversing the automation is not trivial.

This JSFiddle shows the various techniques that don't work for smooth fading, and finally the calculation based technique which does.

This library does the calculation and allows fading in/out smoothly.

Usage

npm install smoothfade
// wrap the smoothfade around a gain node

var sm = smoothfade(context, gain);


// use fadeIn/fadeOut functions to
// fadeIn/fadeOut the audio.

sm.fadeIn();

sm.fadeOut();

API

Constructor

eg: var sm = smoothfade(context, gainNode, options);

Methods

License

Apache-2.0

See License file