2014-11-05 69 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