Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compiling fftw3 in android ndk

Tags:

android-ndk

hi i am new to android-ndk so far i worked with all sample applications in android-ndk,now i am trying to port fftw3 library in android, can you plz suggest me any tutorial for this.

Thanks.

like image 378
imaya Avatar asked Nov 17 '10 06:11

imaya


3 Answers

The FFTW3 build system makes use of Autotools, so that you can not use it directly with the Android NDK. A good blog post dealing with this issue is here.

The idea is to generate a proper config.h file offline and to create Android Makefiles, which replace the missing ones normally generated by the Autotools.

To achieve a modular layout for the different native modules you might use, I'd 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 a jni/new_module_name directory and then adding new_module_name to the APP_MODULES list.

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

Application.mk:

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

Then put the original FFTW3 package under jni/fftw3/project/jni.

At this point you need to generate a config.h. You can do this by using a small shell script like this.

The last step is to create the needed Android Makefile. In jni/fftw3/project/jni put a 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)

Frow now on you have to create all these sources.mk files. E.g. a typical sources.mk looks like this:

rdft/sources.mk:

    sources = buffered2.c \
              buffered.c \
              <....>
              vrank-geq1.c \
              vrank-geq1-rdft2.c

    LOCAL_SRC_FILES += $(sources:%=rdft/%)

Call the ndk-build script in the top directory of your app and you should end up with two ready-to-use FFTW3 libraries:

  • libs/armeabi-v7a/libfftw3.so
  • libs/armeabi/libfftw3.so
like image 66
Matthieu Poullet Avatar answered Nov 19 '22 11:11

Matthieu Poullet


I currently solving similar problem, but without significant results.

As I can recommend use anther well tested library like JTransforms (java pretty fast) or find Badlogic KissFFT implementation (JNI, about 2 times faster, numerical unstable).

like image 30
Tomáš Bílek Avatar answered Nov 19 '22 09:11

Tomáš Bílek


After noticing, that there's a ton of new directories in recent fftw version, containing .c and not listed in the original Android.mk, I got too lazy to write source.mk-generating script, and googled this instead:

include $(LOCAL_PATH)/api/sources.mk

Thanks to Sudhakar Fomra (sfomra at github), got my build done in few minutes.

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

like image 1
kagali-san Avatar answered Nov 19 '22 09:11

kagali-san