Re: Sound and mixing channels question
From: MSCHAEF.COM (mschaef_at_fnord.io.com)
Date: 02/29/04
- Next message: Phlip: "Re: Test-Driven Development"
- Previous message: Edward G. Nilges: "Re: Arthur O'Dwyer on the feasibility of simulating a Turing Machine"
- In reply to: Mats: "Sound and mixing channels question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 28 Feb 2004 21:00:27 -0600
In article <JSa0c.50722$mU6.204665@newsb.telia.net>,
Mats <spamenot.mog.pettersson@telia.com> wrote:
...
>My question is though if say, you have a one byte per sample (or 8 bit
>per sample if you like) buffer and mixes say two channels into that
>buffer, the code i've seen just adds the two channels, but what happens
>if one or several bytes overflow? The output of say 240+128 is 368 which
>would set the mixed byte to 368-256=112?!? Wouldn't this distort the sound?
Yes, there'd be an incredible amount of distortion. One way to begin to
handle this is via saturation arithmetic. Rather than overflowing and
wrapping around as in your example, it caps the result at the maximum
representable value. This has the effect of clipping the tops of the
waveforms, which is more analagous to what happens in actual analog audio
hardware.
Of course, this still is pretty severe distortion, and the best way to
handle that is via mixing your sound in such a way that it does not
overflow at all. However, if you lower the amplitudes of the waveforms
before you add them together, you're throwing away information. It's
better to cast to a wider type, add the samples, and than scale down. I've
used double precision floats for this to good effect, but my application
was very lightweight.
-Mike
-- http://www.mschaef.com
- Next message: Phlip: "Re: Test-Driven Development"
- Previous message: Edward G. Nilges: "Re: Arthur O'Dwyer on the feasibility of simulating a Turing Machine"
- In reply to: Mats: "Sound and mixing channels question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|