From 9ade4fa722c023706c8c4de894d709515b392594 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 3 Oct 2003 23:23:28 +0000 Subject: [PATCH] GetLength optimization --- stepmania/src/RageSoundReader_MP3.cpp | 14 ++++++++++---- stepmania/src/RageSoundReader_MP3.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/stepmania/src/RageSoundReader_MP3.cpp b/stepmania/src/RageSoundReader_MP3.cpp index a1c8cb2dc3..1f76f92684 100644 --- a/stepmania/src/RageSoundReader_MP3.cpp +++ b/stepmania/src/RageSoundReader_MP3.cpp @@ -348,13 +348,20 @@ void fill_frame_index_cache( madlib_t *mad ) } /* Handle first-stage decoding: extracting the MP3 frame data. */ -int RageSoundReader_MP3::do_mad_frame_decode() +int RageSoundReader_MP3::do_mad_frame_decode( bool headers_only ) { int bytes_read = 0; while(1) { - if( !mad_frame_decode(&mad->Frame,&mad->Stream) ) + int ret; + + /* Always actually decode the first packet, so we cleanly pass Xing tags. */ + if( headers_only && !mad->first_frame ) + ret=mad_header_decode( &mad->Frame.header,&mad->Stream ); + else + ret=mad_frame_decode( &mad->Frame,&mad->Stream ); + if( !ret ) { /* OK. */ if( mad->first_frame ) @@ -1069,10 +1076,9 @@ int RageSoundReader_MP3::GetLengthInternal( bool fast ) } MADLIB_rewind(); - /* XXX use mad_header_decode (do_mad_frame_decode(true)?) */ while(1) { - int ret = do_mad_frame_decode(); + int ret = do_mad_frame_decode( true ); if( ret == -1 ) return -1; /* it set the error */ if( ret == 0 ) /* EOF */ diff --git a/stepmania/src/RageSoundReader_MP3.h b/stepmania/src/RageSoundReader_MP3.h index 1a89bc522c..058869661e 100644 --- a/stepmania/src/RageSoundReader_MP3.h +++ b/stepmania/src/RageSoundReader_MP3.h @@ -25,7 +25,7 @@ public: int FindOffsetFix(); int fill_buffer(); - int do_mad_frame_decode(); + int do_mad_frame_decode( bool headers_only=false ); int resync(); void synth_output(); int seek_stream_to_byte( int byte );