From ecc5493c888dfe10de5507b886462dc4983d2be6 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 10 Sep 2004 01:49:39 +0000 Subject: [PATCH] don't bother checking for minor underruns if we have a major underrun --- stepmania/src/arch/Sound/DSoundHelpers.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/stepmania/src/arch/Sound/DSoundHelpers.cpp b/stepmania/src/arch/Sound/DSoundHelpers.cpp index e447c0a667..458395fb7e 100644 --- a/stepmania/src/arch/Sound/DSoundHelpers.cpp +++ b/stepmania/src/arch/Sound/DSoundHelpers.cpp @@ -365,19 +365,23 @@ void DSoundBuf::CheckUnderrun( int cursorstart, int cursorend, int chunksize ) * Realign. */ if( buffer_bytes_filled == 0 ) { - /* There's no data filled at all. We've completely underrun. */ - /* XXX */ - + /* There's no data filled at all. We've completely underrun. Pretend that + * the prefetch is full, and point our write cursor just after it. This way, + * we don't write into the prefetch; doing so shouldn't cause problems, but + * let's play it safe. Pretending the prefetch is full (instead of just moving + * the write cursor) takes us out of a "major underrun" state. */ int missed_by = cursorend - write_cursor; wrap( missed_by, buffersize ); int first_byte_filled = write_cursor-buffer_bytes_filled; wrap( first_byte_filled, buffersize ); - LOG->Trace("major underrun: %i..%i filled but cursor at %i..%i (missed it by %i) %i/%i", - first_byte_filled, write_cursor, cursorstart, cursorend, - missed_by, buffer_bytes_filled, buffersize); + LOG->Trace( "major underrun: %i..%i filled but cursor at %i..%i (missed it by %i)", + first_byte_filled, write_cursor, cursorstart, cursorend, missed_by ); - write_cursor = cursorstart; + write_cursor = cursorend; + buffer_bytes_filled = int(cursorend) - cursorstart; + wrap( buffer_bytes_filled, buffersize ); + return; } /* @@ -405,8 +409,9 @@ void DSoundBuf::CheckUnderrun( int cursorstart, int cursorend, int chunksize ) * ....pppp.... * 5: ....ff...... valid * ....pppp.... - * 6: ............ valid (no data filled) + * 6: ............ * ....pppp.... + * invalid: buffer_bytes_filled == 0; we handled this above */ int first_byte_filled = write_cursor-buffer_bytes_filled; wrap( first_byte_filled, buffersize );