Algorithm to mix sound

后端 未结 20 2054
囚心锁ツ
囚心锁ツ 2020-11-29 16:55

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

20条回答
  •  渐次进展
    2020-11-29 17:19

    convert the samples to floating point values ranging from -1.0 to +1.0, then:

    out = (s1 + s2) - (s1 * s2);

    Will introduce heavy distortion when |s1 + s2| approach 1.0 (at least when I tried it when mixing simple sine waves). I read this recommendation on several locations, but in my humble opinion, it is a useless approach.

    What happens physically when waves 'mix' is that their amplitutes add, just like many of the posters here suggested already. Either

    • clip (distorts the result as well) or
    • summarize your 16 bit values into a 32 bit number, and then divide by the number of your sources (that's what I would suggest as it's the only way known to me avoiding distortions)

提交回复
热议问题