From 8bcbcd6c167e8e7169f006da459f3cbe450a4a59 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Wed, 29 Apr 2015 23:45:25 -0400 Subject: AUDIO: Change callback frequency without restarting the audio stream --- audio/fmopl.cpp | 33 +++++++++++---------------------- audio/fmopl.h | 12 ++++-------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/audio/fmopl.cpp b/audio/fmopl.cpp index 638da6c224..9af7afff54 100644 --- a/audio/fmopl.cpp +++ b/audio/fmopl.cpp @@ -183,14 +183,6 @@ void OPL::stop() { _callback.reset(); } -void OPL::setCallbackFrequency(int timerFrequency) { - if (!isRunning()) - return; - - stopCallbacks(); - startCallbacks(timerFrequency); -} - bool OPL::_hasInstance = false; EmulatedOPL::EmulatedOPL() : @@ -239,6 +231,17 @@ int EmulatedOPL::getRate() const { } void EmulatedOPL::startCallbacks(int timerFrequency) { + setCallbackFrequency(timerFrequency); + // TODO: Eventually start mixer playback here + //g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, _handle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); +} + +void EmulatedOPL::stopCallbacks() { + // TODO: Eventually stop mixer playback here + //g_system->getMixer()->stopHandle(*_handle); +} + +void EmulatedOPL::setCallbackFrequency(int timerFrequency) { _baseFreq = timerFrequency; assert(_baseFreq != 0); @@ -249,20 +252,6 @@ void EmulatedOPL::startCallbacks(int timerFrequency) { // but less prone to arithmetic overflow. _samplesPerTick = (d << FIXP_SHIFT) + (r << FIXP_SHIFT) / _baseFreq; - - // TODO: Eventually start mixer playback here - //g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, _handle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); -} - -void EmulatedOPL::stopCallbacks() { - // TODO: Eventually stop mixer playback here - //g_system->getMixer()->stopHandle(*_handle); -} - -bool EmulatedOPL::isRunning() const { - // TODO - //return g_system->getMixer()->isSoundHandleActive(*_handle); - return true; } } // End of namespace OPL diff --git a/audio/fmopl.h b/audio/fmopl.h index 243cd294e8..8baa9aa218 100644 --- a/audio/fmopl.h +++ b/audio/fmopl.h @@ -176,15 +176,10 @@ public: void stop(); /** - * Is the OPL running? + * Change the callback frequency. This must only be called from a + * timer proc. */ - virtual bool isRunning() const = 0; - - /** - * Change the callback frequency. This has no effect if start() - * has not already been called. - */ - void setCallbackFrequency(int timerFrequency); + virtual void setCallbackFrequency(int timerFrequency) = 0; enum { /** @@ -218,6 +213,7 @@ public: // OPL API int readBuffer(int16 *buffer, const int numSamples); bool isRunning() const; + void setCallbackFrequency(int timerFrequency); int getRate() const; -- cgit v1.2.3