From a22b272aeb3348f3f714ec453a413acaa13a2aa7 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 11 Mar 2005 00:41:24 +0000 Subject: [PATCH] pause support --- .../src/arch/Sound/RageSoundDriver_ALSA9.cpp | 25 +++++++++++++++++++ .../src/arch/Sound/RageSoundDriver_ALSA9.h | 4 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp index 14590df7a2..907cd97570 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp @@ -41,6 +41,9 @@ void RageSound_ALSA9::MixerThread() stream_pool[i]->state != stream::FLUSHING ) continue; /* inactive */ + if( stream_pool[i]->bPaused ) + continue; /* paused */ + bool bEOF = false; while( !shutdown && stream_pool[i]->GetData(bEOF) && !bEOF ) ; @@ -68,6 +71,7 @@ void RageSound_ALSA9::MixerThread() continue; /* stopping but still flushing */ /* The sound has stopped and flushed all of its buffers. */ + stream_pool[i]->bPaused = false; stream_pool[i]->pcm->Stop(); stream_pool[i]->state = stream::FINISHED; } @@ -247,6 +251,27 @@ void RageSound_ALSA9::StopMixing(RageSoundBase *snd) stream_pool[i]->snd = NULL; } +bool RageSound_ALSA9::PauseMixing( RageSoundBase *snd, bool bStop ) +{ + unsigned i; + for( i = 0; i < stream_pool.size(); ++i ) + if(stream_pool[i]->snd == snd) + break; + + /* A sound can be paused in PLAYING or FLUSHING. (FLUSHING means the sound + * has been decoded to the end, and we're waiting for that data to finish, so + * externally it looks and acts like PLAYING.) */ + if( i == stream_pool.size() || + (stream_pool[i]->state != stream::PLAYING && stream_pool[i]->state != stream::FLUSHING) ) + { + LOG->Trace("not stopping a sound because it's not playing"); + return false; + } + + stream_pool[i]->bPaused = bStop; + + return true; +} int64_t RageSound_ALSA9::GetPosition(const RageSoundBase *snd) const { diff --git a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.h b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.h index 549b506cac..d4a0ba7b79 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.h +++ b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.h @@ -13,6 +13,7 @@ public: /* virtuals: */ void StartMixing(RageSoundBase *snd); void StopMixing(RageSoundBase *snd); + bool PauseMixing( RageSoundBase *snd, bool bStop ); int64_t GetPosition( const RageSoundBase *snd ) const; int GetSampleRate( int rate ) const; @@ -39,6 +40,7 @@ private: * channel is available: */ RageSoundBase *snd; RageTimer start_time; + bool bPaused; enum { INACTIVE, @@ -52,7 +54,7 @@ private: bool GetData( bool &bEOF ); - stream() { pcm = NULL; snd = NULL; state=INACTIVE; } + stream() { pcm = NULL; snd = NULL; state = INACTIVE; bPaused = false; } ~stream(); }; friend struct stream;