Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: What's the proper procedure for encoding single channel using lame (Read 5388 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

What's the proper procedure for encoding single channel using lame

I am using the lame 3.99.5 API to encode a single channel mono signal and stream it using RTP to a VLC client.  I am having all sorts of problems and cannot seem to get this working. So I have a couple of questions regarding the MP3 encoding part.

currently I am using this sequence (among other) of calls:

lame_set_num_channels() to set the channel to 1
lame_set_mode() to set the mode to MONO (which is enum 3)
lame_init_params()

then to encode the stream I use
lame_encode_buffer(gfp, buffer_l, buffer_r, nsamples, mp3buf, mp3buf_size)
and here I use a NULL pointer for the buffer_r argument since I only have a single PCM buffer and my data is not interleaved. I cannot find anything in the API document nor the header files that says which of the 2 buffers to use for single channel encoding but not using the right buffer by setting it to a NULL points appears to work--at least it doesn't seq fault 

Q1: is this calling sequence and setup the correct way to do this?

I am generating an encoded stream, so it appears to be ok, but I am not sure since I still cannot get VLC to decode the stream properly.

Q2: If I wanted to produce a 2 channel, pseudo stereo encoded stream from the original single channel mono PCM stream, would I use the following calling sequence?

lame_set_num_channels() to set the channel to 1
lame_set_mode() to set the mode to STEREO (which is enum 0)

My source PCM will always be single channel.

Q3: what is considered the "proper" way to stream a single channel MP3 stream?  as a strictly mono stream or as a 2 channel "stereo" stream?  Bandwidth aside, it would seem to me that most clients would *expect* a 2 channel stereo stream. (I recognize that my stream is not *really* stereo but simply 2 identical channels)

Thanks for any help guys...

-Andres

What's the proper procedure for encoding single channel using lame

Reply #1
Are you filling the structure before you start?

Code: [Select]
        /* Init the global flags structure
         */
        gfp = lame_init();


As far as I recall, 'buffer_l' carries the mono stream.

I think you need to duplicate the stream elsewhere to create a 'pseudo-stereo' output.

What's the proper procedure for encoding single channel using lame

Reply #2
Are you filling the structure before you start?

Code: [Select]
        /* Init the global flags structure
         */
        gfp = lame_init();


As far as I recall, 'buffer_l' carries the mono stream.

I think you need to duplicate the stream elsewhere to create a 'pseudo-stereo' output.


Thank you for your reply
yes, I am calling lame_init() before all of the API calls.

Thanks for the confirmation on buffer_l being the one to use for a single PCM stream.
When you say to duplicate the stream for the 'pseudo-stereo' case, do you mean to duplicate the it in the buffer_r then call lame_encode_buffer() in a normal stereo mode?

-Andres

What's the proper procedure for encoding single channel using lame

Reply #3
lame_set_mode() to set the mode to STEREO (which is enum 0)

IMHO joint stereo mode is much better in this case.

What's the proper procedure for encoding single channel using lame

Reply #4
I guess you could simply duplicate the buffer, but specify 2 channels and, as lvqcl says, use joint stereo as the overhead for the second channel would be negligible as the two channels would be identical.

 

What's the proper procedure for encoding single channel using lame

Reply #5
john33 and lvqcl, thank you for your replies on this. As per your suggestions, that is what I have done and it seems to be working.

-Andres