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);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM