Algorithm to mix sound

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

    I did the following thing:

    MAX_VAL = Full 8 or 16 or whatever value
    dst_val = your base audio sample
    src_val = sample to add to base
    
    Res = (((MAX_VAL - dst_val) * src_val) / MAX_VAL) + dst_val
    

    Multiply the left headroom of src by the MAX_VAL normalized destination value and add it. It will never clip, never be less loud and sound absolutely natural.

    Example:

    250.5882 = (((255 - 180) * 240) / 255) + 180
    

    And this sounds good :)

提交回复
热议问题