Re: [linux-audio-dev] [newbie] mixing audio streams

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

Subject: Re: [linux-audio-dev] [newbie] mixing audio streams
From: Alex Marandon (al_AT_alpage.org)
Date: Sun Mar 14 2004 - 12:54:53 EET


On Sat, Mar 13, 2004 at 06:49:25PM +0100, Jan Weil wrote:
> [snip clipping problem]
> > /* -- mixage, cf. http://www.vttoth.com/digimix.htm -- */
> > for ( i = 0; i <= BUFFER_SIZE; i++ ) {
> > mixed_buffer[i]
> > = buffer1[i] + buffer2[i] - buffer1[i] * buffer2[i] / DYNAMIC_RANGE;
> > }
>
> buffer1 is declared as a short (i. e. usually 16 bits).
> I'd guess this introduces your clipping problems.
> Try this instead:
>
> mixed_buffer[i] = buffer1[i] + buffer2[i] -
> (long) buffer1[i] * buffer2[i] / DYNAMIC_RANGE;

Thanks for your answer. It was actually a mistake, but the alogrithm
itself is also intrinsically wrong because when input values are high,
it produces an output which is over the range of signed short integers.
So when it's converted to integers it makes number of the opposite sign.

I whish I did more maths when I was in school :o)

I've made some tries with simply dividing the sum of samples by the
number of sample (ie: buffer1[i] + buffer2[i] / 2) and the result is not
so bad.


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

This archive was generated by hypermail 2b28 : Sun Mar 14 2004 - 12:56:20 EET