From 5b5a812d3750cc1e8063ccfc8d1d9bf4db6a127b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 11 Jun 2012 12:20:12 +1000 Subject: TONY: Implemented process to properly set hEndOfBuffer when sound effects end --- engines/tony/sound.cpp | 35 +++++++++++++++++++++++++++++++++++ engines/tony/sound.h | 9 +++++++++ engines/tony/tony.cpp | 3 +++ engines/tony/tony.h | 1 + 4 files changed, 48 insertions(+) (limited to 'engines') diff --git a/engines/tony/sound.cpp b/engines/tony/sound.cpp index 1fb4bbee1f..487bf54111 100644 --- a/engines/tony/sound.cpp +++ b/engines/tony/sound.cpp @@ -201,6 +201,8 @@ FPSFX::FPSFX(bool bSoundOn) { _stream = 0; _rewindableStream = 0; bPaused = false; + + _vm->_activeSfx.push_back(this); } @@ -219,6 +221,7 @@ FPSFX::~FPSFX() { return; g_system->getMixer()->stopHandle(_handle); + _vm->_activeSfx.remove(this); delete _stream; // _rewindableStream is deleted by deleting _stream @@ -488,6 +491,38 @@ void FPSFX::GetVolume(int *lpdwVolume) { *lpdwVolume = 0; } +/** + * Returns true if the underlying sound has ended + */ +bool FPSFX::endOfBuffer() const { + return !g_system->getMixer()->isSoundHandleActive(_handle) && (!_stream || _stream->endOfData()); +} + +/** + * Continually checks to see if active sounds have finished playing + * Sets the event signalling the sound has ended + */ +void FPSFX::soundCheckProcess(CORO_PARAM, const void *param) { + CORO_BEGIN_CONTEXT; + Common::List::iterator i; + CORO_END_CONTEXT(_ctx); + + CORO_BEGIN_CODE(_ctx); + + for (;;) { + // Check each active sound + for (_ctx->i = _vm->_activeSfx.begin(); _ctx->i != _vm->_activeSfx.end(); ++_ctx->i) { + FPSFX *sfx = *_ctx->i; + if (sfx->endOfBuffer()) + CoroScheduler.setEvent(sfx->hEndOfBuffer); + } + + // Delay until the next check is done + CORO_INVOKE_1(CoroScheduler.sleep, 50); + } + + CORO_END_CODE; +} /****************************************************************************\ * Metodi di FPSTREAM diff --git a/engines/tony/sound.h b/engines/tony/sound.h index c64680a9cf..6593470d0c 100644 --- a/engines/tony/sound.h +++ b/engines/tony/sound.h @@ -209,6 +209,10 @@ private: \****************************************************************************/ public: + /** + * Check process for whether sounds have finished playing + */ + static void soundCheckProcess(CORO_PARAM, const void *param); /****************************************************************************\ * @@ -353,6 +357,11 @@ public: \****************************************************************************/ void GetVolume(int *lpdwVolume); + + /** + * Returns true if the sound has finished playing + */ + bool endOfBuffer() const; }; class FPSTREAM { diff --git a/engines/tony/tony.cpp b/engines/tony/tony.cpp index 2b9d8fbc20..b1e45c8bfa 100644 --- a/engines/tony/tony.cpp +++ b/engines/tony/tony.cpp @@ -371,6 +371,9 @@ void TonyEngine::initMusic() { // Preload sound effects preloadUtilSFX(0, "U01.ADP"); // Reversed!! preloadUtilSFX(1, "U02.ADP"); + + // Start check processes for sound + CoroScheduler.createProcess(FPSFX::soundCheckProcess, NULL); } void TonyEngine::closeMusic() { diff --git a/engines/tony/tony.h b/engines/tony/tony.h index cee15d07a4..43bc23c636 100644 --- a/engines/tony/tony.h +++ b/engines/tony/tony.h @@ -100,6 +100,7 @@ public: Common::File _vdbFP; Common::Array _voices; FPSOUND _theSound; + Common::List _activeSfx; Globals _globals; Debugger *_debugger; -- cgit v1.2.3