100% found this document useful (1 vote)
16K views2 pages

Calculating The DFT With Jtransform

The document discusses using the JTransform library in Android to calculate the discrete Fourier transform (DFT) of an audio byte stream received from a native function. The author has added the JTransform jar files to the project but is getting compile errors when trying to use the DoubleFFT_1D and complexForward methods, indicating a problem with how the libraries are linked. They are seeking help to properly initialize and use the JTransform DFT methods in an Android application.

Uploaded by

jjros2011
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
16K views2 pages

Calculating The DFT With Jtransform

The document discusses using the JTransform library in Android to calculate the discrete Fourier transform (DFT) of an audio byte stream received from a native function. The author has added the JTransform jar files to the project but is getting compile errors when trying to use the DoubleFFT_1D and complexForward methods, indicating a problem with how the libraries are linked. They are seeking help to properly initialize and use the JTransform DFT methods in an Android application.

Uploaded by

jjros2011
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Calculating the DFT with Jtransform's DoubleFFT_1D() for android

I have been searching everywhere to find a reliable method to calculate the FFT of an audio byte stream received by a native function in android SDK (through eclipse IDE). I have come across the libgdx fft and Jtransform. Jtransform Found here JTransform . I have downloaded them all and added the .jar files to a created libs folder in the root directory for the project. I have then linked the project to the new .jar files through project properties > java Build Path > Libraries. My src java file looks like this attempting to use Jtransform.
package com.spectrum; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.media.AudioFormat; import android.media.AudioManager; import android.media.AudioTrack; import android.media.MediaPlayer; import android.os.Bundle; import android.widget.LinearLayout; import android.widget.TextView; import android.view.View; import com.badlogic.gdx.audio.analysis.*; import edu.emory.mathcs.jtransforms.fft.*; import edu.emory.mathcs.utils.*; public class spectrum extends Activity { static byte [] sin = null; static int f = 2000; static int fs = 44100; double buf; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //initialize(new SpectrumDesktop(), false); sin = playsin(f,fs); buf = bytearray2double(sin); public DoubleFFT_1D(512); //<Undefined> public void complexForward(sin) //<Undefined> playsound(sin); } public static double bytearray2double(byte[] b) { ByteBuffer buf = ByteBuffer.wrap(b); return buf.getDouble(); } private void playsound(byte[] sin2){ int intSize = android.media.AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT); AudioTrack at = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT, intSize, AudioTrack.MODE_STREAM); at.play(); at.write(sin2, 0, sin2.length ); at.stop(); at.release(); } @Override protected void onDestroy() {

super.onDestroy(); // TODO Auto-generated method stub if (mMediaPlayer != null) { mMediaPlayer.release(); mMediaPlayer = null; } } public native byte[] playsin(int f,int fs); /** Load jni .so on initialisation */ static { System.loadLibrary("SPL");

} }

In this example I am only using the Jtransform packages, however I have been getting the same compile error for the lingdx packages. The compiler says that DoubleFFT_1D and complexForward are undefined. So there is something I am missing, like not linking my libraries correctly, I am not sure. Any help would be greatly appreciated. Am I meant to declare an instance of DoubleFFT_1D and complexForward before onCreate or something? I know this is a noob question, but I am new to object oriented languages and learning java on the go. Thanks :)

You might also like