EMI: Initialize EMISound instead of iMuse at engine startup.

This commit is contained in:
Joni Vähämäki 2014-07-18 14:37:29 +03:00
parent a8d48e2545
commit a03a06b0f6
5 changed files with 56 additions and 48 deletions

View file

@ -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");
}

View file

@ -99,6 +99,8 @@ private:
SoundTrack *createEmptyMusicTrack() const;
};
extern EMISound *g_emiSound;
}
#endif

View file

@ -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);
}
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,6 +416,7 @@ 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")) {
if (g_imuse)
g_imuse->startSfx(buf);
resource = (void *)1;
} else if (strstr(buf, ".mat")) {
@ -703,8 +710,10 @@ void GrimEngine::mainLoop() {
_changeFullscreenState = false;
}
if (g_imuse) {
g_imuse->flushTracks();
g_imuse->refreshScripts();
}
_debugger->onFrame();
@ -815,9 +824,12 @@ void GrimEngine::savegameRestore() {
_savedState = SaveGame::openForLoading(filename);
if (!_savedState || !_savedState->isCompatible())
return;
if (g_imuse) {
g_imuse->stopAllSounds();
g_imuse->resetState();
}
g_movie->stop();
if (g_imuse)
g_imuse->pause(true);
g_movie->pause(true);
if (g_registry)
@ -883,6 +895,7 @@ void GrimEngine::savegameRestore() {
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
LuaBase::instance()->postRestoreHandle();
if (g_imuse)
g_imuse->pause(false);
g_movie->pause(false);
debug("GrimEngine::savegameRestore() finished.");
@ -985,6 +998,7 @@ void GrimEngine::savegameSave() {
storeSaveGameImage(_savedState);
if (g_imuse)
g_imuse->pause(true);
g_movie->pause(true);
@ -1038,6 +1052,7 @@ void GrimEngine::savegameSave() {
delete _savedState;
if (g_imuse)
g_imuse->pause(false);
g_movie->pause(false);
debug("GrimEngine::savegameSave() finished.");
@ -1269,6 +1284,7 @@ void GrimEngine::openMainMenuDialog() {
}
void GrimEngine::pauseEngineIntern(bool pause) {
if (g_imuse)
g_imuse->pause(pause);
g_movie->pause(pause);

View file

@ -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;
}

View file

@ -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);