에서 오디오 버퍼의 볼륨을 얻을 방법을 알아낼 필요가있다. 일반적으로 디지털 오디오가 음압과 음압을 모두 재생해야하므로 50 % 값은 "꺼짐"입니다. 디지털 오디오에 대한 위키 백과 문서를 참조하십시오.
실제 VU 고기는 신호 진폭의 새는 적분기입니다. (검류계 또는 전자식 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".
일반적으로 합계 값은 로그 눈금으로 표시됩니다.