Skip to contentSkip to conversation

How to mix two PCM channels with ALSA

DISCUSSION itxEpsilon 2 participants 4 messages Dec 6, 2012

lore
Share & tools
lore

itxEpsilon

author
#0 lore raw

Dear Alsa developers:

I'm trying to write a simple application for mixing two PCM sound channels in C++. Could anyone provide me a quick example about how to implement this operation?

Thank you in advance.
Itx

#1 lore raw
Quoted 5 lines · itxEpsilon

I'm trying to write a simple application for mixing two PCM sound channels in C++. Could anyone provide me a quick example about how to implement this operation?

  outputSample[i] = inputChannel1[i] + inputChannel2[i];

What does this have to do with ALSA?

Regards,
Clemens

author
#2 lore raw
Quoted 8 lines · Clemens Ladisch <clemens <at> ladisch.de> writes:
Quoted 5 lines · itxEpsilon

I'm trying to write a simple application for mixing two PCM sound channels in C++. Could anyone provide me a quick example about how to implement this operation?

Quoted 7 lines
  outputSample[i] = inputChannel1[i] + inputChannel2[i];

What does this have to do with ALSA?

Regards,
Clemens

Hi,
That's no my question, I'd like to know how is performed with the ALSA API.

i.e.

playSound(buffer1);
playSound(buffer2);

is it implicitly mixed when playing two buffers by hardware?

Thanks.
Carlos.

#3 lore raw
Quoted 6 lines · itxEpsilon

I'd like to know how is performed with the ALSA API.

playSound(buffer1);
playSound(buffer2);

is it implicitly mixed when playing two buffers by hardware?

Yes, if the hardware actually support this (nowadays, none does), or if ALSA is configured to use software mixing through dmix or PulseAudio (which are enabled by default in most distributions).

Regards,
Clemens