-
-
Notifications
You must be signed in to change notification settings - Fork 285
Audio Effects
Phil Schatzmann edited this page Jan 11, 2023
·
27 revisions
AudioEffectStream is the starting class to manage different type of audio effects (Distortion, Boost, Chorus etc). In the constructor of the AudioEffectStream class we pass the input stream (or output stream) to which we apply the effects. Here is an example how to set up the different objects:
#include "AudioTools.h"
SineWaveGenerator<int16_t> sine;
GeneratedSoundStream<int16_t> sine_stream(sine);
AudioEffectStream effects(sine_stream);
I2SStream out;
StreamCopy copier(out, effects);
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);
sine_stream.begin(cfg);
effects.begin(cfg);
...
}
In the loop you can just drive the output of the generated sound:
// copy the data
void loop() {
copier.copy();
}
We can use any Stream as input:
AudioKitStream kit;
AudioEffectStream effects(kit);
We can also apply the effects on the output side by writing the audio data to the AudioEffectStream:
#include "AudioTools.h"
SineWaveGenerator<int16_t> sine;
GeneratedSoundStream<int16_t> sine_stream(sine);
I2SStream out;
AudioEffectStream effects(out);
StreamCopy copier(effects, sine_stream);