-
-
Notifications
You must be signed in to change notification settings - Fork 237
Audio Effects
pschatzmann edited this page Feb 12, 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);
This is applying the effects on the audio provided by the microphone of the AudioKit.
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);
- Currently we support only an input and output with a bits_per_sample = 16 (=int16_t)
- The Effects work only on one channel, so if you provide 2 channels, the are combined before applying the effects and then are replicated to give the correct channels as output