Audio 交错立体声线性插值

Audio 交错立体声线性插值,audio,linear-interpolation,Audio,Linear Interpolation,我正在实现音频数据的实时线性插值,它存储在交错音频缓冲区中。音频文件可以是单声道或多声道。对于单声道音频文件,我按如下方式插值: 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 interpol

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

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;

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

我对您的变量名称、位置、oldlength和outsample有点困惑。左/outsample_右似乎用于输出,而newlength和offset则用于输入,b_sample

我认为你的问题是在计算f_指数时包括b_通道计数。试试看

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]作为下一块的第一个采样进行插值,等等。

对于i=0;i