-2

I have developed the Synchronous Audio Interface (SAI) driver for a proprietary Real-Time Operating System (RTOS) using C language. My driver is configured to output left and right channel data (I2S) to the amplifier. But, since the amplifier attached is mono, it only outputs left or right channel audio data to the speaker. Now, i have a stereo PCM 16-bit audio data file and i want to somehow mix the left and right channel audio data in my application and send it to either of the left or right channel in the SAI driver. In this way, i will be able to play combined stereo audio data as mono on the speaker attached to the mono amplifier.

Can anyone suggest me that what's the best possible solution to do it?

Mahad
  • 1
  • 1
  • 3
    _I am trying to_. and _I am using C as my development language_. Show your try. – ryyker May 12 '20 at 12:47
  • @ryyker My apologies, i should have been more clearer of what i am trying to ask. I have updated my question. I dont have an actual implementation of the answer i am looking for. I am looking for 'how' we can achieve the above mentioned scenario. – Mahad May 13 '20 at 07:25
  • 1
    ¿average right and left? `right/2 + left/2` prevents possible overflow in `(right + left)/2` – pmg May 13 '20 at 07:59
  • It's not need to explain your problem 3 or 4 times in the same paragraph. In addition, it's unclear if you have as input a file or two signal (i.e a stereo signal) – Welgriv May 14 '20 at 09:26
  • @pmg Thanks for your answer. Does averaging the left and right channel data have any impact on the quality of the sound being played as output? – Mahad May 14 '20 at 13:56
  • @Welgriv Yeah, while editing the question previously, i added repetitive information. I have made my question concise now. And the input is a raw stereo audio file being read in a software buffer. – Mahad May 14 '20 at 13:59
  • @Mahad Do you really care about quality when you want to transform a sound from stereo to mono ? If the mix of your input file is stereo mixing them even using a analog circuit will give a poor quality. If the mix is not a real stereo (i.e channel left and right are the same) then their will be no impact at all, but mixing the signal is useless. However it is a bit out of topic since your question does not ask for quality issue. – Welgriv May 14 '20 at 16:16
  • @Welgriv Yeah, agreed. Given my question, i wanted to have best possible solution with minimal effect on the quality of sound. I just want to know that what sort of impact will be there when channels are averaged? It seems like major impact will be on the loudness of sound. – Mahad May 14 '20 at 19:54

1 Answers1

0

As said in a comment, the usual way to mix two stereo channels in a mono one is to divide the sample of each channel by 2 and add them.

Example in C like :

int left_channel_sample, right_channel_sample;
int mono_channel = (left_channel_sample / 2) + ( right_channel_sample / 2);

You mentioned some driver you coded, modify it or add some new feature. Can't really help more given the mess of your question...

Welgriv
  • 714
  • 9
  • 24