[mad-dev] Re: Will the last frame be decoded ?

Rob Leslie rob@mars.org
Tue, 29 May 2001 13:46:07 -0700

Eric Peng wrote:
>   I'm using libmad for MP3 streaming decoding.  However, my program
>   doesn't decode the last frame.

You've correctly isolated the problem. The solution is to append enough zero
bytes to your stream buffer after the last frame to satisfy the

The reason for MAD_BUFFER_GUARD has to do with the way decoding is performed.
In Layer III, Huffman decoding may inadvertently read a few bytes beyond the
end of the buffer in the case of certain invalid input. This is not detected
until after the fact. To prevent this from causing problems, and also to
ensure the next frame's main_data_begin pointer is always accessible, MAD
requires MAD_BUFFER_GUARD (currently 8) bytes to be present in the buffer past
the end of the current frame in order to decode the frame.


Rob Leslie