Skip to main content
Topic: Audio Summing Algorithm (Read 10637 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Audio Summing Algorithm


I'm a newbie in digital audio programming. Can anyone point me to an article/formula on how to mix two or more audio streams together? It's probably very simple, but I haven't found anything via Google/Bing.

I'm operating on 32-bit floats on a Mac and managing my own audio callback loop (not using Core Audio mixer objects)


- Nick -

Audio Summing Algorithm

Reply #1
This doesn't belong in the MP3 forum...

As your title says, you just sum the samples.  If you want to mix streams A & B, you simply sum the corresponding samples:  A1+B1=C1, A2+C2=B2... An+Bn=Cn...

Of course, both streams must have the same sample rate (and with integer formats, both must have the same bit-depth) before you sum. 

With integer formats you have to scale the input streams before summing (i.e. divide by 2), or you need to allow for larger numbers (more bits) in the output stream.    Even with 32-bit floating point, you'll normally want to scale before or after mixing to avoid clipping.  (The 32-bit data won't clip, but you can clip the DAC output.)

And frequently with audio mixing, you'll want to scale the input levels because you don't always want a 1:1 mix...  You may want one signal to be louder in the mix.

There is a FREE online DSP (Digital Signal Processing) book at (I don't know if there is an example of mixing in that book.)
I have Digital Audio Processing, by Doug Coulter, which seems to be one of the few books dedicated to audio-related DSP.

You may also want to download & study the Audacity[/color] surce code.

Audio Summing Algorithm

Reply #3
Thanks guys.

I just couldn't believe it was that simple. Sorry for throlling this forum.

Audio Summing Algorithm

Reply #4
As long as you stay in floating-point, and especially as long as you do not use recursive summing (ie IIR filtering), you basically have nothing to worry about.

SimplePortal 1.0.0 RC1 © 2008-2020