获取Java中的音频文件的波形 [英] Obtain wave pattern of a audio file in Java

查看:1470
本文介绍了获取Java中的音频文件的波形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我怎么可能会获得音乐信息,如从音频文件的幅度?

I'm wondering how I may obtain musical information such as amplitude from a audio file?

假设我们有一个原始音频文件,我想从它让我产生一个曲线,如<一个文件中抽取数据什么href=\"http://www1.icsi.berkeley.edu/Speech/mr/nearfar.html\">http://www1.icsi.berkeley.edu/Speech/mr/nearfar.html.一旦我获得这条曲线,我会进行FFT等。

Suppose we have a raw audio file, what I want to extract data from the file which allows me to generate a curve such as http://www1.icsi.berkeley.edu/Speech/mr/nearfar.html. Once I have obtained this curve, I will perform FFT, etc.

我一直在试图寻找在Java的声音解决方案,但我只知道到目前为止,我可以倒数据到字节[] 使用的AudioInputStream
但我怎么翻译的字节[] 双[] ,其中包含有关声音的实际信息?在这种情况下,在值双重[] 重新present 幅度。

I have been trying to search for solutions in Java Sound, but what I only know so far is that I can pour the data into byte[] using AudioInputStream. But how do I translate that byte[] into a double[] which contains actual information about the sound? In this case, the values in the double[] represent amplitude.

任何人都可以请提供一个解决方案在Java中解决这个问题?

Could anyone please provide a solution to solve this problem in Java?

推荐答案

典型的wav文件是16位的小端,所以你可以把每两个连续字节,B1和B2,并获得幅度如下:

Typical wav file is 16 bit little endian, so you can take each two consecutive bytes, b1 and b2, and get the amplitude as follows:

(double) (b2 << 8 | b1 & 0xFF) / 32767.0;

如果输入是立体声的,前两个字节将左声道,然后右声道的两个字节。

if the input is stereo, first two bytes would be left channel, then two bytes for right channel.

这篇关于获取Java中的音频文件的波形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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