{"id":6923,"date":"2014-05-11T17:45:39","date_gmt":"2014-05-11T17:45:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/11\/calculating-the-dft-with-jtransforms-doublefft_1d-for-android-collection-of-common-programming-errors\/"},"modified":"2014-05-11T17:45:39","modified_gmt":"2014-05-11T17:45:39","slug":"calculating-the-dft-with-jtransforms-doublefft_1d-for-android-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/11\/calculating-the-dft-with-jtransforms-doublefft_1d-for-android-collection-of-common-programming-errors\/","title":{"rendered":"Calculating the DFT with Jtransform&#39;s DoubleFFT_1D() for android-Collection of common programming errors"},"content":{"rendered":"<p>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 &gt; java Build Path &gt; Libraries.<\/p>\n<p>My src java file looks like this attempting to use Jtransform.<\/p>\n<pre><code>package com.spectrum;\nimport android.app.Activity;\nimport android.graphics.Bitmap;\nimport android.graphics.BitmapFactory;\nimport android.media.AudioFormat;\nimport android.media.AudioManager;\nimport android.media.AudioTrack;\nimport android.media.MediaPlayer;\nimport android.os.Bundle;\nimport android.widget.LinearLayout;\nimport android.widget.TextView;\nimport android.view.View;\n\nimport com.badlogic.gdx.audio.analysis.*;\nimport edu.emory.mathcs.jtransforms.fft.*;\nimport edu.emory.mathcs.utils.*; \n\npublic class spectrum extends Activity {\nstatic byte [] sin = null;\nstatic int f = 2000;\nstatic int fs = 44100;\ndouble buf;\n\n\/** Called when the activity is first created. *\/\n@Override\npublic void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    \/\/initialize(new SpectrumDesktop(), false);\n\n    sin = playsin(f,fs);\n    buf = bytearray2double(sin);\n    public DoubleFFT_1D(512);        \/\/\n    public void complexForward(sin)  \/\/\n    playsound(sin);\n\n}\npublic static double bytearray2double(byte[] b) {  \n          ByteBuffer buf = ByteBuffer.wrap(b);  \n          return buf.getDouble();  \n      }  \n\n private void playsound(byte[] sin2){\n\nint intSize = android.media.AudioTrack.getMinBufferSize(44100,     AudioFormat.CHANNEL_CONFIGURATION_STEREO,\n            AudioFormat.ENCODING_PCM_16BIT);\n\nAudioTrack at = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_CONFIGURATION_STEREO,\n            AudioFormat.ENCODING_PCM_16BIT, intSize, AudioTrack.MODE_STREAM);\n\nat.play();\nat.write(sin2, 0, sin2.length ); \nat.stop();\nat.release();\n\n}\n\n@Override\nprotected void onDestroy() {\n    super.onDestroy();\n    \/\/ TODO Auto-generated method stub\n    if (mMediaPlayer != null) {\n        mMediaPlayer.release();\n        mMediaPlayer = null;\n    }\n\n}\n\n public native byte[] playsin(int f,int fs);\n\n \/** Load jni .so on initialisation *\/\n static {\n   System.loadLibrary(\"SPL\");\n}\n}\n<\/code><\/pre>\n<p>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?<\/p>\n<p>I know this is a noob question, but I am new to object oriented languages and learning java on the go. Thanks \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6923","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6923","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6923"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6923\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}