我正在实现音频数据的实时线性插值,这些数据存储在交错的音频缓冲区中。音频文件可以是单声道或多声道。在单声道音频文件的情况下,我插入如下:
f_dex = offset + ((position / oldlength) * (newlength * b_channelcount));
i_dex = trunc(f_dex); // get truncated index
fraction = f_dex - i_dex; // calculate fraction value for interpolation
b_read = (b_sample[i_dex] + fraction * (b_sample[i_dex + b_channelcount] - b_sample[i_dex]));
outsample_left += b_read;
outsample_right += b_read;这听起来很棒,我没有任何问题。然而,当我想要读取多通道文件时,我必须纠正计算出的读取位置,以确保它在相应帧中的第一个样本上,例如:
f_dex = offset + ((position / oldlength) * (newlength * b_channelcount));
if ((long)trunc(f_dex) % 2) {
f_dex -= 1.0;
}
i_dex = trunc(f_dex); // get truncated index
fraction = f_dex - i_dex; // calculate fraction value for interpolation
outsample_left += (b_sample[i_dex] + fraction * (b_sample[i_dex + b_channelcount] - b_sample[i_dex])) * w_read;
outsample_right += (b_sample[i_dex + 1] + fraction * (b_sample[(i_dex + 1) + b_channelcount] - b_sample[i_dex + 1])) * w_read;现在,这引入了一些数字噪音,我真的无法解释原因。有没有其他/更好的方法将实时线性插值应用于交错立体声文件?
发布于 2014-11-07 07:39:26
我被你的变量名搞糊涂了,position、oldlength和outsample_left/outsample_right似乎用于输出,而newlength和offset来自输入b_sample
我认为您的问题是将b_channelcount包含在f_dex的计算中。试一试
f_dex = offset + ((position / oldlength) * newlength);您可以省略% 2检查和调整。这种调整并没有达到你的预期。
附录11/7:我遗漏了一些东西,你还需要调整你的i_dex的使用,因为我在这里设置了f_dex,它将每个通道的整个块计数为1。在你使用b_sample[i_dex]之前,使用b_sample[i_dex*b_channelcount];这将把你放在块的第一个样本(如果是立体声)。同样,您可以对右通道使用b_sample[i_dex*b_channelcount + 1] (如果有右通道),对下一个块的第一个样本使用b_sample[(i_dex+1)*b_channelcount]进行插值,依此类推。
https://stackoverflow.com/questions/26766146
复制相似问题