我正在尝试制作自己的基本混音器,并想知道如何获取多个输入音频通道并将所有通道作为一个混合音频源输出,每个输入通道的电平均可控。现在我正在尝试使用 pyo 但我无法实时混合频道。
问问题
550 次
1 回答
0
这是一些将多个输入通道组合成单个输出通道的伪代码,其中每个输入通道在数组 mix_volume 中都有自己的音量控制
max_index = length(all_chan[0]) // identify audio buffer size
all_chan // assume all channels live in a two dimensional array where
// dimension 0 is which channel and dim 1 is index into each audio sample
mix_volume // array holding multiplication factor to control volume per channel
// each element a floating point value between 0.0 and 1.0
output_chan // define and/or allocate your output channel buffer
for index := 0; index < max_index; index++ {
curr_sample := 0 // output audio curve height for current audio sample
for curr_chan := 0; curr_chan < num_channels; curr_chan++ {
curr_sample += (all_chan[curr_chan][index] * mix_volume[curr_chan])
}
output_chan[index] = curr_sample / num_channels // output audio buffer
}
在实时流上执行上述操作的技巧是在事件循环中填充上述 all_chan 音频缓冲区,您可以在其中将每个通道的音频样本值复制到这些缓冲区中,然后从该事件循环内部执行上述代码......通常你会想要您的音频缓冲区有大约 2^12 ( 4096 ) 个音频样本...尝试使用更大或更小的缓冲区大小...太小,此事件循环将变得非常 cpu 密集但又太大,您将产生可听见的延迟.. 。 玩得开心
你可能想使用像 golang YMMV 这样的编译语言
于 2020-04-09T18:23:20.480 回答