如何使用 FFT 从 PCM 获取频率数据
我有一个要传递给阅读器的音频数据数组:
recorder.read(audioData,0,bufferSize);
实例化如下:
AudioRecord recorder;
short[] audioData;
int bufferSize;
int samplerate = 8000;
//get the buffer size to use with this audio record
bufferSize = AudioRecord.getMinBufferSize(samplerate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT)*3;
//instantiate the AudioRecorder
recorder = new AudioRecord(AudioSource.MIC,samplerate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,bufferSize);
recording = true; //variable to use start or stop recording
audioData = new short [bufferSize]; //short array that pcm data is put into.
我有一个在网上找到的 FFT 类和一个与之配套的复杂类。 我已经尝试了两天在网上到处查找,但无法弄清楚如何循环访问 audioData
中存储的值并将其传递给 FFT。
这是我正在使用的 FFT 类:http://www.cs.princeton。 edu/introcs/97data/FFT.java 这是与之配套的复杂类:http://introcs。 cs.princeton.edu/java/97data/Complex.java.html
I have an array of audio data I am passing to a reader:
recorder.read(audioData,0,bufferSize);
The instantiation is as follows:
AudioRecord recorder;
short[] audioData;
int bufferSize;
int samplerate = 8000;
//get the buffer size to use with this audio record
bufferSize = AudioRecord.getMinBufferSize(samplerate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT)*3;
//instantiate the AudioRecorder
recorder = new AudioRecord(AudioSource.MIC,samplerate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,bufferSize);
recording = true; //variable to use start or stop recording
audioData = new short [bufferSize]; //short array that pcm data is put into.
I have a FFT class I have found online and a complex class to go with it.
I have tried for two days looking online everywhere but cant work out how to loop through the values stored in audioData
and pass it to the FFT.
This is the FFT class I am using: http://www.cs.princeton.edu/introcs/97data/FFT.java
and this is the complex class to go with it: http://introcs.cs.princeton.edu/java/97data/Complex.java.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设
audioData
数组包含原始音频数据,您需要从audioData
数组创建一个Complex[]
对象,如下所示:现在您可以将您的
complexData
对象作为参数传递给您的 FFT 函数:Assuming the
audioData
array contains the raw audio data, you need to create aComplex[]
object from theaudioData
array as such:Now you can pass your
complexData
object as a parameter to your FFT function:一些细节取决于 FFT 的目的。
所需的 FFT 长度取决于您在分析中希望的频率分辨率和时间精度(它们成反比),这可能接近也可能不接近音频输入缓冲区的长度。鉴于这些长度差异,您可能必须组合多个缓冲区、分段单个缓冲区或两者的某种组合,以获得满足您的分析要求的 FFT 窗口长度。
Some of the details will depend on the purpose of your FFT.
The length of the FFT required depends on the frequency resolution and time accuracy (which are inversely related), that you wish in your analysis, which may or may not be anywhere near the length of an audio input buffer. Given those differences in length, you may have to combine multiple buffers, segment a single buffer, or some combination of the two, to get the FFT window length that meets your analysis requirements.
PCM 是一种数据编码技术。它与使用 FFT 获取音频数据的频率分析无关。如果您使用 Java 解码 PCM 编码数据,您将获得原始音频数据,然后将其传递到 FFT 库。
PCM is the technique of encoding data. It's not relevant to getting frequency analysis of audio data using FFT. If you use Java to decode PCM encoded data you will get raw audio data which can then be passed to your FFT library.