在WAV文件(JAVA)中查找帧的平均RMS能量

时间:2019-05-12 18:58:25

标签: java arrays audio buffer wav

我需要有关如何在Java中的wav文件中计算每个帧的平均RMS能量的建议。

这是我到目前为止的代码,我的主管指示我将wav文件放入字节样本数组中。

public class wavArray {

public static void main(String[] args) throws IOException {
File file = new File("dogtest2.wav");

ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));

int read;

 byte    buff[];
 buff = new byte[1024];

while ((read = in.read(buff)) > 0)
{
    out.write(buff, 0, read);
}
out.flush();
byte[] audioBytes = out.toByteArray();

int total = 0;

for (int loop = 0; loop < buff.length ; loop++) {
    System.out.println(buff[loop]);
    total += buff[loop];
}

double average = total/buff.length;

 System.out.println(average);
}

任何能使我朝正确方向发展的建议,链接或资源,将不胜感激。

0 个答案:

没有答案