我正在尝试制作自己的基本混音器,想知道如何处理多个输入音频通道,并将所有通道作为一个混合音频源输出,每个输入通道的电平均可控制。目前,我正在尝试使用Pyo,但无法实时混合频道。
答案 0 :(得分: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这样的编译语言