如何使用 FFT 从 PCM 获取频率数据

发布于 2024-12-07 04:28:09 字数 1140 浏览 1 评论 0原文

我有一个要传递给阅读器的音频数据数组:

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

澉约 2024-12-14 04:28:09

假设 audioData 数组包含原始音频数据,您需要从 audioData 数组创建一个 Complex[] 对象,如下所示:

Complex[] complexData = new Complex[audioData.length];
for (int i = 0; i < complexData.length; i++) {
    complextData[i] = new Complex(audioData[i], 0);
}

现在您可以将您的 complexData 对象作为参数传递给您的 FFT 函数:

Complex[] fftResult = FFT.fft(complexData);

Assuming the audioData array contains the raw audio data, you need to create a Complex[] object from the audioData array as such:

Complex[] complexData = new Complex[audioData.length];
for (int i = 0; i < complexData.length; i++) {
    complextData[i] = new Complex(audioData[i], 0);
}

Now you can pass your complexData object as a parameter to your FFT function:

Complex[] fftResult = FFT.fft(complexData);
在你怀里撒娇 2024-12-14 04:28:09

一些细节取决于 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.

攒眉千度 2024-12-14 04:28:09

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文