Re: Audio Summing Algorithm
Reply #4 – 2018-04-23 11:43:22
It's probably very simple You just add the sample values. Nothing special needed. If you exceed 1.0, you can just clip when you convert the final result to integer samples, or divide every sample in the final result so that the highest peak is 1.0. TL;DR Of course this is the simplest algorithm and if you're a newbie, stick with that. <IF YOU'RE NOT AUDIO FANATIC, DON'T READ THAT CRAZY NERDY STUFF> However, what if signals are out-of-phase? In the worst-case scenario (two inverted signals, as in attached picture) waveforms cancel each other and after down-mixing you'll hear literally NOTHING! It's intended while doing technical stuff, for example in a nulling test - if you want to check whether streams are the same, invert one of them and if you get silence, they're the same. However, if you're doing musical stuff, that effect is unwanted and this is why downmixed-to-mono music sometimes sounds a bit differently than in stereo - some frequencies are out-of-phase and they change their power after downmixing because of interference. If you want to do it really-hyper-super-good quality way, dive into advanced programming and do FFT - change the signal into frequencies creating it. After FFT simply average resulting coefficients and then do Inverse FFT - create a signal from the information about its frequencies. For example: let's see at the picture again. With normal downmixing they cancel each other, yeah? But let's FFT both signals. They both have the same frequency and the same amplitude, so FFT will show: FREQ1 blah-blah-blah, AMPL1 1.0, FREQ2 blah-blah-blah, AMPL2 1.0. FFT doesn't show info about the phase, it's ignored. Now because FREQ1 and FREQ2 are perfectly the same, wa can average the amplitudes. That's simple: average of 1.0 and 1.0 is 1.0 We get FREQ blah-blah-blah, AMPL 1.0. Then simply inverse FFT and voila, you get audibly perfect downmix - no single frequency lost its power. It's a bit nerdy, isn't it? I told you not to read that if you're newbie