Permalink
Browse files

add MIDI playback

  • Loading branch information...
1 parent b24dff8 commit 3566659fc6f558c40b213cf5cb533107c03e151c @cyxx committed Jun 24, 2015
Showing with 37 additions and 30 deletions.
  1. +21 −15 game.cpp
  2. +10 −10 mixer.cpp
  3. +2 −2 mixer.h
  4. +4 −3 win16.cpp
View
@@ -927,40 +927,46 @@ void Game::playMusic(const char *name) {
int digitalTrack;
} _midiMapping[] = {
// retail game version
- { "..\\midi\\flyaway.mid", 2 },
- { "..\\midi\\jungle1.mid", 3 },
- { "..\\midi\\sadialog.mid", 4 },
- { "..\\midi\\caves.mid", 5 },
- { "..\\midi\\jungle2.mid", 6 },
- { "..\\midi\\darkcave.mid", 7 },
- { "..\\midi\\waterdiv.mid", 8 },
- { "..\\midi\\merian1.mid", 9 },
- { "..\\midi\\telquad.mid", 10 },
- { "..\\midi\\gameover.mid", 11 },
- { "..\\midi\\complete.mid", 12 },
+ { "flyaway.mid", 2 },
+ { "jungle1.mid", 3 },
+ { "sadialog.mid", 4 },
+ { "caves.mid", 5 },
+ { "jungle2.mid", 6 },
+ { "darkcave.mid", 7 },
+ { "waterdiv.mid", 8 },
+ { "merian1.mid", 9 },
+ { "telquad.mid", 10 },
+ { "gameover.mid", 11 },
+ { "complete.mid", 12 },
// demo game version
- { "..\\midi\\musik.mid", 3 }
+ { "musik.mid", 3 }
};
assert(_musicTrack == 0);
- if (name[0] == 0) {
+ if (name[0] == 0 || strncmp(name, "..\\midi\\", 8) != 0) {
return;
}
debug(DBG_GAME, "Game::playMusic('%s')", name);
stopMusic();
for (unsigned int i = 0; i < ARRAYSIZE(_midiMapping); ++i) {
- if (strcasecmp(_midiMapping[i].fileName, name) == 0) {
+ if (strcasecmp(_midiMapping[i].fileName, name + 8) == 0) {
char filePath[512];
snprintf(filePath, sizeof(filePath), "%s/track%02d.ogg", _musicPath, _midiMapping[i].digitalTrack);
debug(DBG_GAME, "playMusic('%s') track %s", name, filePath);
File *f = new File;
if (f->open(filePath)) {
- _mixer->playSoundVorbis(f, &_mixerMusicId);
+ _mixer->playMusic(f, &_mixerMusicId);
} else {
delete f;
}
return;
}
}
+ File *f = _fs.openFile(name, false);
+ if (f) {
+ _mixer->playMusic(f, &_mixerMusicId);
+ _fs.closeFile(f);
+ return;
+ }
warning("Unable to find mapping for midi music '%s'", name);
}
View
@@ -261,14 +261,14 @@ void Mixer::startSound(File *f, int *id, MixerChannel *mc) {
delete mc;
}
-void Mixer::playSoundWav(File *f, int *id) {
- debug(DBG_MIXER, "Mixer::playSoundWav()");
+void Mixer::playSound(File *f, int *id) {
+ debug(DBG_MIXER, "Mixer::playSound()");
LockAudioStack las(_stub);
startSound(f, id, new MixerChannel_Wav);
}
-void Mixer::playSoundVorbis(File *f, int *id) {
- debug(DBG_MIXER, "Mixer::playSoundVorbis()");
+void Mixer::playMusic(File *f, int *id) {
+ debug(DBG_MIXER, "Mixer::playMusic()");
#ifdef BERMUDA_VORBIS
LockAudioStack las(_stub);
startSound(f, id, new MixerChannel_Vorbis);
@@ -397,8 +397,8 @@ struct MixerImpl {
Mix_Quit();
}
- virtual void playSoundWav(const char *path, int *id) {
- debug(DBG_MIXER, "MixerImpl::playSoundWav()");
+ virtual void playSound(const char *path, int *id) {
+ debug(DBG_MIXER, "MixerImpl::playSound() path '%s'", path);
Mix_Chunk *chunk = Mix_LoadWAV(path);
if (chunk) {
*id = Mix_PlayChannel(-1, chunk, 0);
@@ -407,7 +407,7 @@ struct MixerImpl {
}
}
virtual void playSoundMusic(const char *path, int *id) {
- debug(DBG_MIXER, "MixerImpl::playSoundMusic()");
+ debug(DBG_MIXER, "MixerImpl::playSoundMusic() path '%s'", path);
playMusic(path);
*id = -1;
}
@@ -462,11 +462,11 @@ void Mixer::close() {
_impl->close();
}
-void Mixer::playSoundWav(File *f, int *id) {
- _impl->playSoundWav(f->_path, id);
+void Mixer::playSound(File *f, int *id) {
+ _impl->playSound(f->_path, id);
}
-void Mixer::playSoundVorbis(File *f, int *id) {
+void Mixer::playMusic(File *f, int *id) {
_impl->playSoundMusic(f->_path, id);
}
View
@@ -32,8 +32,8 @@ struct Mixer {
void close();
void startSound(File *f, int *id, MixerChannel *mc);
- void playSoundWav(File *f, int *id);
- void playSoundVorbis(File *f, int *id);
+ void playSound(File *f, int *id);
+ void playMusic(File *f, int *id);
bool isSoundPlaying(int id);
void stopSound(int id);
void stopAll();
View
@@ -18,9 +18,10 @@ int Game::win16_sndPlaySound(int op, void *data) {
break;
case 3: {
const char *fileName = (const char *)data;
- if (_fs.existFile(fileName)) {
- FileHolder fp(_fs, fileName);
- _mixer->playSoundWav(fp.operator->(), &_mixerSoundId);
+ File *f = _fs.openFile(fileName, false);
+ if (f) {
+ _mixer->playSound(f, &_mixerSoundId);
+ _fs.closeFile(f);
} else {
warning("Unable to open wav file '%s'", fileName);
}

0 comments on commit 3566659

Please sign in to comment.