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

Reply via email to