Re: [linux-audio-dev] Combining audio streams

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] Combining audio streams
From: Steve Harris (S.W.Harris_AT_ecs.soton.ac.uk)
Date: Fri Feb 08 2002 - 17:57:51 EET


On Fri, Feb 08, 2002 at 04:37:56 +0100, Christian Naeger wrote:
>
> If there are say two input streams, and I simply add the 16bit shorts from
> both streams, I get lots and lots of overflows. If I divide each stream by
> two before adding them, it sounds very bad.

You are probably causing an overflow in your maths, something like this
should work fine:

   short out, in1, in2;
   int tmp = (in1 + in2) / 2;

   if (tmp > SHTR_MAX) {
     out = SHRT_MAX;
   } else if (tmp < SHRT_MIN) {
     out = SHRT_MIN;
   } else {
     out = tmp;
   }

If your hearing is very good then you could be hearing distorion from the
bottom bit, in which case you will need to dither the audio, but that
is a whole lot harder.

- Steve


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Fri Feb 08 2002 - 17:48:32 EET