将多个输入通道组合为一个输出通道音频直播



我正在尝试制作自己的基本混音器,并想知道如何将多个声道的输入音频作为一个混合音频源输出,每个输入声道的音量可控。现在我正在尝试使用pyo,但我无法实时混合频道。

这里有一些伪代码,可以将多个输入通道组合为一个输出通道,其中每个输入通道在阵列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
}

在直播流上执行上述操作的技巧是在事件循环中填充上述allchan音频缓冲区,将每个通道的音频采样值复制到这些缓冲区中,然后在该事件循环中执行上述代码。。。通常你会希望你的音频缓冲区有大约2^12(4096(个音频样本。。。使用较大或较小的缓冲区大小进行实验。。。太小,这个事件循环将变得非常占用cpu,但太大,您将产生可听见的延迟。。。玩得开心

您可能想要使用像golang YMMV 这样的编译语言

最新更新