Compiling fftw3 in android ndk

Hi, I am new to android-ndk, so far I have worked with all examples of applications in android-ndk, now I am trying to port the fftw3 library to android, can you offer me some tutorial for this.

Thanks.

+7
android-ndk
source share
3 answers

The FFTW3 build system uses Autotools, so you cannot use it directly with the Android NDK. A good blog post on this issue is here .

The idea is to create your own config.h file offline and create Android Makefiles that replace absent ones that Autotools normally generate.

To get a modular layout for various native modules that you can use, I would recommend the following:

In your top jni/ directory, put these two files:

Application.mk :

  APP_OPTIM := release APP_ABI := armeabi armeabi-v7a APP_MODULES := fftw3 

Android.mk :

  TOP_DIR := $(call my-dir) include $(TOP_DIR)/fftw3/project/jni/Android.mk 

This way you can easily add a new module by creating the jni/new_module_name and then adding new_module_name to the APP_MODULES list.

Then create a new jni/fftw3 and put Application.mk :

Application.mk :

  APP_PROJECT_PATH := $(call my-dir)/project APP_MODULES += fftw3 APP_OPTIM := release APP_ABI := armeabi armeabi-v7a 

Then place the source FFTW3 package under jni/fftw3/project/jni .

At this point, you need to generate config.h . You can do this using a small shell script such as this .

The final step is to create the necessary Android Makefile. In jni/fftw3/project/jni install the top Android.mk :

  LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) include $(LOCAL_PATH)/api/sources.mk include $(LOCAL_PATH)/dft/sources.mk include $(LOCAL_PATH)/dft/scalar/sources.mk include $(LOCAL_PATH)/dft/scalar/codelets/sources.mk include $(LOCAL_PATH)/kernel/sources.mk include $(LOCAL_PATH)/rdft/sources.mk include $(LOCAL_PATH)/rdft/scalar/sources.mk include $(LOCAL_PATH)/rdft/scalar/r2cb/sources.mk include $(LOCAL_PATH)/rdft/scalar/r2cf/sources.mk include $(LOCAL_PATH)/rdft/scalar/r2r/sources.mk include $(LOCAL_PATH)/reodft/sources.mk LOCAL_MODULE := fftw3 LOCAL_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/api \ $(LOCAL_PATH)/dft \ $(LOCAL_PATH)/dft/scalar \ $(LOCAL_PATH)/dft/scalar/codelets \ $(LOCAL_PATH)/kernel \ $(LOCAL_PATH)/rdft \ $(LOCAL_PATH)/rdft/scalar \ $(LOCAL_PATH)/rdft/scalar/r2cb \ $(LOCAL_PATH)/rdft/scalar/r2cf \ $(LOCAL_PATH)/rdft/scalar/r2r \ $(LOCAL_PATH)/reodft # Use APP_OPTIM in Application.mk LOCAL_CFLAGS := -g include $(BUILD_SHARED_LIBRARY) 

Now you need to create all these sources.mk files. For example. A typical sources.mk as follows:

rdft/sources.mk :

  sources = buffered2.c \ buffered.c \ <....> vrank-geq1.c \ vrank-geq1-rdft2.c LOCAL_SRC_FILES += $(sources:%=rdft/%) 

Call ndk-build script in the top directory of your application, and in the end you will get two FFTW3 libraries ready for use:

  • libs/armeabi-v7a/libfftw3.so
  • libs/armeabi/libfftw3.so
+17
source share

I am currently solving a similar problem, but without significant results.

How can I recommend using a simple well-tested library such as JTransforms (java is pretty fast) or finding a Badlogic KissFFT implementation (JNI, about 2 times faster, numerical unstable).

+1
source share

Noticing that the latest version of fftw has a ton of new directories containing .c and not listed in the original Android.mk, I was too lazy to write a source.mk-generating script, and instead googled

 include $(LOCAL_PATH)/api/sources.mk 

Thanks to Sudhakar Fomra (sfomra at github), I did my work in a few minutes.

https://github.com/sfomra/FFTW3_MOD-for-Android

+1
source share

All Articles