lame音频编码注意的点

1.注意每次编码的PCM数据不能太短,如果太短编码函数长期返回-1这样的错误,将导致编码器彻底失效程序奔溃的问题,经测试32000在3200下稳定,大概1/10码率是没有问题的,具体请自行查询或调试

/*
* input pcm data, output (maybe) mp3 frames.
* This routine handles all buffering, resampling and filtering for you.
*
* return code number of bytes output in mp3buf. Can be 0
* -1: mp3buf was too small
* -2: malloc() problem
* -3: lame_init_params() not called
* -4: psycho acoustic problems
*
* The required mp3buf_size can be computed from num_samples,
* samplerate and encoding rate, but here is a worst case estimate:
*
* mp3buf_size in bytes = 1.25*num_samples + 7200
*
* I think a tighter bound could be: (mt, March 2000)
* MPEG1:
* num_samples*(bitrate/8)/samplerate + 4*1152*(bitrate/8)/samplerate + 512
* MPEG2:
* num_samples*(bitrate/8)/samplerate + 4*576*(bitrate/8)/samplerate + 256
*
* but test first if you use that!
*
* set mp3buf_size = 0 and LAME will not check if mp3buf_size is
* large enough.
*
* NOTE:
* if gfp->num_channels=2, but gfp->mode = 3 (mono), the L & R channels
* will be averaged into the L channel before encoding only the L channel
* This will overwrite the data in buffer_l[] and buffer_r[].
*
*/

2.针对PCM数据选择正确的编码方法

// mp3 encode
//整形short类型PCM数据
int recvLen = lame_encode_buffer(_lame, recordingData, recordingData, nsamples, buffer, pcmLen);
//浮点类型PCM数据
int recvLen = lame_encode_buffer_interleaved_ieee_float(_lame, recordingData, nsamples, buffer, pcmLen);
//浮点类型PCM数据
int recvLen = lame_encode_buffer_ieee_float(_lame, recordingData, recordingData, nsamples, buffer, pcmLen);
上一篇:Openfire 的安装和配置


下一篇:MUI框架开发HTML5手机APP(一)--搭建第一个手机APP