diff --git a/stepmania/src/RageSoundReader_MP3.cpp b/stepmania/src/RageSoundReader_MP3.cpp index 49157ddb77..c321fbd398 100644 --- a/stepmania/src/RageSoundReader_MP3.cpp +++ b/stepmania/src/RageSoundReader_MP3.cpp @@ -743,29 +743,22 @@ static void mono_to_stereo( char *dst, const char *src, unsigned len ) int RageSoundReader_MP3::Read( char *buf, int iFrames ) { - uint32_t iFramesWritten = 0; - uint32_t bw = 0; + int iFramesWritten = 0; - unsigned len = iFrames * sizeof(int16_t) * GetNumChannels(); - while( bw < len ) + while( iFrames > 0 ) { if( mad->outleft > 0 ) { - /* Ratio of input bytes to output bytes. */ - const int Ratio = Channels == 1? 2:1; + int iFramesToCopy = min( iFrames, int(mad->outleft / (sizeof(int16_t) * GetNumChannels())) ); + const int iBytesToCopy = iFramesToCopy * sizeof(int16_t) * GetNumChannels(); - /* Input bytes to be copied: */ - const unsigned cpysize = min( (len - bw)/Ratio, mad->outleft ); + memcpy( buf, mad->outbuf + mad->outpos, iBytesToCopy ); - if( Channels == 1 ) - mono_to_stereo( (char *) buf + bw, (const char *) mad->outbuf + mad->outpos, cpysize ); - else - memcpy( buf + bw, mad->outbuf + mad->outpos, cpysize ); - - bw += cpysize * Ratio; - iFramesWritten += (cpysize * Ratio) / (sizeof(int16_t) * GetNumChannels()); - mad->outpos += cpysize; - mad->outleft -= cpysize; + buf += iBytesToCopy; + iFrames -= iFramesToCopy; + iFramesWritten += iFramesToCopy; + mad->outpos += iBytesToCopy; + mad->outleft -= iBytesToCopy; continue; } diff --git a/stepmania/src/RageSoundReader_MP3.h b/stepmania/src/RageSoundReader_MP3.h index 2dd3a86a47..1fb74bb215 100644 --- a/stepmania/src/RageSoundReader_MP3.h +++ b/stepmania/src/RageSoundReader_MP3.h @@ -18,6 +18,7 @@ public: int SetPosition_Accurate( int iSample ); int SetPosition_Fast( int iSample ); int Read( char *pBuf, int iFrames ); + unsigned GetNumChannels() const { return Channels; } int GetSampleRate() const { return SampleRate; } int GetNextSourceFrame() const;