From a0cff37f0697cd0082ca5fabac38159b265f4471 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 20 Sep 2005 18:04:26 +0000 Subject: [PATCH] Buggy support for ripped tracks. svn-id: r18849 --- saga/music.cpp | 34 ++++++++++++++++++++++++++++++++++ saga/music.h | 3 +++ 2 files changed, 37 insertions(+) diff --git a/saga/music.cpp b/saga/music.cpp index 2bc49f0ba04..bf994445711 100644 --- a/saga/music.cpp +++ b/saga/music.cpp @@ -28,6 +28,9 @@ #include "sound/audiostream.h" #include "sound/mididrv.h" #include "sound/midiparser.h" +#include "sound/mp3.h" +#include "sound/vorbis.h" +#include "sound/flac.h" #include "common/config-manager.h" #include "common/file.h" @@ -35,6 +38,24 @@ namespace Saga { #define BUFFER_SIZE 4096 +struct TrackFormat { + DigitalTrackInfo* (*openTrackFunction)(int); +}; + +static const TrackFormat TRACK_FORMATS[] = { +#ifdef USE_FLAC + { getFlacTrack }, +#endif +#ifdef USE_VORBIS + { getVorbisTrack }, +#endif +#ifdef USE_MAD + { getMP3Track }, +#endif + + { NULL } // Terminator +}; + // I haven't decided yet if it's a good idea to make looping part of the audio // stream class, or if I should use a "wrapper" class, like I did for Broken // Sword 2, to make it easier to add support for compressed music... but I'll @@ -277,6 +298,8 @@ Music::Music(SagaEngine *vm, Audio::Mixer *mixer, MidiDriver *driver, int enable _songTableLen = 0; _songTable = 0; + + _track = NULL; } Music::~Music() { @@ -345,6 +368,7 @@ void Music::play(uint32 resourceId, MusicFlags flags) { ResourceContext *context; byte *resourceData; size_t resourceSize; + debug(2, "Music::play %d, %d", resourceId, flags); if (!_enabled) { @@ -359,6 +383,16 @@ void Music::play(uint32 resourceId, MusicFlags flags) { _player->stopMusic(); _mixer->stopHandle(_musicHandle); + // Try to open standalone digital track + for (int i = 0; i < ARRAYSIZE(TRACK_FORMATS) - 1; ++i) + if (_track = TRACK_FORMATS[i].openTrackFunction(resourceId - 8)) { + break; + } + if (_track) { + _track->play(_mixer, &_musicHandle, (MUSIC_LOOP ? -1 : 1), 10000); + return; + } + if (_vm->getGameType() == GType_ITE) { if (resourceId >= 9 && resourceId <= 34) { if (flags == MUSIC_DEFAULT) { diff --git a/saga/music.h b/saga/music.h index 05f8b491744..51f308f8977 100644 --- a/saga/music.h +++ b/saga/music.h @@ -26,6 +26,7 @@ #ifndef SAGA_MUSIC_H_ #define SAGA_MUSIC_H_ +#include "sound/audiocd.h" #include "sound/mixer.h" #include "sound/mididrv.h" #include "sound/midiparser.h" @@ -136,6 +137,8 @@ private: MidiParser *xmidiParser; MidiParser *smfParser; + DigitalTrackInfo *_track; + static void musicVolumeGaugeCallback(void *refCon); void musicVolumeGauge(void); };