我正在实现音频数据的实时线性插值,它存储在交错音频缓冲区中。音频文件可以是单声道或多声道。在单声道音频文件的情况下,我插如下:交错立体声线性插值
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;
现在,这引入了一些数字噪声可以和我真的不能解释为什么。是否有任何其他/更好的方法将实时线性插值应用于交错立体声文件?
'为(I = 0;我
2014-11-07 09:53:13
对不起,我似乎无法弄清楚如何在评论中发布正确的代码..如果可能的话。总之,这应该使变量名称和意图更清晰一些。我发现这可以处理单通道文件,但它不适用于多通道。另外,如何确保'f_dex'的计算在框架中的第一个样本上? – 2014-11-07 10:00:53
@MatthiasMüller一个简单的解决方案是将代码编辑到最初的问题中(不一定代替旧代码,但这是一个选项)。我编辑了我的回答,覆盖了'f_dex'(因此'i_dex')现在正在计数帧而不是单个样本的问题。 – hcs 2014-11-07 19:38:57