added code to support the "finale" section

cleaned up playSoundEffect and playTrack

svn-id: r43149
This commit is contained in:
Norbert Lange 2009-08-08 21:59:18 +00:00
parent 319dfcbcc0
commit d77031e64c

View file

@ -67,7 +67,7 @@ void SoundAmiga::loadSoundFile(uint file) {
static const char *const tableFilenames[3][2] = { static const char *const tableFilenames[3][2] = {
{ "introscr.mx", "introinst.mx" }, { "introscr.mx", "introinst.mx" },
{ "kyramusic.mx", 0 }, { "kyramusic.mx", 0 },
{ "finalescr.mx", 0 } { "finalescr.mx", "introinst.mx" }
}; };
assert(file < ARRAYSIZE(tableFilenames)); assert(file < ARRAYSIZE(tableFilenames));
if (_fileLoaded == (FileType)file) if (_fileLoaded == (FileType)file)
@ -112,42 +112,54 @@ void SoundAmiga::playTrack(uint8 track) {
0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00
}; };
int score = -1;
bool loop = false;
byte volume = 0x40;
byte tempo = 0;
switch (_fileLoaded) { switch (_fileLoaded) {
case kFileIntro: case kFileFinal:
if (track >= 2) { // score 0 gets started immediately after loading the music-files with different tempo.
track -= 2; // we need to define a track-value for the fake call of this function
if (_driver->playSong(track)) { if (track == 10) {
_driver->setVolume(0x40); score = 0;
_driver->setTempo(tempoIntro[track] << 4); loop = true;
if (!_mixer->isSoundHandleActive(_musicHandle)) tempo = 0x78;
_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_musicHandle, _driver, -1, Audio::Mixer::kMaxChannelVolume, 0, false); break;
} }
} else if (track == 0){ // if this is not the hardcoded start of the song then
_driver->stopMusic(); // Fallthrough
} else { // track == 1 case kFileIntro:
beginFadeOut(); if (track >= 2 && track < ARRAYSIZE(tempoIntro) + 2) {
score = track - 2;
tempo = tempoIntro[score];
} }
break; break;
case kFileGame: case kFileGame:
if (track < 0x80 && track != 3) { if (track >= 11 && track < ARRAYSIZE(tempoIngame) + 11) {
if (track >= 2) { score = track - 11;
track -= 0xB; loop = loopIngame[track] != 0;
if (_driver->playSong(track, loopIngame[track] != 0)) { tempo = tempoIngame[track];
_driver->setVolume(0x40); }
break;
_driver->setTempo(tempoIngame[track] << 4); default:
return;
}
if (score >= 0) {
if (_driver->playSong(score, loop)) {
_driver->setVolume(volume);
_driver->setTempo(tempo << 4);
if (!_mixer->isSoundHandleActive(_musicHandle)) if (!_mixer->isSoundHandleActive(_musicHandle))
_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_musicHandle, _driver, -1, Audio::Mixer::kMaxChannelVolume, 0, false); _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_musicHandle, _driver, -1, Audio::Mixer::kMaxChannelVolume, 0, false);
} }
} else if (track == 0){ } else if (track == 0)
_driver->stopMusic(); _driver->stopMusic();
} else { // track == 1 else if (track == 1)
beginFadeOut(); beginFadeOut();
}
}
break;
}
} }
void SoundAmiga::haltTrack() { void SoundAmiga::haltTrack() {
@ -167,34 +179,38 @@ void SoundAmiga::beginFadeOut() {
void SoundAmiga::playSoundEffect(uint8 track) { void SoundAmiga::playSoundEffect(uint8 track) {
debug("play sfx %d", track); debug("play sfx %d", track);
const EffectEntry *entry = 0;
bool pan = false;
switch (_fileLoaded) { switch (_fileLoaded) {
case kFileIntro: { case kFileFinal:
case kFileIntro:
assert(track < ARRAYSIZE(tableEffectsIntro)); assert(track < ARRAYSIZE(tableEffectsIntro));
const EffectEntry &entry = tableEffectsIntro[track]; entry = &tableEffectsIntro[track];
bool success = _driver->playNote(entry.note, entry.patch, entry.duration, entry.volume, entry.pan != 0) >= 0; pan = (entry->pan != 0);
if (!_mixer->isSoundHandleActive(_musicHandle))
_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_musicHandle, _driver, -1, Audio::Mixer::kMaxChannelVolume, 0, false);
}
break; break;
case kFileGame:
case kFileGame: { // 0x61 <= track && track <= 0x63 && variable(0x1BFE2) which might indicate song playing in game and finale
uint16 extVar = 1; // maybe indicates music playing or enabled if (0x61 <= track && track <= 0x63)
uint16 extVar2 = 1; // sound loaded ?
if (0x61 <= track && track <= 0x63 && extVar)
playTrack(track - 0x4F); playTrack(track - 0x4F);
assert(track < ARRAYSIZE(tableEffectsGame)); assert(track < ARRAYSIZE(tableEffectsGame));
const EffectEntry &entry = tableEffectsGame[track]; // variable(0x1BFE2) && tableEffectsGame[track].note, which gets set for ingame and unset for finale
if (extVar2 && entry.note) { // (and some function reverses its state)
byte pan = (entry.pan == 2) ? 0 : entry.pan; if (tableEffectsGame[track].note) {
_driver->playNote(entry.note, entry.patch, entry.duration, entry.volume, pan != 0); entry = &tableEffectsGame[track];
if (!_mixer->isSoundHandleActive(_musicHandle)) pan = (entry->pan != 0) && (entry->pan != 2);
_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_musicHandle, _driver, -1, Audio::Mixer::kMaxChannelVolume, 0, false);
}
} }
break; break;
default:
;
}
if (entry) {
const bool success = _driver->playNote(entry->note, entry->patch, entry->duration, entry->volume, pan);
if (success && !_mixer->isSoundHandleActive(_musicHandle))
_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_musicHandle, _driver, -1, Audio::Mixer::kMaxChannelVolume, 0, false);
} }
} }