-
-
Notifications
You must be signed in to change notification settings - Fork 326
ChannelSplitOutput not extracting exact mono audio from stereo source. #2228
-
Hardware: ESP32-S3-Supermini
Software: ESP32S3 Module, Audio Tools 1.2.0, Arduino 2.3.6
To test the new ChannelSplitOutput class, I used a sine-to-serial sketch to convert the stereo output into 2 mono signals. However, the serial plotter shows 2 channels slightly diverging from each other and the serial output confirms the discrepancy in values. Note, the 2 lines do converge now and then before diverging again.
ChannelSplitOutput
ChannelSplitOutput_serial
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);
ChannelSplitOutput stereoToMonoConverter(out,0);
StreamCopy copier(stereoToMonoConverter, sound);
void setup(void) {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
out.begin(info);
sineWave.begin(info, N_B4);
stereoToMonoConverter.addOutput(out,1);
stereoToMonoConverter.begin(info_mono);
}
void loop() {
copier.copy();
delay(200);
}
As a comparison with FormatConverterStream class, the L/R channels in the plot overlay each other exactly so that only 1 line is seen. The serial output also shows same values for both channels.
FormatConverterStream
FormatConverterStream_serial
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;
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);
}
Beta Was this translation helpful? Give feedback.
All reactions
Actually the issue is, that you use the ChannelSplitOutput to send the output to the same output: this is not supported!
You would need to send them to separate output objects!
This is writing the first 1k of data of the left channel followed by the next 1k of data of the right channel and then you print the first sample of the left channel as left channel sample and the second sample of the left channel as right channel sample....
You could try to make the copy size the sample size, but this will be very inefficient....
Replies: 2 comments
-
Actually the issue is, that you use the ChannelSplitOutput to send the output to the same output: this is not supported!
You would need to send them to separate output objects!
This is writing the first 1k of data of the left channel followed by the next 1k of data of the right channel and then you print the first sample of the left channel as left channel sample and the second sample of the left channel as right channel sample....
You could try to make the copy size the sample size, but this will be very inefficient....
Beta Was this translation helpful? Give feedback.
All reactions
-
Ok thanks, my misunderstanding of the ChannelSplitOutput class usage.
On a separate note, I noticed a slight phase shift between the L/R channel output waveform if I wrap stereoToMonoConverter around monoToStereoConverter (compare the screenshot above and below). Commenting out the delay(200) in the loop made no difference.
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(monoToStereoConverter);
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
}
void loop() {
copier.copy();
delay(200);
}
Beta Was this translation helpful? Give feedback.