0
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ I think this is off topic here, but if so we could migrate it to Signal Processing. $\endgroup$ – David Z Mar 27 '15 at 17:04
  • $\begingroup$ Why not just sum them, rather than average them? $\endgroup$ – CR Drost Mar 27 '15 at 18:02
  • $\begingroup$ Do all the math in floating point, and normalize the data when it comes time to write ints to the output file. $\endgroup$ – Solomon Slow Mar 27 '15 at 20:04
  • $\begingroup$ 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 $\endgroup$ – user27118 Mar 27 '15 at 20:09
2
$\begingroup$

You just add them. There is no reason to take an average.

$\endgroup$
4
  • $\begingroup$ except, of course, to prevent clipping/overflow or any other reason you don't want the total energy to increase as much as it would by just adding. (but i up-arrowed the answer.) $\endgroup$ – robert bristow-johnson Mar 27 '15 at 20:50
  • $\begingroup$ and it probably should be migrated to dsp.se. $\endgroup$ – robert bristow-johnson Mar 27 '15 at 20:50
  • $\begingroup$ Reducing the amplitude to prevent clipping would change the loudness. $\endgroup$ – TheBlackCat Mar 28 '15 at 16:37
  • $\begingroup$ 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. $\endgroup$ – robert bristow-johnson Mar 28 '15 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.