-
-
Notifications
You must be signed in to change notification settings - Fork 309
Convert stereo to 2-ch mono for DAC. #2161
-
Hardware: 2 x ICS-43434 mics, ESP32, HiLetgo PCM5102 DAC, audio amp.
Software: ESP 32 Dev Module, Audio Tools 1.1.2 (Aug 2025), Arduino 1.8.19
I have the mics connected to I2S port 0 on an ESP32 and the goal is to balance the L/R mics and convert to a mono stream that feeds a 2-ch DAC on I2S port 1.
2 x mics input -> Equalizer -> Volume/balance -> convert stereo to mono -> 2-ch DAC
This works fine except sounds come out on left speaker only, even though I had config_out.channels=2. Tried wrapping a 2-ch FormatConverterStream around the mono stream but compiler disallowed copy constructor. Have tried other classes mentioned in wiki but due to my lack of knowledge I have no success. Would appreciate some pointers on the correct way to convert the mono stream to
feed the stereo DAC thanks.
streams-i2s-test.ino.txt
Beta Was this translation helpful? Give feedback.
All reactions
Check the documentation of the FormatConverterStream: you are converting to mono!
So the sketch is absolutley doing what you specified...
I also think your sketch has some bug, since you are setting up some objects with the wrong channel information: all before the converter is mono, so you should use info_mono!
Replies: 4 comments 1 reply
-
Check the documentation of the FormatConverterStream: you are converting to mono!
So the sketch is absolutley doing what you specified...
I also think your sketch has some bug, since you are setting up some objects with the wrong channel information: all before the converter is mono, so you should use info_mono!
Beta Was this translation helpful? Give feedback.
All reactions
-
I'll check again but I'm quite sure my mics are stereo. I configured the ICS-43434 mics as per documentation ie left SEL tied to GND, right SEL tied to VCC. This allows audio to come into ESP32 as stereo. I'm using FormatConverterStream to mix the L/R mic signals and then output mono to both channels of the DAC. The end-goal is to have the mono sound coming out from left and right speakers. But I'm stuck at the stage of trying to duplicate the mono output to both DAC channels.
Beta Was this translation helpful? Give feedback.
All reactions
-
OK, I see you configured "in" as stereo. Not sure what the ICS-43434 is doing in this case, but other I2S microphones would provide a stereo signal, with one channel filled and one empty.
Test this with a CSVOuput sketch!
If this is the case it would be better to define them as mono and to a stereo conversion. Another option would be to just copy the channel with the signal to the empty channel with a ConverterFillLeftAndRight
Beta Was this translation helpful? Give feedback.
All reactions
-
Good suggestion thanks. So I made a minimal sketch with sine/CsvOutput and got stereo-mono-stereo conversion going after some work.
Background:
I'm making an audio system for my friend who plays an accordion. Left mic is attached to the bass section and right mic to melody section. However it is undesirable for the audience to hear bass and melody notes on separate speakers. Hence they are blended into a mono stream then output to left/right speakers so they both sound the same.
Sketch
#include "AudioTools.h"
AudioInfo info(44100,2,16);
AudioInfo info_mono(44100,1,16);
SineWaveGenerator<int16_t> sineWave;
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
CsvOutput<int16_t> out(Serial);
FormatConverterStream monoToStereoConverter(out);
FormatConverterStream stereoToMonoConverter;
//FormatConverterStream stereoToMonoConverter(monoToStereoConverter);
//Fail: use of deleted function 'audio_tools::FormatConverterStream::FormatConverterStream(audio_tools::FormatConverterStream&)'
StreamCopy copier(stereoToMonoConverter, sound);
void setup(void) {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
out.begin(info);
sineWave.begin(info, N_B4);
stereoToMonoConverter.begin(info, info_mono); // downmix stereo to mono
monoToStereoConverter.begin(info_mono,info); // duplicate mono to 2 channels
stereoToMonoConverter.setStream(monoToStereoConverter);
}
void loop() {
copier.copy();
delay(200);
}
Output
SineStereoFinal question - code below failed to compile:
FormatConverterStream stereoToMonoConverter(monoToStereoConverter);
Fail: use of deleted function 'audio_tools::FormatConverterStream::FormatConverterStream(audio_tools::FormatConverterStream&)'
As a workaround, I used setStream() but should it be able to wrap like the rest?
Beta Was this translation helpful? Give feedback.
All reactions
-
I committed a correction to support FormatConverterStream stereoToMonoConverter(monoToStereoConverter); now as well
Beta Was this translation helpful? Give feedback.