Issue with mixed generated noise output after mixed mp3 stops playing #2195
-
As a prefix, I'm new to this library, ESP32 in general and even coding with C, so please excuse my inexperience. This might be an expected behavior, but I want to check before I try to solve the issue on my own. I'm working on a project where I would add "radio noise" to mp3 files stored on SD card, my project is not too dissimilar from @alastaira's London Calling Prop. The project uses the A1S audiokit board. My current approach is to generate static noise and mix it with an mp3 file stored on SD card. I achieved this with the below code based on this discussion. The code mixes noise with the mp3 file as expected, but when the mp3 file has finished playing the noise turns into a clicking sound. I would expect the noise to keep playing as normal after the file has finished. Is this clicking sound/change to the noise output an expected behavior or a bug?
#include <SPI.h>
#include <SD.h>
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
const int chipSelect=PIN_AUDIO_KIT_SD_CARD_CS;
File audioFile;
AudioBoardStream i2s(AudioKitEs8388V1); // final output of decoded stream
InputMixer<int16_t> mixer;
EncodedAudioStream decoder(&i2s, new MP3DecoderHelix());
PinkNoiseGenerator<int16_t> Noise;
GeneratedSoundStream<int16_t> NoiseIn(Noise);
VolumeStream volumeSong(decoder);
VolumeStream volumeNoise(NoiseIn);
StreamCopy copier(i2s, mixer);
// Arduino Setup
void setup(void) {
Serial.begin(115200);
while (!Serial)
;
auto config = i2s.defaultConfig(TX_MODE);
config.sd_active = true;
i2s.begin(config);
SD.begin(chipSelect);
audioFile = SD.open("/test2.mp3");
if (!audioFile) {
Serial.println("Failed to open MP3 file!");
stop();
return;
} else {
Serial.println("Opened the MP3 file");
}
Serial.println("Card Mount succeeded");
NoiseIn.begin(config);
Noise.begin();
volumeSong.setVolume(0.8);
volumeSong.begin();
volumeNoise.setVolume(0.3);
volumeNoise.begin();
decoder.setStream(audioFile);
decoder.transformationReader().setResultQueueFactor(14);
decoder.begin();
mixer.add(volumeSong);
mixer.add(volumeNoise);
mixer.begin(config);
copier.begin();
}
void loop() {
copier.copy();
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Please follow the advice given here |
Beta Was this translation helpful? Give feedback.
-
In my suggestion above, I was recommending to use the OutputMixer which gives you more control and flexibility. Can you provide a short example that demonstrates your issue ? |
Beta Was this translation helpful? Give feedback.
-
Did you try something like the following: void setup() {
mixer.setLimitToAvailableData(true); // no output when file has ended
}
void loop() {
if (!copier.copy()){
mixer.remove();
Serial.println("MP3 playback finished, removed from mixer.");
}
} |
Beta Was this translation helpful? Give feedback.
Please follow the advice given here