clamp hardware frames in RageSoundDriver, instead of in each sound
This commit is contained in:
@@ -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 )
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user