android_Lame转换音频格式

这篇博客介绍了如何在Android中利用LAME库进行音频转码,包括设置错误处理函数、初始化编码器、编码过程、添加Xing VBR/INFO标签及释放资源等步骤,适合GUI应用开发者参考。
摘要由CSDN通过智能技术生成

Lame虽然没有ffmpeg强大,但是也可以做一些事情。转码的步骤:

1.(optional) Get the version number of the encoder, if you are interested. 

  void get_lame_version(char *strbuf, size_tbuflen, const char *prefix);

2.Error messages.  By default, LAME willwrite error messages to stderrusing vfprintf().  For GUI applications,this is often a problem and you need to set your own error message handlers:

    lame_set_errorf(gfp,error_handler_function);

  lame_set_debugf(gfp,error_handler_function);
  lame_set_msgf(gfp,error_handler_function);

3.Initialize the encoder.  sets default forall encoder parameters.初始化编码器,设置默认参数

   #include "lame.h"
   lame_global_flags *gfp;//在lame.h中typedeflame_global_flags *lame_t;
   gfp = lame_init();

 默认是 44.1khz、128kbps,音质是5,需要的时候设置自己的参数覆盖默认

   lame_set_num_channels(gfp,2);/* 默认也是2 */
   lame_set_in_samplerate(gfp,44100);  /* 采样率 */
   lame_set_brate(gfp,128);     /* 比特率 */
   lame_set_mode(gfp,1);    /* mode = 0,1,2,3 = stereo,jstereo,dualchannel(not supported),mono default */
   lame_set_quality(gfp,2);     /* 2=high  5 = medium  7=low */

 

4. 检查配置确保返回值ret_code>= 0

   ret_code = lame_init_params(gfp);

 

5  编码: 缓冲区mp3buffer_size大小可以通过 num_samples,samplerate和 encoding rate计算, 最坏的估计是

mp3buffer_size(in bytes) = 1.25*num_samples + 7200.其中num_samples = the number of PCMsamples in each channel.

返回的数字code = 输出到mp3buffer缓冲的大小(number of bytesoutput in mp3buffer),可以为0,但是小于0就出错了

 

 int lame_encode_buffer(lame_global_flags*gfp,
           short      intleftpcm[],
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值