インターリーブされたオーディオ バッファーに格納されているオーディオ データのリアルタイム線形補間を実装しています。オーディオ ファイルは、シングルチャンネルまたはマルチチャンネルにすることができます。シングル チャンネルのオーディオ ファイルの場合、次のように補間します。
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;
これによりデジタル ノイズが発生しますが、その理由を説明することはできません。インターリーブされたステレオ ファイルにリアルタイムの線形補間を適用する他の/より良い方法はありますか?