Re: LPCM Downmix Algorithm problem
Re: LPCM Downmix Algorithm problem
- Subject: Re: LPCM Downmix Algorithm problem
- From: Bob Ingraham <email@hidden>
- Date: Sat, 14 Aug 2010 21:47:40 -0600
Fair enough (yes, I should have run a few numbers through that one.)
So, here;s the issues: I have signed 16-bit integers (-32768 to 32767) representing a quantized wave form (below / above x-axis) and I want to add these "waves" together.
So, I started out with (assuming 2:1 down-mix):
Mixed-Sample = Sample1 + Sample2
But this produces overflow/underflow and I assumed that just allowing an overflow/underflow to "wrap" according to the rules of signed 16-bit integer arithmetic doesn't produce a correct result.
So I tried, in an attempt to "re-scale" the resultant sum back into the 16-bit domain:
Mixed-Sample = (Sample1 + Sample2) / 2
But this doesn't work either.
So, how does one properly model the addition of two-or-more sound waves, represented in digital LPCM?
How do you handle overflow/underflow?
Just clamp values outside the range to the max value (i.e., values over 32767 are set to 32767)?
That doesn't seem to scale well when mixing more channels. In the app I'm working on, I need to mix up to 8 channels together. In that extreme case, the resultant summed "waveform" will certainly be outside the valid sample-value range.
Or does one apply some scaling factor based on the total number of channels being down-mixed together?
If so, how does one derive said scaling factor?
Scaling seems to make the most sense. I'd hoped my research would have turned-up some well-known way to down-mix LPCM samples, but I haven't found anything definitive.
Bob
On Sat, Aug 14, 2010 at 9:00 PM, Steve Bird
<email@hidden> wrote:
On Aug 14, 2010, at 10:48 PM, Bob Ingraham wrote:
> Ok, so one last time, because code is fairly simple, like my brain:
>
> To mix two 16-bit-signed samples:
>
> MixedSample = Sample1 + Sample2 - (Sample1 * Sample2);
---- I don't know where you got that algorithm, but apply a little brainpower to it:
If Sample1 is 10000 and Sample2 is 10000 then you're going to subtract 100,000,000 from the sum?
That will have a hard time fitting into a 16-bit word.
----------------------------------------------------------------
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
www.Culverson.com (toll free) 1-877-676-8175
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden