-
Notifications
You must be signed in to change notification settings - Fork 58
Tutorials: Using Effects
jussi-kalliokoski edited this page Sep 8, 2011
·
3 revisions
In this tutorial, we're going to go a bit further than in the Tutorials: Getting Started as we're going to add a delay effect to our tone, and we're going to change it from a sine tone to a triangle tone.
audiolib.js has a built-in BufferEffect class that handles things for creating multichannel effects that can be applied on buffers. Most of the effects operate on single sample single sample basis by default, but they have a .createBufferBased()
function so that you can create these buffer based effects.
var dev, osc, delay;
function audioCallback(buffer, channelCount){
// Fill the buffer with the oscillator output.
osc.append(buffer, channelCount);
delay.append(buffer);
}
window.addEventListener('load', function(){
// Create an instance of the AudioDevice class
dev = audioLib.AudioDevice(audioCallback /* callback for the buffer fills */, 2 /* channelCount */);
// Create an instance of the Oscillator class
osc = audioLib.Oscillator(dev.sampleRate /* sampleRate */, 440 /* frequency */);
// Create an instance of the Delay class
delay = audioLib.Delay.createBufferBased(2 /* channelCount */, dev.sampleRate, 400 /* delay time (in ms) */);
// Set the oscillator wave shape.
osc.waveShape = 'triangle';
}, true);
Back to Tutorials