Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Markus Luttenberger <m.luttenberger@avibit.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: Play multiple sounds concurrently
Date: Fri, 18 Dec 2009 15:02:51 +0100	[thread overview]
Message-ID: <4B2B8B8B.505@ladisch.de> (raw)
In-Reply-To: <4B2B873E.6010906@avibit.com>

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

      reply	other threads:[~2009-12-18 14:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-18 13:44 Play multiple sounds concurrently Markus Luttenberger
2009-12-18 14:02 ` Clemens Ladisch [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B2B8B8B.505@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=m.luttenberger@avibit.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox