我想在java中为麦克风创建一个音频电平表来检查输入的大小.它应该看起来像操作系统之一.我不是在询问gui.它只是计算出来的字节流中的音频电平
n = targetDataLine.read( tempBuffer , 0 , tempBuffer.length );
Run Code Online (Sandbox Code Playgroud)
所以我已经有一些正在运行的东西,但它甚至没有接近我操作系统的水平仪(窗口)它卡在中间.我有0到100之间的值是好的,但在中间音量,无论输入多么大,它都会在60左右.
这是我现在计算的方式:
amplitude = 0;
for (int j = 0; j < tempBuffer.length; j = j +2 ){
if (tempBuffer[j] > tempBuffer[j+1])
amplitude = amplitude + tempBuffer[j] - tempBuffer[j+1];
else amplitude = amplitude + tempBuffer[j + 1] - tempBuffer[j];
}
amplitude = amplitude / tempBuffer.length * 2;
Run Code Online (Sandbox Code Playgroud)
是否有更好/更精确的方法来计算音频电平来监控它?或者我可能犯了一个重大错误?
那是我的Audioformat:
public static AudioFormat getAudioFormat(){
float sampleRate = 20000.0F;
//8000,11025,16000,22050,44100
int sampleSizeInBits = 16;
//8,16
int channels = 1;
//1,2
boolean signed …Run Code Online (Sandbox Code Playgroud)