BB.AFX
a base module for creating more complicated audio effects (as AFX addons) in the style of BB.AudioFX
Index
Methods
- BB.AFX constructor
- connect
- disconnect
- setDryGain
- setGain
- setWetGain
Constructor
BB.AFX
(
-
config
)
-
config
Parameters:
-
config
ObjectA config object to initialize the effect
Example:
here is an example of a basic addon audio effect, we'll call it AFXname.js
( in this case nothing really, just a simple delay ), extended from BB.AFX
function AFXname( config ){
BB.AFX.call(this, config);
// this.node must be some kind of AudioNode
// likely something like ConvolverNode, DelayNode, etc. ( or combo )
this.node = this.ctx.createDelay();
// initialze the input >> dry/wet >> output ( see BB.AFX._init() )
// must be called after this.node is declared
this._init();
}
AFXname.prototype = Object.create(BB.AFX.prototype);
AFXname.prototype.constructor = AFXname;
by extending from BB.AFX, our AFXname has an input && an output, as well as the delay node ( this.node above ) automatically connected to a "wet" channel ( which is inversely proportional to the "dry" channel )
view the advanced BB.AFX addons example
Properties
ctx
AudioContext
default:BB.Audio.context
the Audio Context this derived from
dry
Number
default:0
the dry channel gain/volume
gain
GainNode
private
the "output" gain node ( use .volume, .setGain() to interface with this )
volume
Number
default:1
the master volume (of output gain node)
wet
Number
default:1
the wet channel gain/volume
Methods
connect
(
-
destination
-
output
-
input
)
-
destination
-
output
-
input
connects the Noise to a particular AudioNode or AudioDestinationNode
Parameters:
-
destination
AudioNodethe AudioNode or AudioDestinationNode to connect to
-
output
Numberwhich output of the the Noise do you want to connect to the destination
-
input
Numberwhich input of the destination you want to connect the Noise to
Example:
BB.Audio.init();
var node = new BB.AudioBase({
volume: 0.75,
});
node.connect( exampleNode );
// connected to both default BB.Audio.context && exampleNode
// so if exampleNode is also connected to BB.Audio.context by default,
// ...then you've got node connected to BB.Audio.context twice
...which looks like this ( where the first Gain is the Noise and the second is the exampleNode )
disconnect
(
-
destination
-
output
-
input
)
-
destination
-
output
-
input
diconnects the Noise from the node it's connected to
Parameters:
-
destination
AudioNodewhat it's connected to
-
output
Numberthe particular output number
-
input
Numberthe particular input number
BB.Audio.init();
var node = new BB.AudioBase({
volume: 0.75,
});
node.disconnect(); // disconnected from default BB.Audio.context
node.connect( exampleNode ); // connected to exampleNode only
...which looks like this ( where the first Gain is the node and the second is the exampleNode )
setDryGain
(
-
num
-
ramp
)
-
num
-
ramp
set's the dry gain ( && adjust the wet gain accordingly, so that they total to 1 )
Parameters:
-
num
Numbera float value, 1 being the default volume, below 1 decreses the volume, above one pushes the gain
-
ramp
Numbervalue in seconds for how quickly/slowly to ramp to the new value (num) specified
Example:
BB.Audio.init();
var fx = new BB.AFX('filter');
var noise = new BB.AudioNoise({
connect: fx
});
fx.setDryGain( 0.75, 2 ); // raises dry level from 0 - 0.75 over 2 seconds (wet level drops to 0.25)
// if no ramp value is needed, you could alternatively do
fx.dry.volume = 0.75; // immediately jumps to 0.75 (and wet to 0.25)
setGain
(
-
num
-
ramp
)
-
num
-
ramp
sets the gain level of the node ( in a sense, master volume control )
Parameters:
-
num
Numbera float value, 1 being the default volume, below 1 decreses the volume, above one pushes the gain
-
ramp
Numbervalue in seconds for how quickly/slowly to ramp to the new value (num) specified
Example:
BB.Audio.init();
var node = new BB.AudioBase({
volume: 0.75
});
node.setGain( 0.25, 2 ); // lower's volume from 0.75 to 0.25 in 2 seconds
// if no ramp value is needed, you could alternatively do
node.volume = 0.5; // immediately jumps from 0.25 to 0.5
setWetGain
(
-
num
-
ramp
)
-
num
-
ramp
set's the wet gain ( && adjust the dry gain accordingly, so that they total to 1 )
Parameters:
-
num
Numbera float value, 1 being the default volume, below 1 decreses the volume, above one pushes the gain
-
ramp
Numbervalue in seconds for how quickly/slowly to ramp to the new value (num) specified
Example:
BB.Audio.init();
var fx = new BB.AFX('filter');
var noise = new BB.AudioNoise({
connect: fx
});
fx.setWetGain( 0.15, 2 ); // drops wet level from 1 - 0.15 over 2 seconds (dry level rises to 0.85)
// if no ramp value is needed, you could alternatively do
fx.wet.volume = 0.15; // immediately jumps to 0.15 (and dry to 0.85)