On Sunday, May 26, 2002, at 08:16 PM, Reza Naima wrote:
In order for minimad to use mmap(), it's necessary to invoke it like this: minimad <input.mp3 >output.pcm
That's how I did invoke it, before the change. It still failed. Perhaps because the location of the mp3 file is nfs mounted, though that's just a guess.
Strange; the file descriptors from redirected stdin as above or from open( ) should be equivalent. Perhaps you were feeding data to minimad from a pipe instead?
Otherwise, do you have any other thoughts?
I answered this in private email: I think the problem is that you are refilling your stream buffer without copying the unconsumed data from the end of the previous buffer.
One other question -- with the high-level API's call of mad_stream_buffer( ), does it want data in a prefered size? Or does it have to end on some multiple of some size?
There is no constraint on the size of the buffer. When MAD finds it cannot decode a complete frame from the remaining data in the buffer, it signals MAD_ERROR_BUFLEN or calls your input callback. As you now know, it's your responsibility to recover the unconsumed data from the buffer before calling mad_stream_buffer() again.
As a guideline, the largest possible frame size is 2880 bytes (Layer II 160 kbps 8000 Hz), so if you expect to be able to decode frames of any size, your buffer should be at least this size + MAD_BUFFER_GUARD bytes. madplay uses a buffer of 40000 bytes, which works out to 2.5 seconds of audio at 128 kbps, or 1 second at 320 kbps.
-- Rob Leslie rob@mars.org