如何计算存储在JAVA中的数组中的wav文件样本的avarege RMS能量 [英] How to calculate avarege RMS energy of wav file samples stored in an array in JAVA

查看:103
本文介绍了如何计算存储在JAVA中的数组中的wav文件样本的avarege RMS能量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个论文,涉及制作一个应用程序,听取背景噪音,并检测高能量的狗吠。



我使用以下代码存储样本将wav文件放入数组缓冲区。







public static void main(String [] args抛出IOException {

文件文件=新文件(dogtest2.wav);



ByteArrayOutputStream out = new ByteArrayOutputStream();

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



int read;



byte buff [];

buff =新字节[1024];



while((read = in.read) (buff))> 0)

{

out.write(buff,0,read);

}

out.flush();

byte [] audioBytes = out.toByteArray();

}

}







现在我知道了ant解码缓冲区样本并找到所有样本的RMS(平均值),因此上面的任何内容都可以被标记为异常的声音事件。



我尝试了什么:



我在网上不断研究这个问题,我的主管告诉我,我需要使用RMS能量来分析来自的音频帧波形文件的平均能量。到目前为止没有找到任何与我的情况相关的东西(据我所知)。





关于什么的任何指导我应该阅读或者任何其他建议将不胜感激。

I am doing a thesis that involves making an app that listens to background noise and detects high energy dog barks.

I have used the following code to store samples of the wav file into an array buffer.



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();
}
}



Now I want to decode the buffer samples and find the RMS (Average) value of all the samples, so anything above this can be tagged as an unusual acoustic event.

What I have tried:

I have researched this continuously online and my supervisor told me I will need to use RMS energy to analyse the audio frames from the wave file for an average energy. So far In have not find anything that is relevant to my situation (as far as I can tell ).


Any guidance about what I should be reading up on or any other advice would be greatly appreciated.

推荐答案

通过一对扬声器播放文件并测量电压和电流强度。



测量放大器输出功率 [ ^ ]



https://itstillworks.com/determine-speaker-rms-12106808.html [ ^ ]
Play the file through a pair of speakers and measure the voltage and amperage.

Measuring amplifier output power[^]

https://itstillworks.com/determine-speaker-rms-12106808.html[^]


嗯,你就像你一样用任何其他语言来做。也就是说,你计算每个样本的大小的平方,将这些正方形加在一起,除以样本数,然后取平方根。



换句话说,此代码为在Web浏览器中运行的代码计算此值。



Well, you'd just do it the same way you'd do it with any other language. Namely, you calculate the square of the magnitude of each sample, add these squares all together, divide by the number of samples and then take the square-root of it.

To say it another way, this code computes this value for code running in a web-browser.

function calcRMS(signal)
{
	var numSamples = signal.length;
	var total = 0;
	for (var cur=0; cur<numSamples; cur++)
	{
		total += signal[cur]*signal[cur];
	}
	var result = Math.sqrt(total / numSamples);
	return result;
}





因为它需要相同的能量才能用千分尺将麦克风 - 隔膜拉向你为了将它推离你,需要一个系统,其中-0.5的样本对能量计算的贡献与0.5的样本一样多。

通过取正方形每个样本,我们消除负号。这使我们可以计算相同的能量值,无论麦克风偏向哪个方向。

例如

-2 * -2 = 4.



2 * 2 = 4



Since it takes the same energy to pull the microphone-diaphram towards you by a micrometer, as it takes it to push it away from you, a system is needed whereby a sample of -0.5 contributes just as much to the energy computation as a sample of 0.5

By taking the square of each sample, we eliminate the negative sign. This allows us to compute the same value for energy regardless of which direction the microphone is deflected in.
E.g
-2*-2 = 4.
and
2*2 = 4


这篇关于如何计算存储在JAVA中的数组中的wav文件样本的avarege RMS能量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆