From 24624a5c9227a8a7acd8e0d13fbc14e02b16ca96 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 22 Dec 2006 21:24:19 +0000 Subject: [PATCH] GetDataToPlay API more like RSR::Read --- stepmania/src/RageSound.cpp | 8 ++++---- stepmania/src/RageSound.h | 4 ++-- .../src/arch/Sound/RageSoundDriver_Generic_Software.cpp | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index a0581a7884..0a9235227a 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -366,7 +366,7 @@ int RageSound::GetData( char *pBuffer, int iFrames ) * * If no data is returned (we're at the end of the stream), return false. */ -bool RageSound::GetDataToPlay( int16_t *pBuffer, int iFrames, int64_t &iStreamFrame, int &iFramesStored ) +int RageSound::GetDataToPlay( int16_t *pBuffer, int iFrames, int64_t &iStreamFrame, int &iFramesStored ) { int iNumRewindsThisCall = 0; @@ -390,7 +390,7 @@ bool RageSound::GetDataToPlay( int16_t *pBuffer, int iFrames, int64_t &iStreamFr { case RageSoundParams::M_STOP: /* Not looping. Normally, we'll just stop here. */ - return false; + return RageSoundReader::END_OF_FILE; case RageSoundParams::M_LOOP: /* Rewind and restart. */ @@ -405,7 +405,7 @@ bool RageSound::GetDataToPlay( int16_t *pBuffer, int iFrames, int64_t &iStreamFr LOG->Warn( "Sound %s is busy looping. Sound stopped (start = %f, length = %f)", GetLoadedFilePath().c_str(), m_Param.m_StartSecond, m_Param.m_LengthSeconds ); - return false; + return RageSoundReader::END_OF_FILE; } /* Rewind and start over. XXX: this will take an exclusive lock */ @@ -425,7 +425,7 @@ bool RageSound::GetDataToPlay( int16_t *pBuffer, int iFrames, int64_t &iStreamFr iFrames -= iGotFrames; pBuffer += iGotFrames * channels; } - return true; + return iFramesStored; } /* Indicate that a block of audio data has been written to the device. */ diff --git a/stepmania/src/RageSound.h b/stepmania/src/RageSound.h index 400cfb0077..66003429ca 100644 --- a/stepmania/src/RageSound.h +++ b/stepmania/src/RageSound.h @@ -16,7 +16,7 @@ class RageSoundBase public: virtual ~RageSoundBase() { } virtual void SoundIsFinishedPlaying() = 0; - virtual bool GetDataToPlay( int16_t *buffer, int size, int64_t &iStreamFrame, int &got_bytes ) = 0; + virtual int GetDataToPlay( int16_t *buffer, int size, int64_t &iStreamFrame, int &got_bytes ) = 0; virtual int GetSampleRate() const = 0; virtual RageTimer GetStartTime() const { return RageZeroTimer; } virtual float GetAbsoluteVolume() const = 0; @@ -201,7 +201,7 @@ public: * signals the stream to stop; once it's flushed, SoundStopped will be called. * Until then, SOUNDMAN->GetPosition can still be called; the sound is still * playing. */ - bool GetDataToPlay( int16_t *pBuffer, int iSize, int64_t &iStreamFrame, int &iBytesRead ); + int GetDataToPlay( int16_t *pBuffer, int iSize, int64_t &iStreamFrame, int &iBytesRead ); void CommitPlayingPosition( int64_t iFrameno, int64_t iPosition, int iBytesRead ); }; diff --git a/stepmania/src/arch/Sound/RageSoundDriver_Generic_Software.cpp b/stepmania/src/arch/Sound/RageSoundDriver_Generic_Software.cpp index 141cd6a84e..e4423572be 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_Generic_Software.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_Generic_Software.cpp @@ -6,6 +6,7 @@ #include "RageUtil.h" #include "RageSoundManager.h" #include "RageSoundMixBuffer.h" +#include "RageSoundReader.h" static const int channels = 2; static const int bytes_per_frame = channels*2; /* 16-bit */ @@ -233,7 +234,7 @@ void RageSound_Generic_Software::DecodeThread() } int iWrote = GetDataForSound( *pSound ); - if( !iWrote ) + if( iWrote == RageSoundReader::END_OF_FILE ) { /* This sound is finishing. */ pSound->m_State = Sound::STOPPING; @@ -375,7 +376,7 @@ void RageSound_Generic_Software::StartMixing( RageSoundBase *pSound ) // LOG->Trace("StartMixing: (#%i) buffering %i (%i writable) (%p)", i, (int) frames_to_buffer, s.buffer.num_writable(), s.m_pSound ); int iWrote = GetDataForSound( s ); iFramesFilled += iWrote; - if( !iWrote ) + if( iWrote < 0 ) { // LOG->Trace("StartMixing: XXX hit EOF (%p)", s.m_pSound ); break;