From ce6b11a3438997287c7e9ccf3b6b242b8bc3efd6 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 19 Jan 2004 20:37:14 +0000 Subject: [PATCH] RageSound::CleanPosMap --- stepmania/src/RageSound.cpp | 20 ++++++++++++++++++-- stepmania/src/RageSound.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index ea072e20b5..73453e26f9 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -393,9 +393,9 @@ int RageSound::GetPCM(char *buffer, int size, int sampleno) LockMut(SOUNDMAN->lock); ASSERT(playing); + /* Erase old pos_map data. */ - while(pos_map.size() > 1 && pos_map.back().sampleno - pos_map.front().sampleno > pos_map_backlog_samples) - pos_map.pop_front(); + CleanPosMap( pos_map ); /* * "sampleno" is the audio driver's conception of time. "position" @@ -621,6 +621,22 @@ int RageSound::SearchPosMap( const deque &pos_map, int cur_sample, bo return closest_position; } +void RageSound::CleanPosMap( deque &pos_map ) +{ + /* Determine the number of frames of data we have. */ + int total_frames = 0; + for( unsigned i = 0; i < pos_map.size(); ++i ) + total_frames += pos_map[i].samples; + + /* Remove the oldest entry so long we'll stil have enough data. Don't delete every + * sample, so we'll always have some data to extrapolate from. */ + while( pos_map.size() > 1 && total_frames - pos_map.front().samples > pos_map_backlog_samples ) + { + total_frames -= pos_map.front().samples; + pos_map.pop_front(); + } +} + /* Get the position in frames (ignoring GetOffsetFix). */ int RageSound::GetPositionSecondsInternal( bool *approximate ) const { diff --git a/stepmania/src/RageSound.h b/stepmania/src/RageSound.h index d3ef645ab6..ea24d0b432 100644 --- a/stepmania/src/RageSound.h +++ b/stepmania/src/RageSound.h @@ -106,6 +106,7 @@ private: }; deque pos_map; static int SearchPosMap( const deque &pos_map, int cur_sample, bool *approximate ); + static void CleanPosMap( deque &pos_map ); CString m_sFilePath;