From b55a70acb88a7375ac21351450ea99ed2f72d820 Mon Sep 17 00:00:00 2001 From: Florian Kagerer Date: Fri, 20 Aug 2010 17:04:32 +0000 Subject: KYRA/TOWNS: fix memory leak and some cleanup svn-id: r52232 --- sound/softsynth/fmtowns_pc98/towns_audio.cpp | 7 +------ sound/softsynth/fmtowns_pc98/towns_pc98_driver.cpp | 9 +-------- sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp | 20 ++++++++++---------- sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.h | 11 ++++++----- 4 files changed, 18 insertions(+), 29 deletions(-) (limited to 'sound/softsynth') diff --git a/sound/softsynth/fmtowns_pc98/towns_audio.cpp b/sound/softsynth/fmtowns_pc98/towns_audio.cpp index bef062b8e6..bbc4891edc 100644 --- a/sound/softsynth/fmtowns_pc98/towns_audio.cpp +++ b/sound/softsynth/fmtowns_pc98/towns_audio.cpp @@ -222,19 +222,14 @@ TownsAudioInterface::TownsAudioInterface(Audio::Mixer *mixer, TownsAudioInterfac _timerBase = (uint32)(_baserate * 1000000.0f); _tickLength = 2 * _timerBase; - - setTimerCallbackA((ChipTimerProc)&TownsAudioInterface::timerCallbackA); - setTimerCallbackB((ChipTimerProc)&TownsAudioInterface::timerCallbackB); } TownsAudioInterface::~TownsAudioInterface() { Common::StackLock lock(_mutex); reset(); + deinit(); _ready = false; - setTimerCallbackA(); - setTimerCallbackB(); - delete[] _fmSaveReg[0]; delete[] _fmSaveReg[1]; delete[] _fmInstruments; diff --git a/sound/softsynth/fmtowns_pc98/towns_pc98_driver.cpp b/sound/softsynth/fmtowns_pc98/towns_pc98_driver.cpp index 6d52937cc6..7b7fbddc4b 100644 --- a/sound/softsynth/fmtowns_pc98/towns_pc98_driver.cpp +++ b/sound/softsynth/fmtowns_pc98/towns_pc98_driver.cpp @@ -1037,21 +1037,14 @@ TownsPC98_AudioDriver::TownsPC98_AudioDriver(Audio::Mixer *mixer, EmuType type) _musicPlaying(false), _sfxPlaying(false), _fading(false), _looping(0), _ready(false) { _sfxOffsets[0] = _sfxOffsets[1] = 0; - - setTimerCallbackA((ChipTimerProc)&TownsPC98_AudioDriver::timerCallbackA); - setTimerCallbackB((ChipTimerProc)&TownsPC98_AudioDriver::timerCallbackB); } TownsPC98_AudioDriver::~TownsPC98_AudioDriver() { Common::StackLock lock(_mutex); - reset(); - + deinit(); _ready = false; - setTimerCallbackA(); - setTimerCallbackB(); - if (_channels) { for (int i = 0; i < _numChan; i++) delete _channels[i]; diff --git a/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp b/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp index e304537c22..b51f695087 100644 --- a/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp +++ b/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp @@ -842,11 +842,9 @@ TownsPC98_FmSynth::TownsPC98_FmSynth(Audio::Mixer *mixer, EmuType type) : } TownsPC98_FmSynth::~TownsPC98_FmSynth() { - Common::StackLock lock(_mutex); - - _ready = false; + if (_ready) + deinit(); - _mixer->stopHandle(_soundHandle); delete _ssg; delete _prc; delete[] _chanInternal; @@ -885,6 +883,9 @@ bool TownsPC98_FmSynth::init() { _prc->init(_percussionData); } + _timers[0].cb = &TownsPC98_FmSynth::timerCallbackA; + _timers[1].cb = &TownsPC98_FmSynth::timerCallbackB; + _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); @@ -1158,12 +1159,11 @@ int TownsPC98_FmSynth::readBuffer(int16 *buffer, const int numSamples) { return numSamples; } -void TownsPC98_FmSynth::setTimerCallbackA(ChipTimerProc proc) { - _timers[0].cb = proc; -} - -void TownsPC98_FmSynth::setTimerCallbackB(ChipTimerProc proc) { - _timers[1].cb = proc; +void TownsPC98_FmSynth::deinit() { + _mixer->stopHandle(_soundHandle); + _timers[0].cb = &TownsPC98_FmSynth::idleTimerCallback; + _timers[1].cb = &TownsPC98_FmSynth::idleTimerCallback; + _ready = false; } uint8 TownsPC98_FmSynth::readSSGStatus() { diff --git a/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.h b/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.h index 4c2de467d7..17bb98482c 100644 --- a/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.h +++ b/sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.h @@ -71,9 +71,7 @@ public: } protected: - typedef void (TownsPC98_FmSynth::*ChipTimerProc)(); - void setTimerCallbackA(ChipTimerProc proc = &TownsPC98_FmSynth::timerCallbackA); - void setTimerCallbackB(ChipTimerProc proc = &TownsPC98_FmSynth::timerCallbackB); + void deinit(); // Implement this in your inherited class if your driver generates // additional output that has to be inserted into the buffer. @@ -84,8 +82,8 @@ protected: } uint8 readSSGStatus(); - virtual void timerCallbackA() {} - virtual void timerCallbackB() {} + virtual void timerCallbackA() = 0; + virtual void timerCallbackB() = 0; // The audio driver can store and apply two different audio settings // (usually for music and sound effects). The channel mask will determine @@ -143,6 +141,9 @@ private: bool _regProtectionFlag; + typedef void (TownsPC98_FmSynth::*ChipTimerProc)(); + void idleTimerCallback() {}; + struct ChipTimer { bool enabled; uint16 value; -- cgit v1.2.3