3
votes

Looking at the API of libmp3lame, all the functions:

1- Either take left and right channels, like this one:

int CDECL lame_encode_buffer (
    lame_global_flags*  gfp,           /* global context handle         */
    const short int     buffer_l [],   /* PCM data for left channel     */
    const short int     buffer_r [],   /* PCM data for right channel    */
    const int           nsamples,      /* number of samples per channel */
    unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
    const int           mp3buf_size ); /* number of valid octets in this
                                          stream                        */

2- Take interleaved data, like this one:

int CDECL lame_encode_buffer_interleaved(
    lame_global_flags*  gfp,           /* global context handlei        */
    short int           pcm[],         /* PCM data for left and right
                                          channel, interleaved          */
    int                 num_samples,   /* number of samples per channel,
                                          _not_ number of samples in
                                          pcm[]                         */
    unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
    int                 mp3buf_size ); /* number of valid octets in this
                                          stream                        */

This is the case, although one can choose MONO instead of stereo. Using:

lame_set_mode(lame,MPEG_mode_e::MONO);

But then how can I get libmp3lame to take MONO PCM data and encode mono mp3 audio? What's the right API to use for that if I don't have a second channel?

1

1 Answers

4
votes

Looks like you need to set mode to MONO, set number of channels to 1 (lame_set_num_channels), and use lame_encode_buffer with PCM data in "left" buffer.