Algorithm to mix sound

You should add them together, but clip the result to the allowable range to prevent over/underflow.

In the event of the clipping occuring, you will introduce distortion into the audio, but that’s unavoidable. You can use your clipping code to “detect” this condition and report it to the user/operator (equivalent of red ‘clip’ light on a mixer…)

You could implement a more “proper” compressor/limiter, but without knowing your exact application, it’s hard to say if it would be worth it.

If you’re doing lots of audio processing, you might want to represent your audio levels as floating-point values, and only go back to the 16-bit space at the end of the process. High-end digital audio systems often work this way.

Leave a Comment