Re: Play multiple sounds concurrently

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Markus Luttenberger wrote:
> I want to play multiple sounds concurrently with ALSA. The audio data is 
> mono and G.711 a-law encoded. I can successfully play a single source of 
> audio data but the sound is distorted when I try to play two sources.
> 
>    wr_buf[count] = (char) (0.5 * buf1[count]) +
>                    (char) (0.5 * buf2[count]);

A-law is a somewhat logarithmic encoding; simply adding two values with
linear scale factors will not work.

If both your source data and the output device use A-law, you have to
decode the samples to linear PCM, add them, and encode them back.  See
<http://git.alsa-project.org/?p=alsa-lib.git;a=blob;f=src/pcm/pcm_alaw.c;hb=HEAD>
for the algorithm that alsa-lib uses; you would use something like
buf[] = s16_to_alaw((alaw_to_s16(buf1[]) + alaw_to_s16(buf2[])) / 2);

If it is possible for your output device to use a linear PCM format,
you might want to use that to avoid the additional encoding step.


HTH
Clemens
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux