From 9a74f9be013624e1e480f12e79bd88956203c327 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 25 Mar 2004 02:24:39 +0000 Subject: [PATCH] optimizion for small chunksizes --- stepmania/src/RageSound.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 80e81da2f4..21131063e7 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -197,6 +197,9 @@ void RageSound::Update(float delta) // if( playing && delta ) // FillBuf(int(delta * GetSampleRate() * framesize)); + + /* Erase old pos_map data. */ + CleanPosMap( pos_map ); } /* Return the number of bytes available in the input buffer. */ @@ -504,11 +507,20 @@ bool RageSound::GetDataToPlay( int16_t *buffer, int size, int &sound_frame, int void RageSound::CommitPlayingPosition( int64_t frameno, int pos, int got_frames ) { LockMut(SOUNDMAN->lock); - pos_map_t p( frameno, pos, got_frames ); - pos_map.push_back( p ); - /* Erase old pos_map data. */ - CleanPosMap( pos_map ); + if( pos_map.size() ) + { + /* Optimization: If the last entry lines up with this new entry, just merge them. */ + pos_map_t &last = pos_map.back(); + if( last.frameno+last.frames == frameno && + last.position+last.frames == pos ) + { + last.frames += got_frames; + return; + } + } + + pos_map.push_back( pos_map_t( frameno, pos, got_frames ) ); } /* Called by the mixer: return a block of sound data.