Skip to main content
Topic: Raw Streaming to MP3 (Read 1826 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!

Tercio.

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_out_samplerate(lame,8000);
    lame_set_disable_reservoir(lame,0);
    lame_set_bWriteVbrTag(lame,1);
    lame_set_preset(lame, 1007);//standard quality and fast
    lame_set_VBR(lame, vbr_off);
    // end from audacity


    lame_set_mode(lame,MONO);
    int ret = lame_init_params(lame);
    if (ret >=0)
    {
        // print configuration
        lame_print_config(lame);

        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);
        lame_close(lame);
        fclose(mp3);
        fclose(pcm);

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

 
SimplePortal 1.0.0 RC1 © 2008-2020