Algorithm to mix sound

后端 未结 20 2112
囚心锁ツ
囚心锁ツ 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:10

    You can also buy yourself some headroom with an algorithm like y= 1.1x - 0.2x^3 for the curve, and with a cap on the top and bottom. I used this in Hexaphone when the player is playing multiple notes together (up to 6).

    float waveshape_distort( float in ) {
      if(in <= -1.25f) {
        return -0.984375;
      } else if(in >= 1.25f) {
        return 0.984375;
      } else {    
        return 1.1f * in - 0.2f * in * in * in;
      }
    }
    

    It's not bullet-proof - but will let you get up to 1.25 level, and smoothes the clip to a nice curve. Produces harmonic distortion, which sounds better than clipping and may be desirable in some circumstances.

提交回复
热议问题