1
因此,我正在處理音頻的這個應用程序,並且我有一個包含所有要發送到聲卡的數據的緩衝區。我想知道是否有人有任何建議,以此作爲VU儀表的最佳方式?如果它有什麼區別,我使用Java。我見過的大多數例子都是用於物理VU表。從音頻緩衝區製作VU表
編輯:我需要弄清楚如何讓音頻緩衝區的容量在任何給定的點
因此,我正在處理音頻的這個應用程序,並且我有一個包含所有要發送到聲卡的數據的緩衝區。我想知道是否有人有任何建議,以此作爲VU儀表的最佳方式?如果它有什麼區別,我使用Java。我見過的大多數例子都是用於物理VU表。從音頻緩衝區製作VU表
編輯:我需要弄清楚如何讓音頻緩衝區的容量在任何給定的點
什麼我的回答確實很粗略計算緩衝區的絕對值的漏積分。 由於數字音頻需要重現正反兩方面的聲壓,通常50%的值是「關閉」的。如果你沒有得到這個,請參閱關於數字音頻的維基百科文章。
真正的VU探測器是信號幅度的泄漏積分器。 (如果電流計或電子伏特計芯片具有足夠高的輸入電阻,則簡單的緩衝器和電容器就足夠了)
因此對於16位採樣,代碼可能看起來像......(離我頭頂)
//set up
long total=0;
const long half = 32768; //2^(n-1)
const long decayInMilliseconds=30; // 30ms for the needle to fall back to zero.
// leak rate is enough to get the reported signal to decay to zero decayMilliseconds after
// the actual amplitude goes to zero.
int leakRate = (sample_rate*1000 /decayInMilliseconds) * half;
// goes in a loop to do the work
// can be executed on buffer-loads of data at less than the sampling rate, but the net number of calls to it persecond needs to equal the sampling rate.
int amplitude = buffer[i]-half;
total = total + abs(amplitude);
total = total - leakRate;
if(total > half) {
total = half;
}
//total is the current "vu level".
總計值通常以對數形式顯示。