Android Visualizer getWaveForm() 在高音量下表现得很奇怪
我正在使用 Android Visualizer 获取音频流的波形数据并计算其 RMS。
public int[] getFormattedData(byte[] rawVizData) {
for (int i = 0; i < formattedVizData.length; i++) {
// convert from unsigned 8 bit to signed 16 bit
int tmp = ((int) rawVizData[i] & 0xFF) - 128;
formattedVizData[i] = tmp;
}
return formattedVizData;
}
//...
double rms = 0;
int[] formattedVizData = getFormattedData(buffer);
if (formattedVizData.length > 0) {
for (int i = 0; i < formattedVizData.length; i++) {
int val = formattedVizData[i];
rms += val * val;
}
rms = Math.sqrt(rms / formattedVizData.length);
}
我将捕获大小设置为 1024,并预计如果播放音量较高,信号的 RMS 值会增加。我使用 440Hz 正弦测试音进行测试并得到以下结果:
VOLUME RMS MIN VALUE MAX VALUE 6.67% 5.5 -8 7 13.33% 13.3 -19 18 20.00% 28.1 -40 39 26.67% 42.6 -60 59 33.33% 68 -96 95 40.00% 54 -77 76 46.67% 81 -115 114 53.33% 64 -91 90 60.00% 51 -91 90 66.67% 68 -97 96 73.33% 48 -69 68 80.00% 68 -97 96 86.67% 45 -65 64 93.33% 64 -91 90 100.00% 90 -128 127
为什么我的假设对于音量 > 不再成立? 33.33%?我在这里缺少什么? 我的代码中是否存在一些我似乎无法找到的明显错误?
我尝试了几天,找出为什么这不起作用,但到目前为止还没有找到解决方案。
非常感谢任何帮助。
I am using the Android Visualizer to obtain the waveform data of an audio stream and calculate the RMS of it.
public int[] getFormattedData(byte[] rawVizData) {
for (int i = 0; i < formattedVizData.length; i++) {
// convert from unsigned 8 bit to signed 16 bit
int tmp = ((int) rawVizData[i] & 0xFF) - 128;
formattedVizData[i] = tmp;
}
return formattedVizData;
}
//...
double rms = 0;
int[] formattedVizData = getFormattedData(buffer);
if (formattedVizData.length > 0) {
for (int i = 0; i < formattedVizData.length; i++) {
int val = formattedVizData[i];
rms += val * val;
}
rms = Math.sqrt(rms / formattedVizData.length);
}
I set the capture size to 1024 and expected the RMS value of the signal to grow if the playback volume is higher. I test with a 440Hz sine test tone and get the following results:
VOLUME RMS MIN VALUE MAX VALUE 6.67% 5.5 -8 7 13.33% 13.3 -19 18 20.00% 28.1 -40 39 26.67% 42.6 -60 59 33.33% 68 -96 95 40.00% 54 -77 76 46.67% 81 -115 114 53.33% 64 -91 90 60.00% 51 -91 90 66.67% 68 -97 96 73.33% 48 -69 68 80.00% 68 -97 96 86.67% 45 -65 64 93.33% 64 -91 90 100.00% 90 -128 127
Why does my assumption not hold anymore for volumes > 33.33%? What am I missing here?
Is there some obvious bug in my code I just seem to be unable to find?
I tried for days now finding out why this is not working and so far couldn't come up with a solution.
Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论