android 编译libmad

之前项目里面需要转歌曲,不过是通过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/sh

NDK=/opt/android-ndk-r8d
PLATFORM=$NDK/platforms/android-8/arch-arm/
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
CC=$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.c

LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_ARM_MODE := arm
LOCAL_MODULE:= libmad
LOCAL_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 -fPIC
include $(BUILD_SHARED_LIBRARY)

5、在终端运行ndk-build,得到结果如下:

root@zhangjie:/home/libmad-0.15.1b/jni# ndk-build
Compile arm    : mad <= version.c
Compile arm    : mad <= fixed.c
Compile arm    : mad <= bit.c
Compile arm    : mad <= timer.c
Compile arm    : mad <= stream.c
Compile arm    : mad <= frame.c
Compile arm    : mad <= synth.c
Compile arm    : mad <= decoder.c
Compile arm    : mad <= layer12.c
Compile arm    : mad <= layer3.c
Compile arm    : mad <= huffman.c
Compile arm    : mad <= imdct_l_arm.S
Compile arm    : mad <= minimad.c
SharedLibrary  : libmad.so
Install        : libmad.so => libs/armeabi/libmad.so


你可能感兴趣的:(android,libmad)