2014-11-05 54 views
0

我正在实现音频数据的实时线性插值,它存储在交错音频缓冲区中。音频文件可以是单声道或多声道。在单声道音频文件的情况下,我插如下:交错立体声线性插值

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; 

现在,这引入了一些数字噪声可以和我真的不能解释为什么。是否有任何其他/更好的方法将实时线性插值应用于交错立体声文件?

回答

0

我对你们的变量名有点糊涂了,positionoldlengthoutsample_left/outsample_right似乎是同时newlength输出和offset从输入,b_sample

我认为你的问题是计算f_dex包括b_channelcount。尝试代替

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]用于内插的下一个块的第一样本等

+0

'为(I = 0;我 2014-11-07 09:53:13

+0

对不起,我似乎无法弄清楚如何在评论中发布正确的代码..如果可能的话。总之,这应该使变量名称和意图更清晰一些。我发现这可以处理单通道文件,但它不适用于多通道。另外,如何确保'f_dex'的计算在框架中的第一个样本上? – 2014-11-07 10:00:53

+0

@MatthiasMüller一个简单的解决方案是将代码编辑到最初的问题中(不一定代替旧代码,但这是一个选项)。我编辑了我的回答,覆盖了'f_dex'(因此'i_dex')现在正在计数帧而不是单个样本的问题。 – hcs 2014-11-07 19:38:57