From 3a1d1e129fb85d897bea69c7a408232b77123dc3 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 22 Dec 2006 06:14:20 +0000 Subject: [PATCH] use RetriedRead --- stepmania/src/RageSound.cpp | 35 +++++-------------------- stepmania/src/RageSoundReader_Chain.cpp | 2 +- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index a4299cdef9..a0581a7884 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -284,41 +284,20 @@ int RageSound::GetData( char *pBuffer, int iFrames ) /* Read data from our source. */ ASSERT( m_pSource ); - fRate = m_pSource->GetStreamToSourceRatio(); - int iNewSourceFrame = m_pSource->GetNextSourceFrame(); + int iNewSourceFrame; + iGotFrames = m_pSource->RetriedRead( pBuffer, iFrames, &iNewSourceFrame, &fRate ); - /* m_pSource->Read() may return 0, which means "try again immediately". As - * a failsafe, only try this a finite number of times. Use a high number, - * because in principle each filter in the stack may cause this. */ - int iTries = 100; - while( iGotFrames == 0 && --iTries ) + if( iGotFrames == RageSoundReader::ERROR ) { - iGotFrames = m_pSource->Read( pBuffer, iFrames ); - if( iGotFrames == RageSoundReader::ERROR ) - { - Fail( m_pSource->GetError() ); - - /* Pretend we got EOF. */ - return 0; - } - - if( iGotFrames == RageSoundReader::END_OF_FILE ) - { - iGotFrames = 0; - break; - } - - ASSERT_M( iGotFrames >= 0, ssprintf("%i", iGotFrames) ); // unhandled error condition - } - - if( iTries == 0 ) - { - Fail( "Read() busy looping" ); + Fail( m_pSource->GetError() ); /* Pretend we got EOF. */ return 0; } + if( iGotFrames == RageSoundReader::END_OF_FILE ) + iGotFrames = 0; + /* If we didn't get any data, don't update iSourceFrame, so we just keep * extrapolating if we're in M_CONTINUE. */ if( iGotFrames == 0 ) diff --git a/stepmania/src/RageSoundReader_Chain.cpp b/stepmania/src/RageSoundReader_Chain.cpp index f69e87d2f3..d54f173553 100644 --- a/stepmania/src/RageSoundReader_Chain.cpp +++ b/stepmania/src/RageSoundReader_Chain.cpp @@ -370,7 +370,7 @@ int RageSoundReader_Chain::Read( char *pBuffer, int iFrames ) int iFramesRead = 0; while( iFramesRead < iFrames ) { - int iGotFrames = pSound->Read( (char *) Buffer, iFrames - iFramesRead ); + int iGotFrames = pSound->RetriedRead( (char *) Buffer, iFrames - iFramesRead ); if( iGotFrames < 0 ) { iFramesRead = iGotFrames;