diff --git a/engines/grim/emi/sound/emisound.cpp b/engines/grim/emi/sound/emisound.cpp index 9776ff7781d..f85f82d1b64 100644 --- a/engines/grim/emi/sound/emisound.cpp +++ b/engines/grim/emi/sound/emisound.cpp @@ -36,15 +36,19 @@ #include "engines/grim/textsplit.h" #include "engines/grim/emi/sound/emisound.h" #include "engines/grim/emi/sound/track.h" +#include "engines/grim/emi/sound/aifftrack.h" #include "engines/grim/emi/sound/mp3track.h" #include "engines/grim/emi/sound/scxtrack.h" #include "engines/grim/emi/sound/vimatrack.h" +#include "engines/grim/movie/codecs/vima.h" #define NUM_CHANNELS 32 namespace Grim { -class SoundTrack; +EMISound *g_emiSound = nullptr; + +extern uint16 imuseDestTable[]; void EMISound::timerHandler(void *refCon) { EMISound *emiSound = (EMISound *)refCon; @@ -59,6 +63,7 @@ EMISound::EMISound(int fps) { _curMusicState = -1; _musicChannel = -1; _callbackFps = fps; + vimaInit(imuseDestTable); initMusicTable(); g_system->getTimerManager()->installTimerProc(timerHandler, 1000000 / _callbackFps, this, "emiSoundCallback"); } diff --git a/engines/grim/emi/sound/emisound.h b/engines/grim/emi/sound/emisound.h index 3ab4367b312..99c719e90f8 100644 --- a/engines/grim/emi/sound/emisound.h +++ b/engines/grim/emi/sound/emisound.h @@ -99,6 +99,8 @@ private: SoundTrack *createEmptyMusicTrack() const; }; +extern EMISound *g_emiSound; + } #endif diff --git a/engines/grim/grim.cpp b/engines/grim/grim.cpp index 16fd8165f51..b1f5cdd225b 100644 --- a/engines/grim/grim.cpp +++ b/engines/grim/grim.cpp @@ -65,6 +65,7 @@ #include "engines/grim/debugger.h" #include "engines/grim/imuse/imuse.h" +#include "engines/grim/emi/sound/emisound.h" #include "engines/grim/lua/lua.h" @@ -183,6 +184,8 @@ GrimEngine::~GrimEngine() { g_movie = nullptr; delete g_imuse; g_imuse = nullptr; + delete g_emiSound; + g_emiSound = nullptr; delete g_sound; g_sound = nullptr; delete g_localizer; @@ -282,7 +285,10 @@ Common::Error GrimEngine::run() { else g_movie = CreateBinkPlayer(demo); } - g_imuse = new Imuse(20, demo); + if (getGameType() == GType_GRIM) + g_imuse = new Imuse(20, demo); + else if (getGameType() == GType_MONKEY4) + g_emiSound = new EMISound(20); g_sound = new SoundPlayer(); bool fullscreen = ConfMan.getBool("fullscreen"); @@ -410,7 +416,8 @@ void GrimEngine::handleDebugLoadResource() { else if (strstr(buf, ".snm")) resource = (void *)g_movie->play(buf, false, 0, 0); else if (strstr(buf, ".wav") || strstr(buf, ".imu")) { - g_imuse->startSfx(buf); + if (g_imuse) + g_imuse->startSfx(buf); resource = (void *)1; } else if (strstr(buf, ".mat")) { CMap *cmap = g_resourceloader->loadColormap("item.cmp"); @@ -703,8 +710,10 @@ void GrimEngine::mainLoop() { _changeFullscreenState = false; } - g_imuse->flushTracks(); - g_imuse->refreshScripts(); + if (g_imuse) { + g_imuse->flushTracks(); + g_imuse->refreshScripts(); + } _debugger->onFrame(); @@ -815,10 +824,13 @@ void GrimEngine::savegameRestore() { _savedState = SaveGame::openForLoading(filename); if (!_savedState || !_savedState->isCompatible()) return; - g_imuse->stopAllSounds(); - g_imuse->resetState(); + if (g_imuse) { + g_imuse->stopAllSounds(); + g_imuse->resetState(); + } g_movie->stop(); - g_imuse->pause(true); + if (g_imuse) + g_imuse->pause(true); g_movie->pause(true); if (g_registry) g_registry->save(); @@ -883,7 +895,8 @@ void GrimEngine::savegameRestore() { _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume")); LuaBase::instance()->postRestoreHandle(); - g_imuse->pause(false); + if (g_imuse) + g_imuse->pause(false); g_movie->pause(false); debug("GrimEngine::savegameRestore() finished."); @@ -985,7 +998,8 @@ void GrimEngine::savegameSave() { storeSaveGameImage(_savedState); - g_imuse->pause(true); + if (g_imuse) + g_imuse->pause(true); g_movie->pause(true); savegameCallback(); @@ -1038,7 +1052,8 @@ void GrimEngine::savegameSave() { delete _savedState; - g_imuse->pause(false); + if (g_imuse) + g_imuse->pause(false); g_movie->pause(false); debug("GrimEngine::savegameSave() finished."); @@ -1269,7 +1284,8 @@ void GrimEngine::openMainMenuDialog() { } void GrimEngine::pauseEngineIntern(bool pause) { - g_imuse->pause(pause); + if (g_imuse) + g_imuse->pause(pause); g_movie->pause(pause); if (pause) { diff --git a/engines/grim/sound.cpp b/engines/grim/sound.cpp index 410be4873b9..bd04f7dcb56 100644 --- a/engines/grim/sound.cpp +++ b/engines/grim/sound.cpp @@ -29,30 +29,18 @@ namespace Grim { SoundPlayer *g_sound = nullptr; -SoundPlayer::SoundPlayer() { - // TODO: Replace this with g_emiSound when we get a full working sound-system for more than voices. - if (g_grim->getGameType() == GType_MONKEY4) - _emiSound = new EMISound(20); - else - _emiSound = nullptr; -} - -SoundPlayer::~SoundPlayer() { - delete _emiSound; -} - bool SoundPlayer::startVoice(const char *soundName, int volume, int pan) { if (g_grim->getGameType() == GType_GRIM) return g_imuse->startVoice(soundName, volume, pan); else - return _emiSound->startVoice(soundName, volume, pan); + return g_emiSound->startVoice(soundName, volume, pan); } bool SoundPlayer::getSoundStatus(const char *soundName) { if (g_grim->getGameType() == GType_GRIM) return g_imuse->getSoundStatus(soundName); else - return _emiSound->getSoundStatus(soundName); + return g_emiSound->getSoundStatus(soundName); } void SoundPlayer::stopSound(const char *soundName) { @@ -60,7 +48,7 @@ void SoundPlayer::stopSound(const char *soundName) { g_imuse->stopSound(soundName); return; } else { - _emiSound->stopSound(soundName); + g_emiSound->stopSound(soundName); } } @@ -68,14 +56,14 @@ int32 SoundPlayer::getPosIn16msTicks(const char *soundName) { if (g_grim->getGameType() == GType_GRIM) return g_imuse->getPosIn16msTicks(soundName); else - return _emiSound->getPosIn16msTicks(soundName); + return g_emiSound->getPosIn16msTicks(soundName); } void SoundPlayer::setVolume(const char *soundName, int volume) { if (g_grim->getGameType() == GType_GRIM) { g_imuse->setVolume(soundName, volume); } else { - _emiSound->setVolume(soundName, volume); + g_emiSound->setVolume(soundName, volume); } } @@ -83,7 +71,7 @@ void SoundPlayer::setPan(const char *soundName, int pan) { if (g_grim->getGameType() == GType_GRIM) { g_imuse->setPan(soundName, pan); } else { - _emiSound->setPan(soundName, pan); + g_emiSound->setPan(soundName, pan); } } @@ -91,7 +79,7 @@ void SoundPlayer::setMusicState(int stateId) { if (g_grim->getGameType() == GType_GRIM) { g_imuse->setMusicState(stateId); } else { - _emiSound->setMusicState(stateId); + g_emiSound->setMusicState(stateId); } } @@ -99,7 +87,7 @@ void SoundPlayer::restoreState(SaveGame *savedState) { if (g_grim->getGameType() == GType_GRIM) { g_imuse->restoreState(savedState); } else { - _emiSound->restoreState(savedState); + g_emiSound->restoreState(savedState); } } @@ -108,39 +96,39 @@ void SoundPlayer::saveState(SaveGame *savedState) { if (g_grim->getGameType() == GType_GRIM) { g_imuse->saveState(savedState); } else { - _emiSound->saveState(savedState); + g_emiSound->saveState(savedState); } } // EMI-only uint32 SoundPlayer::getMsPos(int stateId) { - assert(_emiSound); // This shouldn't ever be called from Grim. - return _emiSound->getMsPos(stateId); + assert(g_emiSound); // This shouldn't ever be called from Grim. + return g_emiSound->getMsPos(stateId); } void SoundPlayer::selectMusicSet(int setId) { - assert(_emiSound); - return _emiSound->selectMusicSet(setId); + assert(g_emiSound); + return g_emiSound->selectMusicSet(setId); } void SoundPlayer::pushState() { - assert(_emiSound); // This shouldn't ever be called from Grim. - return _emiSound->pushStateToStack(); + assert(g_emiSound); // This shouldn't ever be called from Grim. + return g_emiSound->pushStateToStack(); } void SoundPlayer::popState() { - assert(_emiSound); // This shouldn't ever be called from Grim. - return _emiSound->popStateFromStack(); + assert(g_emiSound); // This shouldn't ever be called from Grim. + return g_emiSound->popStateFromStack(); } void SoundPlayer::flushStack() { - assert(_emiSound); // This shouldn't ever be called from Grim. - return _emiSound->flushStack(); + assert(g_emiSound); // This shouldn't ever be called from Grim. + return g_emiSound->flushStack(); } bool SoundPlayer::stateHasLooped(int stateId) { - assert(_emiSound); // This shouldn't ever be called from Grim. + assert(g_emiSound); // This shouldn't ever be called from Grim. if (g_grim->getGameType() == GType_MONKEY4) { - return _emiSound->stateHasLooped(stateId); + return g_emiSound->stateHasLooped(stateId); } return false; } diff --git a/engines/grim/sound.h b/engines/grim/sound.h index b6f9b5afd18..7e0cb661e7e 100644 --- a/engines/grim/sound.h +++ b/engines/grim/sound.h @@ -30,10 +30,7 @@ namespace Grim { class EMISound; class SoundPlayer { - EMISound *_emiSound; public: - SoundPlayer(); - ~SoundPlayer(); bool startVoice(const char *soundName, int volume = 127, int pan = 64); bool getSoundStatus(const char *soundName); void stopSound(const char *soundName);