They asked a lot about this, but I'm still stuck about implementing the FFT class on Android, I need to process my audio data using FFT ...
I already read almost the same question here How can I get frequency data from PCM using FFT and here How can I get frequency from FFT result ? and more questions, but still haven't found the answer, even after I tried the answers given ...
The FFT class that I use: http://www.cs.princeton.edu/introcs/97data/FFT.java
A complex class to go with it: http://introcs.cs.princeton.edu/java/97data/Complex.java.html
Here is my code
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaRecorder; import android.os.Bundle; import android.os.Environment; import android.view.View; import android.widget.Button; public class Latihan extends Activity{ private static final int RECORDER_BPP = 16; private static final String AUDIO_RECORDER_FILE_EXT_WAV = ".wav"; private static final String AUDIO_RECORDER_FOLDER = "AudioRecorder"; private static final String AUDIO_RECORDER_TEMP_FILE = "record_temp.raw"; private static final int RECORDER_SAMPLERATE = 44100; private static final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_STEREO; private static final int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT; short[] audioData; private AudioRecord recorder = null; private int bufferSize = 0; private Thread recordingThread = null; private boolean isRecording = false; Complex[] fftTempArray; Complex[] fftArray; int[] bufferData; int bytesRecorded; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.p1); setButtonHandlers(); enableButtons(false); bufferSize = AudioRecord.getMinBufferSize (RECORDER_SAMPLERATE,RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING)*3; audioData = new short [bufferSize];
I assume that the audioData array contains raw audio data, but my code catches the exception and returns "N is not a power of 2"
Is there something wrong with my code? How do I pass it to the FFT.java class and get fftResult ??
Or is there another way to convert data in the time domain into frequency data that is simpler?
It has been several months since I got stuck with this ... My project too compares 2 * .wav audio files, any help would be appreciated ... :)
source share