I have two raw sound streams that I need to add together. For the purposes of this question, we can assume they are the same bitrate and bit depth (say 16 bit sample, 44.1k
I cannot believe that nobody knows the correct answer. Everyone is close enough but still, a pure philosophy. The nearest, i.e. the best was: (s1 + s2) -(s1 * s2). It's excelent approach, especially for MCUs.
So, the algorithm goes:
factor = average(s1)
You assume that both signals are already OK, not overflowing the 32767.0s1 = (s1/max(s1))*factor
s2 = (s2/max(s2))*factor
output = ((s1+s2)/max(s1+s2))*factor
Note that after the step 1. you don't really need to turn back to integers, you may work with floats in -1.0 to 1.0 interval and apply the return to integers at the end with the previously chosen power factor. I hope I didn't mistake now, cause I'm in a hurry.