Skip to main content


Please be aware that much of the software linked to or mentioned on this forum is niche and therefore infrequently downloaded. Lots of anti-virus scanners and so-called malware detectors like to flag infrequently downloaded software as bad until it is either downloaded enough times, or its developer actually bothers with getting each individual release allow listed by every single AV vendor. You can do many people a great favor when encountering such a "problem" example by submitting them to your AV vendor for examination. For almost everything on this forum, it is a false positive.
Topic: Raw Streaming to MP3 (Read 2112 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Raw Streaming to MP3

Hi All!!

I'm new here and with audio things!

I have a RAW audio(8Khz, 8bits) streaming, and I need to encode that to MP3, but I can't encode that when streaming finish... because of streaming length... it can be only 1 minute or more than 5 hours...

So I need to encode that RAW streaming to MP3.

I'm using Java as plataform.

I'm thinking to use Lame reading from StdIn and java writing to that but still no success.

Thanks all!


Re: Raw Streaming to MP3

Reply #1
I'm having the same issue .. has this ever been resolved in code ?
my conversion goes from raw to MP3
I attached input and output images (notice the output is really distorted)

My platform is C on ubuntu 1804LTS .. this is the conversion code
 int read, write;
    FILE *pcm = fopen("./input.raw", "rb");
    FILE *mp3 = fopen("./convertedFile.mp3", "wb");
    int n_bytes_read;
    int n_bytes_write;
    int i;
#define PCM_BUF_SIZE 1024
#define MP3_SIZE 8192

    short pcm_buffer_s[PCM_BUF_SIZE];
    unsigned char pcm_buffer[PCM_BUF_SIZE];   
    unsigned char mp3_buffer[MP3_SIZE];

    lame_global_flags *lame;
    //lame_t lame = lame_init();
    lame = lame_init();
    lame_set_num_channels(lame, 1);
    lame_set_in_samplerate(lame, 8000);
    lame_set_analysis(lame, 1);// debug .. get statistics data
    lame_set_errorf(lame, my_debugf);// debug .. get logging out of lame
    lame_set_msgf(lame, my_debugf);// debug .. get logging out of lame
    // from audacity
    lame_set_error_protection(lame, 0);
    lame_set_preset(lame, 1007);//standard quality and fast
    lame_set_VBR(lame, vbr_off);
    // end from audacity

    int ret = lame_init_params(lame);
    if (ret >=0)
        // print configuration

        do {
            n_bytes_read = fread(pcm_buffer, sizeof(char), PCM_BUF_SIZE, pcm);
            for (i = 0; i < n_bytes_read; i++) {
                pcm_buffer_s = (short)(pcm_buffer - 0x80) << 8;
            if (n_bytes_read == 0) {
                n_bytes_write = lame_encode_flush(lame, mp3_buffer, MP3_SIZE);
            } else {
                n_bytes_write = lame_encode_buffer(lame, pcm_buffer_s, NULL, n_bytes_read, mp3_buffer, MP3_SIZE);

            fwrite(mp3_buffer, sizeof(char), n_bytes_write, mp3);
        } while (n_bytes_read > 0);

        return 0;
    } else { printf("failed to initialize lame\n"); }

SimplePortal 1.0.0 RC1 © 2008-2021