Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ChannelSplitOutput not extracting exact mono audio from stereo source. #2228

Answered by pschatzmann
alw1746 asked this question in Q&A
Discussion options

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);
}
You must be logged in to vote

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

Comment options

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....

You must be logged in to vote
0 replies
Answer selected by pschatzmann
Comment options

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);
}

FormatConverterStream_wrap

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /