# How can I add a sound wave on top of an existing one, without harming the original's loudness?

I'm working on a program that has to do with adding sound waves on top of sound waves. Currently what I'm doing is simply an average of the two waves. So if I have wave A, and I want to write wave B 'on top' of it, every sample in the new A is equal to the average of two matching samples in the original waves.

This works decently, however sometimes it leads to a significant decrease of loudness in wave A. Is there a better way to combine sound waves?

For example, if I have a sound wave of a guitar playing, I want to be able to add on top of it a sound wave of a saxophone playing, without decreasing the volume of the guitar. What's the best way to do this?

• I think this is off topic here, but if so we could migrate it to Signal Processing. – David Z Mar 27 '15 at 17:04
• Why not just sum them, rather than average them? – CR Drost Mar 27 '15 at 18:02
• Do all the math in floating point, and normalize the data when it comes time to write ints to the output file. – Solomon Slow Mar 27 '15 at 20:04
• Bear in mind that sounds can mask one another. This is an effect of human perception of sound. However, people do not notice this as a rule, so I doubt it's an issue for you. See en.wikipedia.org/wiki/Auditory_masking – user27118 Mar 27 '15 at 20:09

• not (necessarily) the total loudness (that of A and B together). but yes, it would reduce the loudness of wave A. the point is that there are reasons (not "no reason") to average or to use AGC or level compression. – robert bristow-johnson Mar 28 '15 at 17:02