Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Audio Summing Algorithm (Read 12556 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Audio Summing Algorithm

Hi,

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)

Thanks,

- 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.


FYI -
There is a FREE online DSP (Digital Signal Processing) book at DSPguide.com. (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.