Re: Problem decoding very small file

Tamas Marki <[email protected]>
Newsgroups gmane.comp.audio.mp3.lame
Message-ID <CAL768UepwksrFzbWyjetROphpWjvi0LLrPcENAwQLxyH3JOACg@mail.gmail.com>
> > The thing is, I read in the whole file (no ID3 tag), hip_decode_headers
> > returns 0, but there is no more data in the file, so I essentially get
> > nothing out of it.
>
> Can you provide an example file?

I uploaded one here: http://tmarki.com/ZSS_Fi_MasterLink.mp3

It was encoded by Lame CLI from this source:
http://noproblo.dayjo.org/ZeldaSounds/ZSS/ZSS_Fi_MasterLink.wav

If I transcode it with the Lame CLI everything is fine, so I must be doing
something wrong in my code... I'm using a 8kB buffer for the MP3 data
(because lame_encode_flush recommends buffers size > 7200 bytes).

My encoding loop goes like this:

int readloc = fread(glob_mp3_buffer, sizeof(unsigned char), MP3_SIZE,
glob_mp3_in);
if (readloc) {
    int read2 = 0;
    read2 = hip_decode_headers(glob_hipt, glob_mp3_buffer, MP3_SIZE,
glob_pcm_buffer1, glob_pcm_buffer2, &glob_mp3data);
    // snipped code handling mp3 header
    if (read2) { // this is 0 on the first pass for very small files
        int coded = lame_encode_buffer(glob_lame, glob_pcm_buffer1,
glob_pcm_buffer2, read2, glob_mp3_outbuffer, PCM_SIZE);
        if (coded > 0) {
            glob_write += fwrite (glob_mp3_outbuffer, 1, coded,
glob_mp3_out);
        }
    }
}

The finishing/flushing part:

int coded = lame_encode_flush(glob_lame,glob_mp3_outbuffer, MP3_SIZE);
if (coded > 0) {
    glob_write += fwrite (glob_mp3_outbuffer, 1, coded, glob_mp3_out);
}
hip_decode_exit(glob_hipt);
lame_close(glob_lame);

It works fine if the file is larger than MP3_SIZE (=8k).

Thanks

-- 
Tamas Marki
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.