Skip to content

Commit

Permalink
JADE: Play the main menu music from the XACT WaveBank
Browse files Browse the repository at this point in the history
This makes the music play in the Xbox version as well. Previously, we
played the WAV file from the launcher, which doesn't exist in the Xbox
version.

We're still hard-coding the index to the main menu music, though.
  • Loading branch information
DrMcCoy committed Aug 19, 2018
1 parent 3079b21 commit a92e598
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/engines/jade/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "src/events/events.h"

#include "src/sound/sound.h"
#include "src/sound/audiostream.h"
#include "src/sound/xactwavebank.h"

#include "src/engines/aurora/util.h"

Expand Down Expand Up @@ -63,6 +65,12 @@ Module &Game::getModule() {
}

void Game::run() {
try {
_musicBank.reset(Sound::XACTWaveBank::load("musicbank"));
} catch (...) {
Common::exceptionDispatcherWarning();
}

_module.reset(new Module(*_console));

while (!EventMan.quitRequested()) {
Expand Down Expand Up @@ -104,7 +112,27 @@ void Game::runModule() {

void Game::playMenuMusic() {
stopMenuMusic();
_menuMusic = playSound("background", Sound::kSoundTypeMusic, true);

if (_musicBank) {
/* TODO: music.2da contains an entry for "mus_thm_MAINTHEME1", but this
* gives us a state number. We will probably need to throw that state
* number at the XACT SoundBank (xsb) somehow.
*
* Until that works, we'll get the main menu music by its index in the
* XACT WaveBank (xwb) instead.
*/
static const size_t mainMenuMusic = 46;

try {
Sound::AudioStream *stream = Sound::makeLoopingAudioStream(_musicBank->getWave(mainMenuMusic), 0);

_menuMusic = SoundMan.playAudioStream(stream, Sound::kSoundTypeMusic);
SoundMan.startChannel(_menuMusic);

} catch (...) {
Common::exceptionDispatcherWarning();
}
}
}

void Game::stopMenuMusic() {
Expand Down
5 changes: 5 additions & 0 deletions src/engines/jade/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

#include "src/aurora/nwscript/variablecontainer.h"

namespace Sound {
class XACTWaveBank;
}

namespace Engines {

class Console;
Expand Down Expand Up @@ -70,6 +74,7 @@ class Game : public Aurora::NWScript::VariableContainer {

::Engines::Console *_console;

Common::ScopedPtr<Sound::XACTWaveBank> _musicBank;
Sound::ChannelHandle _menuMusic;

void playMenuMusic();
Expand Down

0 comments on commit a92e598

Please sign in to comment.