Skip to content

Commit

Permalink
MADS: Fix OPL init error when showing credits multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Sep 6, 2014
1 parent 2942f93 commit efcf87a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 37 deletions.
8 changes: 7 additions & 1 deletion engines/mads/mads.cpp
Expand Up @@ -55,6 +55,7 @@ MADSEngine::MADSEngine(OSystem *syst, const MADSGameDescription *gameDesc) :
_resources = nullptr;
_sound = nullptr;
_audio = nullptr;
_opl = nullptr;
}

MADSEngine::~MADSEngine() {
Expand All @@ -68,6 +69,8 @@ MADSEngine::~MADSEngine() {
delete _resources;
delete _sound;
delete _audio;

delete _opl;
}

void MADSEngine::initialize() {
Expand All @@ -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);
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions engines/mads/mads.h
Expand Up @@ -99,6 +99,7 @@ class MADSEngine : public Engine {
ScreenSurface _screen;
SoundManager *_sound;
AudioPlayer *_audio;
FM_OPL *_opl;
bool _easyMouse;
bool _invObjectsAnimated;
bool _textWindowStill;
Expand Down
27 changes: 12 additions & 15 deletions engines/mads/nebular/sound_nebular.cpp
Expand Up @@ -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());
Expand Down Expand Up @@ -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,
Expand All @@ -217,8 +216,6 @@ ASound::~ASound() {
delete[] (*i)._data;

_mixer->stopHandle(_soundHandle);
_opl->reset();
delete _opl;
}

void ASound::adlibInit() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down
22 changes: 12 additions & 10 deletions engines/mads/nebular/sound_nebular.h
Expand Up @@ -305,10 +305,12 @@ class ASound : public Audio::AudioStream {
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
Expand Down Expand Up @@ -408,7 +410,7 @@ class ASound1 : public ASound {
void command111213();
int command2627293032();
public:
ASound1(Audio::Mixer *mixer);
ASound1(Audio::Mixer *mixer, FM_OPL *opl);

virtual int command(int commandId, int param);
};
Expand Down Expand Up @@ -460,7 +462,7 @@ class ASound2 : public ASound {
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);
};
Expand Down Expand Up @@ -520,7 +522,7 @@ class ASound3 : public ASound {
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);
};
Expand Down Expand Up @@ -558,7 +560,7 @@ class ASound4 : public ASound {

void method1();
public:
ASound4(Audio::Mixer *mixer);
ASound4(Audio::Mixer *mixer, FM_OPL *opl);

virtual int command(int commandId, int param);
};
Expand Down Expand Up @@ -604,7 +606,7 @@ class ASound5 : public ASound {
int command42();
int command43();
public:
ASound5(Audio::Mixer *mixer);
ASound5(Audio::Mixer *mixer, FM_OPL *opl);

virtual int command(int commandId, int param);
};
Expand Down Expand Up @@ -633,7 +635,7 @@ class ASound6 : public ASound {
int command25();
int command29();
public:
ASound6(Audio::Mixer *mixer);
ASound6(Audio::Mixer *mixer, FM_OPL *opl);

virtual int command(int commandId, int param);
};
Expand Down Expand Up @@ -665,7 +667,7 @@ class ASound7 : public ASound {
int command36();
int command37();
public:
ASound7(Audio::Mixer *mixer);
ASound7(Audio::Mixer *mixer, FM_OPL *opl);

virtual int command(int commandId, int param);
};
Expand Down Expand Up @@ -708,7 +710,7 @@ class ASound8 : public ASound {
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);
};
Expand Down Expand Up @@ -767,7 +769,7 @@ class ASound9 : public ASound {
int command59();
int command60();
public:
ASound9(Audio::Mixer *mixer);
ASound9(Audio::Mixer *mixer, FM_OPL *opl);

virtual int command(int commandId, int param);
};
Expand Down
21 changes: 11 additions & 10 deletions engines/mads/sound.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion engines/mads/sound.h
Expand Up @@ -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<int> _queuedCommands;
public:
SoundManager(MADSEngine *vm, Audio::Mixer *mixer);
SoundManager(MADSEngine *vm, Audio::Mixer *mixer, FM_OPL *opl);
~SoundManager();

/**
Expand Down

0 comments on commit efcf87a

Please sign in to comment.