1、下NDK并配置环境变量
2、配置JNI,具体参考http://blog.csdn.net/shimiso/article/details/43447785
3、配置自己的运行.h和.c文件以及util文件
#include "lame.h"
#include "com_eachpal_audio_MyLameUtil.h"
#include <stdio.h>
#include <jni.h>
static lame_global_flags *lame = NULL;
JNIEXPORT void JNICALL Java_com_eachpal_audio_MyLameUtil_init(
JNIEnv *env, jclass cls, jint inSamplerate, jint inChannel, jint outSamplerate, jint outBitrate, jint quality) {
if (lame != NULL) {
lame_close(lame);
lame = NULL;
}
lame = lame_init();
lame_set_in_samplerate(lame, inSamplerate);
lame_set_num_channels(lame, inChannel);//输入流的声道
lame_set_out_samplerate(lame, outSamplerate);
lame_set_brate(lame, outBitrate);
lame_set_quality(lame, quality);
lame_init_params(lame);
}
JNIEXPORT jint JNICALL Java_com_eachpal_audio_MyLameUtil_encode(
JNIEnv *env, jclass cls, jshortArray buffer_l, jshortArray buffer_r,
jint samples, jbyteArray mp3buf) {
jshort* j_buffer_l = (*env)->GetShortArrayElements(env, buffer_l, NULL);
jshort* j_buffer_r = (*env)->GetShortArrayElements(env, buffer_r, NULL);
const jsize mp3buf_size = (*env)->GetArrayLength(env, mp3buf);
jbyte* j_mp3buf = (*env)->GetByteArrayElements