From bc097b6b03f8c2f2053d429950fd535873ed625f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 23 Dec 2006 10:53:39 +0000 Subject: [PATCH] clamp hardware frames in RageSoundDriver, instead of in each sound --- stepmania/src/RageSound.cpp | 21 --------------- stepmania/src/RageSound.h | 3 --- stepmania/src/arch/Sound/RageSoundDriver.h | 3 +++ .../RageSoundDriver_Generic_Software.cpp | 26 +++++++++++++++++-- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index a8630f06df..b3e3acc9fe 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -67,7 +67,6 @@ RageSound::RageSound(): m_pSource = NULL; m_iStreamFrame = 0; m_iStoppedSourceFrame = 0; - m_iMaxDriverFrame = 0; m_bPlaying = false; } @@ -94,7 +93,6 @@ RageSound &RageSound::operator=( const RageSound &cpy ) m_Param = cpy.m_Param; m_iStreamFrame = cpy.m_iStreamFrame; m_iStoppedSourceFrame = cpy.m_iStoppedSourceFrame; - m_iMaxDriverFrame = 0; m_bPlaying = false; delete m_pSource; @@ -357,7 +355,6 @@ void RageSound::SoundIsFinishedPlaying() // LOG->Trace("set playing false for %p (SoundIsFinishedPlaying) (%s)", this, this->GetLoadedFilePath().c_str()); m_bPlaying = false; - m_iMaxDriverFrame = 0; m_HardwareToStreamMap.Clear(); m_StreamToSourceMap.Clear(); @@ -438,24 +435,6 @@ int64_t RageSound::GetPositionSecondsInternal( bool *bApproximate, RageTimer *pT /* Get our current hardware position. */ int64_t iCurrentHardwareFrame = SOUNDMAN->GetPosition( pTimer ); - /* It's sometimes possible for the hardware position to move backwards, usually - * on underrun. We can try to prevent this in each driver, but it's an obscure - * error, so let's clamp the result here instead. Be sure to reset this on stop, - * since the position may reset. */ - if( iCurrentHardwareFrame < m_iMaxDriverFrame ) - { - /* Clamp the output to one per second, so one underruns don't cascade due to - * output spam. */ - static RageTimer last(RageZeroTimer); - if( last.IsZero() || last.Ago() > 1.0f ) - { - LOG->Trace( "Sound %s: driver returned a lesser position (%i < %i)", - this->GetLoadedFilePath().c_str(), (int) iCurrentHardwareFrame, (int) m_iMaxDriverFrame ); - last.Touch(); - } - } - m_iMaxDriverFrame = iCurrentHardwareFrame = max( iCurrentHardwareFrame, m_iMaxDriverFrame ); - bool bApprox; int64_t iStreamFrame = m_HardwareToStreamMap.Search( iCurrentHardwareFrame, &bApprox ); if( bApproximate && bApprox ) diff --git a/stepmania/src/RageSound.h b/stepmania/src/RageSound.h index cf39124ee5..e25ef9c9fd 100644 --- a/stepmania/src/RageSound.h +++ b/stepmania/src/RageSound.h @@ -171,9 +171,6 @@ private: int m_iStoppedSourceFrame; bool m_bPlaying; - /* Keep track of the max SOUNDMAN->GetPosition result (see GetPositionSecondsInternal). */ - mutable int64_t m_iMaxDriverFrame; - RString m_sError; int64_t GetPositionSecondsInternal( bool *bApproximate = NULL, RageTimer *pTimer = NULL ) const; diff --git a/stepmania/src/arch/Sound/RageSoundDriver.h b/stepmania/src/arch/Sound/RageSoundDriver.h index 1983d463f2..af91416702 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver.h +++ b/stepmania/src/arch/Sound/RageSoundDriver.h @@ -194,6 +194,9 @@ private: /* List of currently playing sounds: XXX no vector */ Sound m_Sounds[32]; + int64_t ClampHardwareFrame( int64_t iHardwareFrame ) const; + mutable int64_t m_iMaxHardwareFrame; + bool m_bShutdownDecodeThread; static int DecodeThread_start( void *p ); diff --git a/stepmania/src/arch/Sound/RageSoundDriver_Generic_Software.cpp b/stepmania/src/arch/Sound/RageSoundDriver_Generic_Software.cpp index 2f671588aa..2165663182 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_Generic_Software.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_Generic_Software.cpp @@ -464,10 +464,32 @@ RageSoundDriver::~RageSoundDriver() } } +int64_t RageSoundDriver::ClampHardwareFrame( int64_t iHardwareFrame ) const +{ + /* It's sometimes possible for the hardware position to move backwards, usually + * on underrun. We can try to prevent this in each driver, but it's an obscure + * error, so let's clamp the result here instead. */ + if( iHardwareFrame < m_iMaxHardwareFrame ) + { + /* Clamp the output to one per second, so one underruns don't cascade due to + * output spam. */ + static RageTimer last(RageZeroTimer); + if( last.IsZero() || last.Ago() > 1.0f ) + { + LOG->Trace( "RageSoundDriver: driver returned a lesser position (%i < %i)", + (int) iHardwareFrame, (int) m_iMaxHardwareFrame ); + last.Touch(); + } + return m_iMaxHardwareFrame; + } + m_iMaxHardwareFrame = iHardwareFrame = max( iHardwareFrame, m_iMaxHardwareFrame ); + return iHardwareFrame; +} + int64_t RageSoundDriver::GetHardwareFrame( RageTimer *pTimestamp ) const { if( pTimestamp == NULL ) - return GetPosition(); + return ClampHardwareFrame( GetPosition() ); /* * We may have unpredictable scheduling delays between updating the timestamp @@ -496,7 +518,7 @@ int64_t RageSoundDriver::GetHardwareFrame( RageTimer *pTimestamp ) const } } - return iPositionFrames; + return ClampHardwareFrame( iPositionFrames ); } /*