1、lame c库:
https://github.com/intervigilium/liblame
下载后解压,进入目录,terminal里运行ndk-build即可
2、lame android库
https://github.com/intervigilium/Lame4Android
需要引用上面编译好的.so文件
3、方法1里的lame的源码可能不是最新的,我们可以下载最新的lame
http://lame.sourceforge.net/download.php
a、解压,复制lame-3.99.5/libmp3lame 到jni目录里,改名为lame
b、拷贝 lame.h (include目录下),至jni/lame.h
c、创建jni/Android.mk,内容如下:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := lame
LOCAL_CLFAGS := -std=c99
LOCAL_LDLIBS := -llog
LOCAL_SRC_FILES := lame/bitstream.c lame/fft.c lame/id3tag.c lame/mpglib_interface.c lame/presets.c lame/quantize.c lame/reservoir.c lame/tables.c lame/util.c lame/VbrTag.c lame/encoder.c lame/gain_analysis.c lame/lame.c lame/newmdct.c lame/psymodel.c lame/quantize_pvt.c lame/set_get.c lame/takehiro.c lame/vbrquantize.c lame/version.c
include $(BUILD_SHARED_LIBRARY)
d、创建jni/Application.mk,内容如下
APP_ABI := armeabi armeabi-v7a arm64-v8a x86_64
APP_MODULES := lame
APP_CFLAGS += -DSTDC_HEADERS
#APP_ABI:=x86_64
#APP_PLATFORM := android-21
4、terminal里运行ndk-build,编译后的so文件放在libs里
说明:
Application.mk里要加APP_CFLAGS += -DSTDC_HEADERS,不然会报错undefined reference to `bcopy‘等错误
删除非.c
/.h
文件:GNU autotools, Makefile.am Makefile.in libmp3lame_vc8.vcproj logoe.ico depcomp, folders i386 等无用文件。编辑 jni/utils.h。把extern ieee754_float32_t fast_log2(ieee754_float32_t x);
替换为extern float fast_log2(float x);
。如果忘了替换,编译时会报出以下错误:
- [armeabi] Compile thumb : mp3lame <= bitstream.c
- In file included from jni/bitstream.c:36:0:
- jni/util.h:574:5: error: unknown type name ‘ieee754_float32_t‘
- jni/util.h:574:40: error: unknown type name ‘ieee754_float32_t‘
- make.exe: *** [obj/local/armeabi/objs/mp3lame/bitstream.o] Error 1