From 896ce3f103d73b3d987fdb48117260cd881f0f6f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 28 Mar 2004 05:10:26 +0000 Subject: [PATCH] make sure the last frame of MP3s is decoded --- stepmania/src/RageSoundReader_MP3.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/stepmania/src/RageSoundReader_MP3.cpp b/stepmania/src/RageSoundReader_MP3.cpp index cfd36ad14e..d94ca5bfa0 100644 --- a/stepmania/src/RageSoundReader_MP3.cpp +++ b/stepmania/src/RageSoundReader_MP3.cpp @@ -332,12 +332,23 @@ int RageSoundReader_MP3::fill_buffer() mad->inbuf_filepos += mad->Stream.next_frame - mad->inbuf; } - int rc = file.Read( mad->inbuf + inbytes, sizeof (mad->inbuf)-inbytes ); + const bool bWasAtEOF = file.AtEOF(); + + int rc = file.Read( mad->inbuf + inbytes, sizeof(mad->inbuf)-inbytes-MAD_BUFFER_GUARD ); if( rc < 0 ) { SetError( file.GetError() ); return -1; } + + if ( file.AtEOF() && !bWasAtEOF ) + { + /* We just reached EOF. Append MAD_BUFFER_GUARD bytes of NULs to the + * buffer, to ensure that the last frame is flushed. */ + memset( mad->inbuf + inbytes + rc, 0, MAD_BUFFER_GUARD ); + rc += MAD_BUFFER_GUARD; + } + if ( rc == 0 ) return 0;