aboutsummaryrefslogtreecommitdiff
path: root/sound/softsynth
diff options
context:
space:
mode:
authorFlorian Kagerer2010-08-20 17:04:32 +0000
committerFlorian Kagerer2010-08-20 17:04:32 +0000
commitb55a70acb88a7375ac21351450ea99ed2f72d820 (patch)
treeb8b0becec25f5d26551bcfd908e38dbfd8f665af /sound/softsynth
parent9d5dada110c5563fd77ed19b061ee1a92cde952c (diff)
downloadscummvm-rg350-b55a70acb88a7375ac21351450ea99ed2f72d820.tar.gz
scummvm-rg350-b55a70acb88a7375ac21351450ea99ed2f72d820.tar.bz2
scummvm-rg350-b55a70acb88a7375ac21351450ea99ed2f72d820.zip
KYRA/TOWNS: fix memory leak and some cleanup
svn-id: r52232
Diffstat (limited to 'sound/softsynth')
-rw-r--r--sound/softsynth/fmtowns_pc98/towns_audio.cpp7
-rw-r--r--sound/softsynth/fmtowns_pc98/towns_pc98_driver.cpp9
-rw-r--r--sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp20
-rw-r--r--sound/softsynth/fmtowns_pc98/towns_pc98_fmsynth.h11
4 files changed, 18 insertions, 29 deletions
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;