From efcf87a6e5d9be34839cb60e3b257fe330a3b103 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 5 Sep 2014 22:21:24 -0400 Subject: MADS: Fix OPL init error when showing credits multiple times --- engines/mads/mads.cpp | 8 +++++++- engines/mads/mads.h | 1 + engines/mads/nebular/sound_nebular.cpp | 27 ++++++++++++--------------- engines/mads/nebular/sound_nebular.h | 22 ++++++++++++---------- engines/mads/sound.cpp | 21 +++++++++++---------- engines/mads/sound.h | 3 ++- 6 files changed, 45 insertions(+), 37 deletions(-) (limited to 'engines') diff --git a/engines/mads/mads.cpp b/engines/mads/mads.cpp index 6c1b436e3b..126b89dc34 100644 --- a/engines/mads/mads.cpp +++ b/engines/mads/mads.cpp @@ -55,6 +55,7 @@ MADSEngine::MADSEngine(OSystem *syst, const MADSGameDescription *gameDesc) : _resources = nullptr; _sound = nullptr; _audio = nullptr; + _opl = nullptr; } MADSEngine::~MADSEngine() { @@ -68,6 +69,8 @@ MADSEngine::~MADSEngine() { delete _resources; delete _sound; delete _audio; + + delete _opl; } void MADSEngine::initialize() { @@ -76,6 +79,9 @@ void MADSEngine::initialize() { DebugMan.addDebugChannel(kDebugScripts, "scripts", "Game scripts"); DebugMan.addDebugChannel(kDebugGraphics, "graphics", "Graphics handling"); + _opl = OPL::Config::create(); + _opl->init(11025); + // Initial sub-system engine references MSurface::setVm(this); MSprite::setVm(this); @@ -89,7 +95,7 @@ void MADSEngine::initialize() { Font::init(this); _font = new Font(); _screen.init(); - _sound = new SoundManager(this, _mixer); + _sound = new SoundManager(this, _mixer, _opl); _audio = new AudioPlayer(_mixer, getGameID()); _game = Game::init(this); diff --git a/engines/mads/mads.h b/engines/mads/mads.h index 9a8f2152a1..8fc2788c28 100644 --- a/engines/mads/mads.h +++ b/engines/mads/mads.h @@ -99,6 +99,7 @@ public: ScreenSurface _screen; SoundManager *_sound; AudioPlayer *_audio; + FM_OPL *_opl; bool _easyMouse; bool _invObjectsAnimated; bool _textWindowStill; diff --git a/engines/mads/nebular/sound_nebular.cpp b/engines/mads/nebular/sound_nebular.cpp index b46863cea3..5ce362e053 100644 --- a/engines/mads/nebular/sound_nebular.cpp +++ b/engines/mads/nebular/sound_nebular.cpp @@ -149,7 +149,7 @@ AdlibSample::AdlibSample(Common::SeekableReadStream &s) { /*-----------------------------------------------------------------------*/ -ASound::ASound(Audio::Mixer *mixer, const Common::String &filename, int dataOffset) { +ASound::ASound(Audio::Mixer *mixer, FM_OPL *opl, const Common::String &filename, int dataOffset) { // Open up the appropriate sound file if (!_soundFile.open(filename)) error("Could not open file - %s", filename.c_str()); @@ -197,8 +197,7 @@ ASound::ASound(Audio::Mixer *mixer, const Common::String &filename, int dataOffs // Store passed parameters, and setup OPL _dataOffset = dataOffset; _mixer = mixer; - _opl = OPL::Config::create(); - assert(_opl); + _opl = opl; _opl->init(getRate()); _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, @@ -217,8 +216,6 @@ ASound::~ASound() { delete[] (*i)._data; _mixer->stopHandle(_soundHandle); - _opl->reset(); - delete _opl; } void ASound::adlibInit() { @@ -942,8 +939,8 @@ const ASound1::CommandPtr ASound1::_commandList[42] = { &ASound1::command40, &ASound1::command41 }; -ASound1::ASound1(Audio::Mixer *mixer) - : ASound(mixer, "asound.001", 0x1520) { +ASound1::ASound1(Audio::Mixer *mixer, FM_OPL *opl) + : ASound(mixer, opl, "asound.001", 0x1520) { _cmd23Toggle = false; // Load sound samples @@ -1243,7 +1240,7 @@ const ASound2::CommandPtr ASound2::_commandList[44] = { &ASound2::command40, &ASound2::command41, &ASound2::command42, &ASound2::command43 }; -ASound2::ASound2(Audio::Mixer *mixer) : ASound(mixer, "asound.002", 0x15E0) { +ASound2::ASound2(Audio::Mixer *mixer, FM_OPL *opl) : ASound(mixer, opl, "asound.002", 0x15E0) { _command12Param = 0xFD; // Load sound samples @@ -1614,7 +1611,7 @@ const ASound3::CommandPtr ASound3::_commandList[61] = { &ASound3::command60 }; -ASound3::ASound3(Audio::Mixer *mixer) : ASound(mixer, "asound.003", 0x15B0) { +ASound3::ASound3(Audio::Mixer *mixer, FM_OPL *opl) : ASound(mixer, opl, "asound.003", 0x15B0) { _command39Flag = false; // Load sound samples @@ -2018,7 +2015,7 @@ const ASound4::CommandPtr ASound4::_commandList[61] = { &ASound4::command60 }; -ASound4::ASound4(Audio::Mixer *mixer) : ASound(mixer, "asound.004", 0x14F0) { +ASound4::ASound4(Audio::Mixer *mixer, FM_OPL *opl) : ASound(mixer, opl, "asound.004", 0x14F0) { // Load sound samples _soundFile.seek(_dataOffset + 0x122); for (int i = 0; i < 210; ++i) @@ -2274,7 +2271,7 @@ const ASound5::CommandPtr ASound5::_commandList[42] = { &ASound5::command40, &ASound5::command41 }; -ASound5::ASound5(Audio::Mixer *mixer) : ASound(mixer, "asound.002", 0x15E0) { +ASound5::ASound5(Audio::Mixer *mixer, FM_OPL *opl) : ASound(mixer, opl, "asound.002", 0x15E0) { // Load sound samples _soundFile.seek(_dataOffset + 0x144); for (int i = 0; i < 164; ++i) @@ -2515,7 +2512,7 @@ const ASound6::CommandPtr ASound6::_commandList[30] = { &ASound6::nullCommand, &ASound6::command29 }; -ASound6::ASound6(Audio::Mixer *mixer) : ASound(mixer, "asound.006", 0x1390) { +ASound6::ASound6(Audio::Mixer *mixer, FM_OPL *opl) : ASound(mixer, opl, "asound.006", 0x1390) { // Load sound samples _soundFile.seek(_dataOffset + 0x122); for (int i = 0; i < 200; ++i) @@ -2671,7 +2668,7 @@ const ASound7::CommandPtr ASound7::_commandList[38] = { &ASound7::command36, &ASound7::command37 }; -ASound7::ASound7(Audio::Mixer *mixer) : ASound(mixer, "asound.007", 0x1460) { +ASound7::ASound7(Audio::Mixer *mixer, FM_OPL *opl) : ASound(mixer, opl, "asound.007", 0x1460) { // Load sound samples _soundFile.seek(_dataOffset + 0x122); for (int i = 0; i < 214; ++i) @@ -2877,7 +2874,7 @@ const ASound8::CommandPtr ASound8::_commandList[38] = { &ASound8::command36, &ASound8::command37 }; -ASound8::ASound8(Audio::Mixer *mixer) : ASound(mixer, "asound.008", 0x1490) { +ASound8::ASound8(Audio::Mixer *mixer, FM_OPL *opl) : ASound(mixer, opl, "asound.008", 0x1490) { // Load sound samples _soundFile.seek(_dataOffset + 0x122); for (int i = 0; i < 174; ++i) @@ -3133,7 +3130,7 @@ const ASound9::CommandPtr ASound9::_commandList[52] = { &ASound9::command48, &ASound9::command49, &ASound9::command50, &ASound9::command51 }; -ASound9::ASound9(Audio::Mixer *mixer) : ASound(mixer, "asound.009", 0x16F0) { +ASound9::ASound9(Audio::Mixer *mixer, FM_OPL *opl) : ASound(mixer, opl, "asound.009", 0x16F0) { _v1 = _v2 = 0; _soundPtr = nullptr; diff --git a/engines/mads/nebular/sound_nebular.h b/engines/mads/nebular/sound_nebular.h index 744467b45e..abb6516030 100644 --- a/engines/mads/nebular/sound_nebular.h +++ b/engines/mads/nebular/sound_nebular.h @@ -305,10 +305,12 @@ public: public: /** * Constructor + * @param mixer Mixer + * @param opl OPL * @param filename Specifies the adlib sound player file to use * @param dataOffset Offset in the file of the data segment */ - ASound(Audio::Mixer *mixer, const Common::String &filename, int dataOffset); + ASound(Audio::Mixer *mixer, FM_OPL *opl, const Common::String &filename, int dataOffset); /** * Destructor @@ -408,7 +410,7 @@ private: void command111213(); int command2627293032(); public: - ASound1(Audio::Mixer *mixer); + ASound1(Audio::Mixer *mixer, FM_OPL *opl); virtual int command(int commandId, int param); }; @@ -460,7 +462,7 @@ private: void command9Randomize(); void command9Apply(byte *data, int val, int incr); public: - ASound2(Audio::Mixer *mixer); + ASound2(Audio::Mixer *mixer, FM_OPL *opl); virtual int command(int commandId, int param); }; @@ -520,7 +522,7 @@ private: void command9Randomize(); void command9Apply(byte *data, int val, int incr); public: - ASound3(Audio::Mixer *mixer); + ASound3(Audio::Mixer *mixer, FM_OPL *opl); virtual int command(int commandId, int param); }; @@ -558,7 +560,7 @@ private: void method1(); public: - ASound4(Audio::Mixer *mixer); + ASound4(Audio::Mixer *mixer, FM_OPL *opl); virtual int command(int commandId, int param); }; @@ -604,7 +606,7 @@ private: int command42(); int command43(); public: - ASound5(Audio::Mixer *mixer); + ASound5(Audio::Mixer *mixer, FM_OPL *opl); virtual int command(int commandId, int param); }; @@ -633,7 +635,7 @@ private: int command25(); int command29(); public: - ASound6(Audio::Mixer *mixer); + ASound6(Audio::Mixer *mixer, FM_OPL *opl); virtual int command(int commandId, int param); }; @@ -665,7 +667,7 @@ private: int command36(); int command37(); public: - ASound7(Audio::Mixer *mixer); + ASound7(Audio::Mixer *mixer, FM_OPL *opl); virtual int command(int commandId, int param); }; @@ -708,7 +710,7 @@ private: void method1(byte *pData); void adjustRange(byte *pData, byte v, int incr); public: - ASound8(Audio::Mixer *mixer); + ASound8(Audio::Mixer *mixer, FM_OPL *opl); virtual int command(int commandId, int param); }; @@ -767,7 +769,7 @@ private: int command59(); int command60(); public: - ASound9(Audio::Mixer *mixer); + ASound9(Audio::Mixer *mixer, FM_OPL *opl); virtual int command(int commandId, int param); }; diff --git a/engines/mads/sound.cpp b/engines/mads/sound.cpp index 35d948e0b0..12109895b5 100644 --- a/engines/mads/sound.cpp +++ b/engines/mads/sound.cpp @@ -29,9 +29,10 @@ namespace MADS { -SoundManager::SoundManager(MADSEngine *vm, Audio::Mixer *mixer) { +SoundManager::SoundManager(MADSEngine *vm, Audio::Mixer *mixer, FM_OPL *opl) { _vm = vm; _mixer = mixer; + _opl = opl; _driver = nullptr; _pollSoundEnabled = false; _soundPollFlag = false; @@ -49,31 +50,31 @@ void SoundManager::init(int sectionNumber) { case GType_RexNebular: switch (sectionNumber) { case 1: - _driver = new Nebular::ASound1(_mixer); + _driver = new Nebular::ASound1(_mixer, _opl); break; case 2: - _driver = new Nebular::ASound2(_mixer); + _driver = new Nebular::ASound2(_mixer, _opl); break; case 3: - _driver = new Nebular::ASound3(_mixer); + _driver = new Nebular::ASound3(_mixer, _opl); break; case 4: - _driver = new Nebular::ASound4(_mixer); + _driver = new Nebular::ASound4(_mixer, _opl); break; case 5: - _driver = new Nebular::ASound5(_mixer); + _driver = new Nebular::ASound5(_mixer, _opl); break; case 6: - _driver = new Nebular::ASound6(_mixer); + _driver = new Nebular::ASound6(_mixer, _opl); break; case 7: - _driver = new Nebular::ASound7(_mixer); + _driver = new Nebular::ASound7(_mixer, _opl); break; case 8: - _driver = new Nebular::ASound8(_mixer); + _driver = new Nebular::ASound8(_mixer, _opl); break; case 9: - _driver = new Nebular::ASound9(_mixer); + _driver = new Nebular::ASound9(_mixer, _opl); break; default: _driver = nullptr; diff --git a/engines/mads/sound.h b/engines/mads/sound.h index 9a251f9dd0..b2af7e2346 100644 --- a/engines/mads/sound.h +++ b/engines/mads/sound.h @@ -37,13 +37,14 @@ class SoundManager { private: MADSEngine *_vm; Audio::Mixer *_mixer; + FM_OPL *_opl; Nebular::ASound *_driver; bool _pollSoundEnabled; bool _soundPollFlag; bool _newSoundsPaused; Common::Queue _queuedCommands; public: - SoundManager(MADSEngine *vm, Audio::Mixer *mixer); + SoundManager(MADSEngine *vm, Audio::Mixer *mixer, FM_OPL *opl); ~SoundManager(); /** -- cgit v1.2.3