我尝试将 2 个 16 位线性 PCM 音频流混合在一起,但似乎无法克服噪音问题。我认为它们是在将样品混合在一起时溢出的。
我有以下功能...
short int mix_sample(short int sample1, short int sample2)
{
return #mixing_algorithm#;
}
...这是我尝试过的#mixing_algorithm#
sample1/2 + sample2/2
2*(sample1 + sample2) - 2*(sample1*sample2) - 65535
(sample1 + sample2) - sample1*sample2
(sample1 + sample2) - sample1*sample2 - 65535
(sample1 + sample2) - ((sample1*sample2) >> 0x10) // same as divide by 65535
其中一些产生了比其他更好的结果,但即使是最好的结果也包含相当多的噪音。
有什么想法如何解决吗?
我找到的最好的解决方案是由维克托·托特提供 http://www.vttoth.com/CMS/index.php/technical-notes/68。他为 8 位无符号 PCM 提供了一个解决方案,并将其更改为 16 位有符号 PCM,结果如下:
int a = 111; // first sample (-32768..32767)
int b = 222; // second sample
int m; // mixed result will go here
// Make both samples unsigned (0..65535)
a += 32768;
b += 32768;
// Pick the equation
if ((a < 32768) || (b < 32768)) {
// Viktor's first equation when both sources are "quiet"
// (i.e. less than middle of the dynamic range)
m = a * b / 32768;
} else {
// Viktor's second equation when one or both sources are loud
m = 2 * (a + b) - (a * b) / 32768 - 65536;
}
// Output is unsigned (0..65536) so convert back to signed (-32768..32767)
if (m == 65536) m = 65535;
m -= 32768;
使用这一算法意味着几乎不需要对输出进行裁剪,因为它只有一个值未在范围内。与直接平均不同,即使一个源静音,另一个源的音量也不会降低。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)