android 编译faac,faac 移植到android

在项目中需要应用到faac 压缩音频传输,有网友提供了移植方法和库.so 测试了声音不对,所以参考了他的移植方法 封装的接口。

可以在资源下载自己修改http://download.csdn.net/detail/undiif123/5494433

jint Java_com_sinaapp_bashell_AacEncoder_AACEncoderOpen(JNIEnv* env,                                              jobject this,jint sampleRate,jint channels) {         faacEncConfigurationPtr myFormat;         unsigned int mpegVersion = MPEG4;     unsigned int objectType = LOW;     unsigned int useMidSide = 1; unsigned long quantqual = 100; static unsigned int useTns = 1; int rawBits = 16; int rawRate =sampleRate; int rawEndian = 1; int shortctl = SHORTCTL_NORMAL;     g_hEncoder = faacEncOpen(sampleRate, channels,         &samplesInput, &maxOutputBytes);         myFormat = faacEncGetCurrentConfiguration(g_hEncoder);     myFormat->allowMidside = useMidSide;     myFormat->aacObjectType = objectType;     myFormat->mpegVersion = mpegVersion;     myFormat->outputFormat =1;     myFormat->useTns = useTns;     myFormat->useLfe = 0;     myFormat->quantqual =quantqual;     myFormat->bandWidth = 0; myFormat->shortctl = shortctl;     faacEncSetConfiguration(g_hEncoder, myFormat);     sprintf(g_szFileName,"/storage/sdcard0/new_test1.aac");//"/mnt/sdcard/new.aac");///data/IPVOD/    // sprintf(g_szFileName,"/storage/sdcard0/new_test1.pcm");//"/mnt/sdcard/new.aac");///data/IPVOD/ LOGI("samplesInput:%d,maxOutputBytes:%d",samplesInput,maxOutputBytes); g_OutFile = fopen(g_szFileName, "wb"); if(g_OutFile == NULL) {LOGI("open aacfile failed!"); return 1;}; sprintf(g_szFileName,"/storage/sdcard0/new_test0.pcm");//"/mnt/sdcard/new.aac");///data/IPVOD/ g_OutFile0 = fopen(g_szFileName, "wb"); if(g_OutFile0 == NULL) {LOGI("open aacfile failed!"); return 1;};    return 1; } jint Java_com_sinaapp_bashell_AacEncoder_AacWrite(JNIEnv* env,jobject this,jbyteArray jBuffer, jint jBufferSize) {        int *pcmbuf;    unsigned char *bitbuf;    jbyte* bBuffer = (*env)->GetByteArrayElements(env,jBuffer,0);    pcmbuf = (short*)malloc(samplesInput*sizeof(int));    bitbuf = (unsigned char*)malloc(maxOutputBytes*sizeof(unsigned char));       unsigned int bytesWritten;    if(g_hEncoder != NULL) {    unsigned int nBufferSize = (unsigned int)jBufferSize/2;    int nByteCount=0;    unsigned short* buf=(unsigned short*)bBuffer;    fwrite(jBuffer, 1, jBufferSize, g_OutFile0);    while(nByteCount < nBufferSize)    {     int audioLength=samplesInput;     if((nByteCount+samplesInput) >= nBufferSize) {     audioLength=nBufferSize-nByteCount; }     int i;     for (i = 0; i < audioLength; i++)     {    int s = ((int16_t *)buf+nByteCount)[i];    pcmbuf[i] = s << 8;     } nByteCount+=samplesInput;     bytesWritten = faacEncEncode(g_hEncoder,                         pcmbuf,                         audioLength,                         bitbuf,                         maxOutputBytes); if (bytesWritten < 0)continue; fwrite(bitbuf, 1, bytesWritten, g_OutFile);    }   }   if(bitbuf) free(bitbuf);   if(pcmbuf) free(pcmbuf);   return 1; } /* jint Java_com_sinaapp_bashell_AacEncoder_AACEncoderEncode(JNIEnv* env,                                       jobject this,jint hEncoder, jbyteArray inputBuffer, jint inputBufferSize) {    int *pcmbuf;    unsigned char *bitbuf;    jbyte* bBuffer = (*env)->GetByteArrayElements(env,inputBuffer,0);    jsize jLen = (*env)->GetArrayLength(env,inputBuffer);    int bytesInput = (int)jLen;    pcmbuf = (short*)malloc(samplesInput*sizeof(int));    bitbuf = (unsigned char*)malloc(maxOutputBytes*sizeof(unsigned char));       unsigned int bytesWritten;    if(g_hEncoder != NULL) {    unsigned int nBufferSize = (unsigned int)inputBufferSize/2;    int nByteCount=0;    unsigned short* buf=(unsigned short*)bBuffer;    fwrite(bBuffer, 1, inputBufferSize, g_OutFile0);    while(nByteCount < nBufferSize)    {      int audioLength jint Java_com_sinaapp_bashell_AacEncoder_AACEncoderClose(JNIEnv* env,jobject this) {  if(g_hEncoder != NULL) {   faacEncClose(g_hEncoder);  }  if(g_OutFile)fclose(g_OutFile);   return 1; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值