I am having difficulties converting 32 bit float raw audio to mp3 using lame. I am currently able to convert the audio to an mp3 but the output has evenly spaced gaps that appear like they are inserted between the proper output (none of the expected output is missing).
Th attached image is of the audacity timeline for the converted audio, the raw audio plays fine in audacity. I can also get the audio to play perfectly in GNURadio when I open it with a File Source with a float output and send it to a 48kHz Audio Sink. I have attached my source code and a sample input.
You want to check the return code of the lame_encode functions. Write data only, if the encoder said it produced some.
When I am writing to file I am writing a buffer of the size returned from the lame_encode function with count of 1. This should account for not writing data when nothing was produced by the encoded since I am only writing the returned encoded buffer size.
write = lame_encode_buffer_interleaved_ieee_float(lame, pcm_buffer, read, mp3_buffer, MP3_SIZE);
fwrite(mp3_buffer, write, 1, mp3);
I modified my code to ensure that only up to the number returned from the lame encode function entries from the encoded buffer are written to file. From the return values from the lame_encode and fwrite were always the same
int numwritten = fwrite(mp3_buffer, 1, write, mp3);
Well, fwrite takes unsigned integers and lame_encode can return negative integers signaling error conditions. Anyway, the nsamples argument for lame_encode is the number of samples per channel, not the total number of samples in the pcm buffer. (as documented in lame.h)
The input audio is only one channel so I tried lame_set_num_channels(lame,1) with no success. I am out of ideas of what to try next.
Why are you calling the interleaved variant, when there is nothing interleaved at all?
In mono case, don't use them.
Changing from lame_encode_buffer_interleaved_ieee_float to lame_encode_buffer_ieee_float worked! I just put the same input buffer as the both the left and right channels. Thanks for the assistance!
Last edit: Jeremy 2014-11-11