You are setting it up to encode a mono stream (lame_set_mode(lame, MONO);
) but providing the data as if it were interleaved stereo.
If it's a mono stream, then remove the 2*
from fread
, to read enough samples for a single channel; and call lame_encode_buffer
rather than lame_encode_buffer_interleaved
, with the right-hand channel pointer set to either NULL
or pcm_buffer
, to encode just one channel.
If it's a stereo stream, then don't set the mode to mono. You probably shouldn't do this anyway; I think it detects the mode based on the number of channels.
Also, as I mentioned when I wrote that code, you should check for and handle errors if you're using it in a real application. It's a very basic example.