From 2f1782d8920a21089b4700709d11c4d235bee182 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 10 Dec 2006 05:41:41 +0000 Subject: [PATCH] merge Read and ReadBlock --- stepmania/src/RageSoundReader_Chain.cpp | 31 +++++++++---------------- stepmania/src/RageSoundReader_Chain.h | 1 - 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/stepmania/src/RageSoundReader_Chain.cpp b/stepmania/src/RageSoundReader_Chain.cpp index fed3acc3e9..86512da91f 100644 --- a/stepmania/src/RageSoundReader_Chain.cpp +++ b/stepmania/src/RageSoundReader_Chain.cpp @@ -303,8 +303,15 @@ float RageSoundReader_Chain::GetStreamToSourceRatio() const /* As we iterate through the sound tree, we'll find that we need data from different * sounds; a sound may be needed by more than one other sound. */ -int RageSoundReader_Chain::ReadBlock( int16_t *pBuffer, int iFrames ) +int RageSoundReader_Chain::Read( char *pBuffer, int iFrames ) { + while( m_iNextSound < m_aSounds.size() && m_iCurrentFrame == m_aSounds[m_iNextSound].GetOffsetFrame(m_iActualSampleRate) ) + { + Sound *pSound = &m_aSounds[m_iNextSound]; + ActivateSound( pSound ); + ++m_iNextSound; + } + /* Clamp iFrames to the beginning of the next sound we need to start. */ if( m_iNextSound < m_aSounds.size() ) { @@ -327,6 +334,7 @@ int RageSoundReader_Chain::ReadBlock( int16_t *pBuffer, int iFrames ) iFrames = m_apActiveSounds.front()->pSound->Read( (char *) pBuffer, iFrames ); if( iFrames == 0 ) ReleaseSound( m_apActiveSounds.front() ); + m_iCurrentFrame += iFrames; return iFrames; } @@ -335,6 +343,7 @@ int RageSoundReader_Chain::ReadBlock( int16_t *pBuffer, int iFrames ) /* If we have more sounds ahead of us, pretend we read the entire block, since * there's silence in between. Otherwise, we're at EOF. */ memset( pBuffer, 0, iFrames * m_iChannels * sizeof(int16_t) ); + m_iCurrentFrame += iFrames; return iFrames; } @@ -364,28 +373,10 @@ int RageSoundReader_Chain::ReadBlock( int16_t *pBuffer, int iFrames ) /* Read mixed frames into the output buffer. */ mix.read( (int16_t *) pBuffer ); + m_iCurrentFrame += iMaxFramesRead; return iMaxFramesRead; } - -int RageSoundReader_Chain::Read( char *pBuffer, int iFrames ) -{ - while( m_iNextSound < m_aSounds.size() && m_iCurrentFrame == m_aSounds[m_iNextSound].GetOffsetFrame(m_iActualSampleRate) ) - { - Sound *pSound = &m_aSounds[m_iNextSound]; - ActivateSound( pSound ); - ++m_iNextSound; - } - - int iFramesRead = ReadBlock( (int16_t *) pBuffer, iFrames ); - if( iFramesRead == -1 ) - return -1; - - m_iCurrentFrame += iFramesRead; - - return iFramesRead; -} - int RageSoundReader_Chain::GetLength() const { int iLength = 0; diff --git a/stepmania/src/RageSoundReader_Chain.h b/stepmania/src/RageSoundReader_Chain.h index f7d95f230e..3059bfa7d2 100644 --- a/stepmania/src/RageSoundReader_Chain.h +++ b/stepmania/src/RageSoundReader_Chain.h @@ -43,7 +43,6 @@ public: float GetStreamToSourceRatio() const; private: - int ReadBlock( int16_t *pBuffer, int iFrames ); int GetSampleRateInternal() const; int m_iPreferredSampleRate;