From 18d09949c51e37d590f99a5be9c685fa5ca6ab4f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 18 Jan 2007 10:30:47 +0000 Subject: [PATCH] less overhead when not used --- stepmania/src/RageSoundReader_PitchChange.cpp | 23 +++++++++++++------ stepmania/src/RageSoundReader_PitchChange.h | 2 ++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/stepmania/src/RageSoundReader_PitchChange.cpp b/stepmania/src/RageSoundReader_PitchChange.cpp index 0d9c151612..64a29d5bc5 100644 --- a/stepmania/src/RageSoundReader_PitchChange.cpp +++ b/stepmania/src/RageSoundReader_PitchChange.cpp @@ -22,6 +22,8 @@ RageSoundReader_PitchChange::RageSoundReader_PitchChange( RageSoundReader *pSour m_pSource = m_pResample; m_fSpeedRatio = 1.0f; m_fPitchRatio = 1.0f; + m_fLastSetSpeedRatio = m_fSpeedRatio; + m_fLastSetPitchRatio = m_fPitchRatio; } RageSoundReader_PitchChange::RageSoundReader_PitchChange( const RageSoundReader_PitchChange &cpy ): @@ -34,6 +36,8 @@ RageSoundReader_PitchChange::RageSoundReader_PitchChange( const RageSoundReader_ m_pSpeedChange = dynamic_cast( m_pResample->GetSource() ); m_fSpeedRatio = cpy.m_fSpeedRatio; m_fPitchRatio = cpy.m_fPitchRatio; + m_fLastSetSpeedRatio = cpy.m_fLastSetSpeedRatio; + m_fLastSetPitchRatio = cpy.m_fLastSetPitchRatio; } int RageSoundReader_PitchChange::Read( char *pBuf, int iFrames ) @@ -42,9 +46,11 @@ int RageSoundReader_PitchChange::Read( char *pBuf, int iFrames ) * immediately on the next Read(). When this is true, apply the ratio to the * resampler and the speed changer simultaneously, so they take effect as * closely together as possible. */ - float fRate = GetStreamToSourceRatio(); - if( m_pSpeedChange->NextReadWillStep() ) + if( (m_fLastSetSpeedRatio != m_fSpeedRatio || m_fLastSetPitchRatio != m_fPitchRatio) && + m_pSpeedChange->NextReadWillStep() ) { + float fRate = GetStreamToSourceRatio(); + /* This is the simple way: */ // m_pResample->SetRate( m_fPitchRatio ); // m_pSpeedChange->SetSpeedRatio( m_fSpeedRatio / m_fPitchRatio ); @@ -56,12 +62,15 @@ int RageSoundReader_PitchChange::Read( char *pBuf, int iFrames ) float fActualPitchRatio = m_pResample->GetRate(); float fRequestedSpeedRatio = m_fSpeedRatio / fActualPitchRatio; m_pSpeedChange->SetSpeedRatio( fRequestedSpeedRatio ); - } - /* If we just applied a new speed and it caused the ratio to change, return - * no data, so the caller can see the new ratio. */ - if( fRate != GetStreamToSourceRatio() ) - return 0; + m_fLastSetSpeedRatio = m_fSpeedRatio; + m_fLastSetPitchRatio = m_fPitchRatio; + + /* If we just applied a new speed and it caused the ratio to change, return + * no data, so the caller can see the new ratio. */ + if( fRate != GetStreamToSourceRatio() ) + return 0; + } return RageSoundReader_Filter::Read( pBuf, iFrames ); } diff --git a/stepmania/src/RageSoundReader_PitchChange.h b/stepmania/src/RageSoundReader_PitchChange.h index 4c0673671a..c8eeb25d13 100644 --- a/stepmania/src/RageSoundReader_PitchChange.h +++ b/stepmania/src/RageSoundReader_PitchChange.h @@ -27,6 +27,8 @@ private: float m_fSpeedRatio; float m_fPitchRatio; + float m_fLastSetSpeedRatio; + float m_fLastSetPitchRatio; }; #endif