之前項目裡面需要轉歌曲,不過是通過java來實現的比較慢,最近有時間在網上查看mp3解碼,找到libmad,能夠實現mp3的解碼,所以編譯成庫測試一下效能。
1、下載源碼,到官網 http://sourceforge.net/projects/mad/files/libmad/0.15.1b/ 現在最新的版本是libmad-0.15.1b
2、解壓下載的檔案,進入並建立jni目錄,然後將裡面的檔案都拷貝到jni目錄下面
3、組建組態檔案,建立config.sh,來組建組態檔案,內容如下:
#!/bin/shNDK=/opt/android-ndk-r8dPLATFORM=$NDK/platforms/android-8/arch-arm/PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86CC=$PREBUILT/bin/arm-linux-androideabi-gcc ./configure --prefix=/home/libmad-0.15.1b/jni/dist --host=arm --enable-speed --enable-static --enable-fpm=arm --with-pic CC="$CC --sysroot=$PLATFORM"
4、在終端運行config.sh,會得到配置config.h等檔案,然後根據Makefile檔案便下Android.mk,內容如下:
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_SRC_FILES := \ version.c \ fixed.c \ bit.c \ timer.c \ stream.c \ frame.c \ synth.c \ decoder.c \ layer12.c \ layer3.c \ huffman.c \ imdct_l_arm.S \ minimad.cLOCAL_C_INCLUDES := $(LOCAL_PATH)LOCAL_ARM_MODE := armLOCAL_MODULE:= libmadLOCAL_CFLAGS := -DHAVE_CONFIG_H -DFPM_ARM -ffast-math \-O3 -Wall -g -O -fforce-addr \-fthread-jumps -fcse-follow-jumps -fcse-skip-blocks \-fexpensive-optimizations -fregmove -fschedule-insns2 \-fstrength-reduce -fPICinclude $(BUILD_SHARED_LIBRARY)
5、在終端運行ndk-build,得到結果如下:
root@zhangjie:/home/libmad-0.15.1b/jni# ndk-buildCompile arm : mad <= version.cCompile arm : mad <= fixed.cCompile arm : mad <= bit.cCompile arm : mad <= timer.cCompile arm : mad <= stream.cCompile arm : mad <= frame.cCompile arm : mad <= synth.cCompile arm : mad <= decoder.cCompile arm : mad <= layer12.cCompile arm : mad <= layer3.cCompile arm : mad <= huffman.cCompile arm : mad <= imdct_l_arm.SCompile arm : mad <= minimad.cSharedLibrary : libmad.soInstall : libmad.so => libs/armeabi/libmad.so