Lame mp3 encoder Android移植

Lame源码加入到Android项目的jni,和项目直接编译加载到项目中

1.下载最新lame源码,官网地址

2.下载完后解压,需要对源码做适当的修改

2.1拷贝源码目录下libmp3lame目录中的.c和.h文件到Android studio工程jni目录下同时拷贝include目录下的lame.h

Lame mp3 encoder Android移植_第1张图片

3.修改如下几个文件

3.1删除fft.c文件的47行的 #include "vector/lame_intrin.h"

3.2删除set_get.h文件的24行的#include

3.3将util.h文件的574行的"extern ieee754_float32_t fast_log2(ieee754_float32_t x);" 替换为 "extern float fast_log2(float x);"

4 本例中直接将lame编译成静态库,注Android.mk一定要添加 LOCAL_CFLAGS = -DSTDC_HEADERS,不然编译出错

5.Android.mk如下

LOCAL_PATH	:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE    := liblame3100

LOCAL_CFLAGS    := -Werror
LOCAL_CFLAGS    = -DSTDC_HEADERS

LOCAL_C_INCLUDES := \
		$(LOCAL_PATH)/ \

LOCAL_EXPORT_C_INCLUDES := \
		$(LOCAL_PATH)/

LOCAL_SRC_FILES := \
    $(LOCAL_PATH)/ \
    $(LOCAL_PATH)/bitstream.c \
    $(LOCAL_PATH)/encoder.c \
    $(LOCAL_PATH)/fft.c \
    $(LOCAL_PATH)/gain_analysis.c \
    $(LOCAL_PATH)/id3tag.c \
    $(LOCAL_PATH)/lame.c \
    $(LOCAL_PATH)/mpglib_interface.c \
    $(LOCAL_PATH)/newmdct.c \
    $(LOCAL_PATH)/presets.c \
    $(LOCAL_PATH)/psymodel.c \
    $(LOCAL_PATH)/quantize.c \
    $(LOCAL_PATH)/quantize_pvt.c \
    $(LOCAL_PATH)/reservoir.c \
    $(LOCAL_PATH)/set_get.c \
    $(LOCAL_PATH)/tables.c \
    $(LOCAL_PATH)/takehiro.c \
    $(LOCAL_PATH)/util.c \
    $(LOCAL_PATH)/vbrquantize.c \
    $(LOCAL_PATH)/VbrTag.c \
    $(LOCAL_PATH)/version.c \

include $(BUILD_STATIC_LIBRARY)

6.实例(直接采用手机录音获取pcm音频数据,后编码成mp3格式数据),上传待续。。。

你可能感兴趣的:(Android)