-
-
Notifications
You must be signed in to change notification settings - Fork 282
Audio Effects
Phil Schatzmann edited this page Mar 8, 2022
·
27 revisions
AudioEffects is the starting class to manage different type of audio effects (Distortion, Boost, Chorus etc). In the constructor of the AudioEffects class we pass the input to which we apply the effects. Finally we can use the GeneratedSoundStream class to convert the AudioEffects as an input stream source. Here is an example how to set up the different objects:
#include "AudioTools.h"
SineWaveGenerator<int16_t> sine;
AudioEffects<SineWaveGenerator<int16_t>> effects(sine);
GeneratedSoundStream<int16_t> in(effects);
I2SStream out;
StreamCopy copier(out, in);
In the setup() we then assign one or multiple Effect implementations.
ADSRGain adsr(0.0001,0.0001, 0.9 , 0.0002);
void setup() {
...
// setup effects
effects.addEffect(adsr);
// Setup output
auto cfg = i2s.defaultConfig(TX_MODE);
i2s.begin(cfg);
// Setup sound generation based on AudioKit settins
sine.begin(cfg, 0);
in.begin(cfg);
...
}
We can also use an Stream as input:
AudioKitStream kit;
AudioEffects<GeneratorFromStream<effect_t>> effects(kit,2, 1.0);
GeneratedSoundStream<int16_t> in(effects);
The 2 n the constructor indicates that the input stream has two channels and we can pass a factor to control the volume of the input.