Mixing Audio Input with effect #1870
-
Hello, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
There is quite a lot going on and it is diffcult to say what the issue is. It would also be a bit more efficient if you get rid of the VolumeStream and just rely on adjusting weights of the mixer instead. Finally I suggest to comment out the effects.addEffect(fuzz); so that you can check if the mixing of the clean signal via the 2 paths is working at all since the current setup relys on quite a lot of magic. |
Beta Was this translation helpful? Give feedback.
-
I was playing around with your sketch, and I know now what's going wrong: the OutputMixer exptects identical write sizes of the different inputs: unfortunately it is not really defined how each component submits it's samples to the output: this could be in individual samples! This can be fixed by adding a BufferedStream into the chain which makes sure that the data is written only when the buffer size is reached! Here is the adampted example that works for a LyraT: #include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioSTK.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
AudioInfo info(44100, 2, 16);
AudioBoardStream i2s(LyratV43); // or use I2SStream
MultiOutput split;
OutputMixer<int16_t> mixer(i2s, 2); // output mixer with 2 outputs mixing to AudioBoardStream
BufferedStream effects_buffer(1024, mixer);
BufferedStream direct_buffer(1024, mixer);
AudioEffectStream effects(effects_buffer);
StreamCopy copier(split, i2s, 1024); // copy i2sStream to csvStream
Fuzz fuzz(6.5, 500);
STKChorus chorus(6000);
PitchShift pitch(0.5);
Boost boost(1.0);
// Arduino Setup
void setup(void) {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// setup multioutput
split.add(effects);
split.add(direct_buffer);
// setup effects
//effects.addEffect(fuzz);
//effects.addEffect(chorus);
//effects.addEffect(boost);
//effects.addEffect(pitch);
effects.begin(info);
auto cfg = i2s.defaultConfig(RXTX_MODE);
cfg.copyFrom(info);
cfg.sd_active = false;
cfg.input_device = ADC_INPUT_LINE2;
cfg.buffer_size = 256;
cfg.buffer_count = 3;
i2s.begin(cfg);
i2s.setVolume(1.0);
//mixer.setWeight(0, 1.0);
//mixer.setWeight(1, 0.0);
mixer.begin(1024);
}
// Arduino loop - copy data
void loop() {
copier.copy();
}
ps. I have the gut feeling that the direct_buffer is not really necessary and could be omitted. I reduced the buffer size in i2s to minimize the lag. It would also be a good idea to replace the 1024 which are scattered across the sketch with a constant and maybe reduce the value a bit. |
Beta Was this translation helpful? Give feedback.
-
I haven't looked into the implementation of the STK effects. The lag is most likely caused by the i2s buffers, so try to keep them low.... |
Beta Was this translation helpful? Give feedback.
I was playing around with your sketch, and I know now what's going wrong: the OutputMixer exptects identical write sizes of the different inputs: unfortunately it is not really defined how each component submits it's samples to the output: this could be in individual samples! This can be fixed by adding a BufferedStream into the chain which makes sure that the data is written only when the buffer size is reached!
Here is the adampted example that works for a LyraT: