When two or more audio tracks are simply "added" together, they may peak at the same time, causing the resulting "sum" track to be clipped. I am looking for an algorithm or technique to bring the "sum" track back within limits, without causing too much distortion. Are there any standard ways of doing this? Please note that I'm not looking for a solution in a specific audio tool like audacity; rather, I want to understand how such tools implement track mixing.
I believe Zettt has nailed an answer (nice one Zettt). I want to extend this to a bigger picture.
There may be an algorithm but I don't know of it specifically as an equation. This is all about mixing sound tracks like you are a great chef cooking up an unbelievable dish. Start with the finest ingredients, in this case sounds you have already recorded that are clear, and do not clip at all. Your goal is to mix all the ingredients so you can taste each one without it overwhelming the others or losing its identity. This is why your ears like your taste buds will be the most important guide. Consider how a music arranger puts together a score for an orchestra. Take into account how the timbre of each instrument will have both an individual composite of harmonics and how these change over the entire instrument's range.
For instance if I was mixing violins and a triangle, I already know that a triangle has a very odd set of harmonics, and I won't have to give that track much gain at all for me to hear it clearly. You rarely see a percussionist hitting a triangle very hard because its tone is so differently constructed that a slight hit will cut through the rest of the orchestra very easily.
Mixing is not about adding one thing on top of each other, it's about balancing a blend that you can hear everything in the mix. Yes, you have to keep the gain under 0 dB, you can not have any clipping, not any or else you just burnt your dish.
You can think of the spectra envelope of each instrument as a guide but allow for your ear to tell you when it's right.
What controls do you have when you are mixing tracks?
For one you have the gain of each track, then you have where it lives in the stereo field, is it best in the center? 15% to the right, 20% to the left?
How you control the way an overall sound envelope is another factor, does it have a fast attack, does it fade away, do you want to have it ride in the distance, or bring it up front?
Another thing to think about is the depth, how much reverb if any, this will also color the sound. Notice as you add reverb you loose some highs and it sounds like it's further away, is that what you want?
Summary: Mixing sound is like making a great meal, you start with the best ingredients and allow each to stand out without overwhelming the others or getting lost. Be aware of your instruments spectra, envelopes, and how all this changes over the entire range. Be aware of what controls you do have and how these can be best set for your desired results.
Finally, don't be afraid to try new things, take risks, you can always change it back before you make your master.
Two uncorrelated signals sum up by about 3dB per additional signal (I couldn't find an English reference for this. Maybe someone else will.). To keep your sum from clipping, just turn down the volume of the individual tracks.
A digital signal always has a maximum level. If summing two tracks to one signal drives the level above this point, it will clip.
Most DAW tools I know of don't have any kind of fix for this. They will happily let you drive a signal to clipping, and leave the decisions of how to deal with this to you.
There are a few standard techniques for getting around this:
Keep in mind that compression and limiting do modify your signal, and therefore are distortions, albeit usually mild ones. Extremely compressed signals tend to sound distorted.
When you describe an algorithm to automatically reduce peaking sounds, this is the sort of thing I think of.