hi i am new to android-ndk so far i worked with all sample applications in android-nd开发者_开发百科k,now i am trying to port fftw3 library in android, can you plz suggest me any tutorial for this.
Thanks.
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
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).
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
The best way to compile fftw3 for Android armeabi-v7a is:
export SYSROOT="$NDK_ROOT/platforms/$TARGET/arch-arm"
export CFLAGS="-I$NDK_ROOT/platforms/$TARGET/arch-arm/usr/include --sysroot=$SYSROOT"
export CPPFLAGS="-I$NDK_ROOT/platforms/$TARGET/arch-arm/usr/include --sysroot=$SYSROOT"
export CC=$($NDK_ROOT/ndk-which gcc)
export LD=$($NDK_ROOT/ndk-which ld)
export CPP=$($NDK_ROOT/ndk-which cpp)
export CXX=$($NDK_ROOT/ndk-which g++)
export AS=$($NDK_ROOT/ndk-which as)
export AR=$($NDK_ROOT/ndk-which ar)
export RANLIB=$($NDK_ROOT/ndk-which ranlib)
./configure --host=arm-linux-androideabi --target=arm-linux-androideabi
make OS=android NDKROOT=$NDK_ROOT TARGET=android-9 ARCH=arm NDKLEVEL=9
Quite painlessly, FFTW can be built for Android with its official CMake script in http://fftw.org/fftw-3.3.8.tar.gz:
externalNativeBuild {
cmake {
arguments "-DANDROID_ARM_NEON=TRUE"
arguments "-DCMAKE_BUILD_TYPE=Release"
arguments "-DBUILD_SHARED_LIBS=OFF"
arguments "-DBUILD_TESTS=OFF"
arguments "-DDISABLE_FORTRAN=ON"
arguments "-DENABLE_FLOAT=ON"
targets "fftw3f"
}
}
精彩评论