webaudio-chnl
v0.0.8
Published
Chnl - one channel, all effects.
Downloads
5
Readme
Chnl - one channel, all effects.
Why would I ever want a Chnl?
I needed something with a LOT of audio effects integrated which can be manipulated in many different aspects. And I needed to use this in many different ways: Every native AudioNode should be able to connect to it as it would be a normal AudioNode, but also other Chnls should be able to connect to another Chnl. So I could simply and intuitively create audio graphs with a set of effects. No matter if I connect a song, mic input or even a synthesizer.
Therefore I created Chnl.
Installation
Via npm
npm i webaudio-chnl -S
Usage
It's really simple. And intuitive.
Creating a Chnl
You can create a new Chnl instance by constructing the Chnl-class with your AudioContext object as the 1° parameter.
new Channel(audioCtx)
Effects
You have access to a lot of effects. Under the hood, Chnl uses the webaudio-effect-units-collection module. So you have access to a lot of effects which can be enabled and disabled.
You can access the effects with the effects property of your Chnl instance.
Example
const channel = new Chnl(audioCtx);
const {
gain,
chorus,
delay,
phaser,
overdrive,
compressor,
lowpass,
highpass,
tremolo,
wahwah,
bitcrusher,
moog,
pingPongDelay
} = channel.effects;
gain.setValue('gain', 0.55);
delay.addEffect('delay');
delay.setValue('feedback', 0.2);
Connecting
Connect to a Chnl
You can connect any normal AudioNode to a Chnl:
const channel = new Chnl(audioCtx);
const gain = audioCtx.createGain();
gain.connect(channel);
But you can also connect a Chnl to a normal AudioNode:
const channel = new Chnl(audioCtx);
const gain = audioCtx.createGain();
channel.connect(gain);
You can even connect one Chnl to another one:
const channel1 = new Chnl(audioCtx);
const channel2 = new Chnl(audioCtx);
channel1.connect(channel2);
Have fun connecting!
Activating an effect (since v0.0.6)
Per default, no effect is connected in the interior audio graph. In previous versions, this was the case. I decided to revise the way how effects are used. Because if all effects are initially actively connected, there's way more needless audio processing (also if the effects are initially turned off). Therefore I decided to connect the effects only if they are explicitly needed.
TLDR: Before using an effect, you need to activate it. When activating an effect, the whole audiograph will be rebuilt.
Note: The 'gain'-effect is already activated by default.
Example:
const chnl = new Chnl(audioCtx);
chnl.addEffect('delay');
chnl.addEffect('chorus');
chnl.effects.delay.setValue('delayTime', 500);
Disabling an effect (since v0.0.6)
Since you can activate an effect, it's no surprise that you can also disable the same effect. When you disable an effect, it will be removed from the audiograph to prevent needless processing. Example:
const chnl = new Chnl(audioCtx);
chnl.addEffect('delay');
chnl.effects.delay.setValue('delayTime', 500);
chnl.removeEffect('chorus');
Final example
This a bit more advanced example, which connects an oscillator to a Chnl and applies some effects.
const audioCtx = new AudioContext();
const chnl = new Chnl(audioCtx);
const osci = audioCtx.createOscillator();
osci.frequency.value = 300;
osci.connect(chnl);
chnl.connect(audioCtx.destination);
// Activate effects
chnl.addEffect('highpass');
chnl.addEffect('bitcrusher');
chnl.effects.gain.setValue('gain', 0.2);
chnl.effects.highpass.setValue('frequency', 500);
chnl.effects.bitcrusher.setValue('bits', 4);
osci.start();