我正在做一个项目,我需要获取音轨的电平,为此我正在使用BASS音频库(C++) 中的BASS_ChannelGetLevel方法。但问题是它总是为我返回一个 0,我不明白为什么!文档说, 当通道停止时,该方法将返回 0。
请在下面找到我正在使用的代码:
#include <iostream>
#include "bass.h"
using namespace std;
int main() {
DWORD level, left, right;
double pos;
if (BASS_Init(-1, 44100, BASS_DEVICE_DEFAULT, 0, NULL)) {
// create the stream
int stream = BASS_StreamCreateFile(FALSE, "test.ogg", 0,
BASS_STREAM_DECODE, BASS_SAMPLE_FLOAT);
if (stream != 0) {
BASS_ChannelPlay(stream, FALSE);
level = BASS_ChannelGetLevel(stream);
} else
cout << "error 1: " << BASS_ErrorGetCode() << endl;
left = LOWORD(level); // the left level
right = HIWORD(level); // the right level
cout << " low word : " << left << endl;
cout << " high word : " << right << endl;
cout << "error 3: " << BASS_ErrorGetCode() << endl;
// free the stream
BASS_StreamFree(stream);
// free BASS
BASS_Free();
}
}