How to get frequency data from PCM using FFT

I have an array of audio data that I pass to the reader:

recorder.read(audioData,0,bufferSize); 

Creating an instance 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 an FFT class that I found online, and a complex class to go with it. I tried for two days to search the Internet everywhere, but I can’t figure out how to audioData over the values ​​stored in audioData and transfer them to the FFT.

This is the FFT class that I use: http://www.cs.princeton.edu/introcs/97data/FFT.java and this is a complex class to go with it: http://introcs.cs.princeton.edu/java /97data/Complex.java.html

+6
source share
3 answers

Assuming the audioData array contains 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); 
+3
source

Some details will depend on the purpose of your FFT.

The length of the required FFT depends on the frequency resolution and time accuracy (which are related to the feedback) that you want in your analysis, which may or may not be anywhere closer to the length of the audio input buffer. Given these differences in length, you may need to combine several buffers, segment one buffer or some combination of the two to get the FFT window length that fits your analysis requirements.

+1
source

PCM is a data encoding method. This is not related to obtaining frequency analysis of audio data using FFT. If you use Java to decode PCM encoded data, you will get raw audio data that can then be transferred to your FFT library.

0
source

Source: https://habr.com/ru/post/898325/


All Articles