Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove channels from PCM

Tags:

c

audio

pcm

I have extended "libtinyalsa" (a very small version of ALSA) with a method to resample in- & outgoing PCM-audio (with libresample, e.g. from 48 kHz to 44.1 kHz).

Now I would like to extend it with a "downMixing" (is that the right word?) method.

I have 5.1 channel PCM and just need 2 channel stereo audio (left & right):

  • is "downMixing" the right word?
  • how can I do this in C?

I have no real knowledge about C and PCM - simple answers would be really welcome.

With kind regards & thanks in advance!

like image 808
Martin L. Avatar asked Dec 31 '25 10:12

Martin L.


1 Answers

I believe downmixing a 5.1 PCM stream to stereo could be done something like this:

L = clamp((FL + RL + C*0.708 + LFE*0.708) / 2) 
R = clamp((FR + RR + C*0.708 + LFE*0.708) / 2)

You can refer e.g. to the downmix effect in Android for an example of this.

Or just select two of the channels that you will keep (e.g. FL and FR) and skip past the samples from the other channels.

like image 157
Michael Avatar answered Jan 02 '26 01:01

Michael