diff options
-rw-r--r-- | scumm/sound.cpp | 6 | ||||
-rw-r--r-- | sound/audiocd.cpp | 33 | ||||
-rw-r--r-- | sound/audiocd.h | 31 |
3 files changed, 42 insertions, 28 deletions
diff --git a/scumm/sound.cpp b/scumm/sound.cpp index 80857d1bf6..79c5f06013 100644 --- a/scumm/sound.cpp +++ b/scumm/sound.cpp @@ -1364,7 +1364,7 @@ void Sound::playCDTrack(int track, int numLoops, int startFrame, int duration) { // Play it if (!_soundsPaused) - AudioCD.playCDTrack(track, numLoops, startFrame, duration); + AudioCD.play(track, numLoops, startFrame, duration); // Start the timer after starting the track. Starting an MP3 track is // almost instantaneous, but a CD player may take some time. Hopefully @@ -1373,11 +1373,11 @@ void Sound::playCDTrack(int track, int numLoops, int startFrame, int duration) { } void Sound::stopCD() { - AudioCD.stopCD(); + AudioCD.stop(); } int Sound::pollCD() const { - return AudioCD.pollCD(); + return AudioCD.isPlaying(); } void Sound::updateCD() { diff --git a/sound/audiocd.cpp b/sound/audiocd.cpp index 6da8cf28aa..718ed10214 100644 --- a/sound/audiocd.cpp +++ b/sound/audiocd.cpp @@ -33,19 +33,21 @@ AudioCDManager::AudioCDManager() { _current_cache = 0; } -void AudioCDManager::playCDTrack(int track, int numLoops, int startFrame, int duration) { +void AudioCDManager::play(int track, int numLoops, int startFrame, int duration) { if (numLoops != 0 || startFrame != 0) { // Try to load the track from a .mp3/.ogg file, and if found, use // that. If not found, attempt to do regular Audio CD playback of // the requested track. int index = getCachedTrack(track); + + _cd.track = track; + _cd.numLoops = numLoops; + _cd.start = startFrame; + _cd.duration = duration; + if (index >= 0) { g_engine->_mixer->stopHandle(_cd.handle); _cd.playing = true; - _cd.track = track; - _cd.numLoops = numLoops; - _cd.start = startFrame; - _cd.duration = duration; _track_info[index]->play(g_engine->_mixer, &_cd.handle, _cd.start, _cd.duration); } else { g_system->play_cdrom(track, numLoops, startFrame, duration); @@ -53,7 +55,7 @@ void AudioCDManager::playCDTrack(int track, int numLoops, int startFrame, int du } } -void AudioCDManager::stopCD() { +void AudioCDManager::stop() { if (_cd.playing) { g_engine->_mixer->stopHandle(_cd.handle); _cd.playing = false; @@ -62,7 +64,7 @@ void AudioCDManager::stopCD() { } } -int AudioCDManager::pollCD() const { +int AudioCDManager::isPlaying() const { return _cd.playing || g_system->poll_cdrom(); } @@ -74,12 +76,9 @@ void AudioCDManager::updateCD() { // to be repeated, and if that's the case, play it again. Else, stop // the CD explicitly. if (_cd.numLoops == -1 || --_cd.numLoops > 0) { -//FIXME _scumm->VAR(_scumm->VAR_MUSIC_TIMER) = 0; -//FIXME if (!_soundsPaused) { - int index = getCachedTrack(_cd.track); - assert(index >= 0); - _track_info[index]->play(g_engine->_mixer, &_cd.handle, _cd.start, _cd.duration); -//FIXME } + int index = getCachedTrack(_cd.track); + assert(index >= 0); + _track_info[index]->play(g_engine->_mixer, &_cd.handle, _cd.start, _cd.duration); } else { g_engine->_mixer->stopHandle(_cd.handle); _cd.playing = false; @@ -90,6 +89,14 @@ void AudioCDManager::updateCD() { } } +AudioCDManager::Status AudioCDManager::getStatus() const { + // TODO: This could be improved for "real" CD playback. + // But to do that, we have to extend the OSystem interface. + Status info = _cd; + info.playing = isPlaying(); + return info; +} + int AudioCDManager::getCachedTrack(int track) { int i; #if defined(USE_MAD) || defined(USE_VORBIS) diff --git a/sound/audiocd.h b/sound/audiocd.h index c02e50f4f6..4065f9f030 100644 --- a/sound/audiocd.h +++ b/sound/audiocd.h @@ -37,11 +37,22 @@ public: class AudioCDManager : public Common::Singleton<AudioCDManager> { public: - void playCDTrack(int track, int numLoops, int startFrame, int duration); - void stopCD(); - int pollCD() const; + struct Status { + bool playing; + int track; + int start; + int duration; + int numLoops; + }; + + void play(int track, int numLoops, int startFrame, int duration); + void stop(); + int isPlaying() const; + void updateCD(); + Status getStatus() const; + private: friend class Common::Singleton<AudioCDManager>; AudioCDManager(); @@ -50,6 +61,11 @@ private: private: /* used for emulated CD music */ + struct ExtStatus : Status { + PlayingSoundHandle handle; + }; + ExtStatus _cd; + enum { CACHE_TRACKS = 10 }; @@ -57,15 +73,6 @@ private: DigitalTrackInfo *_track_info[CACHE_TRACKS]; int _current_cache; - struct { - PlayingSoundHandle handle; - int track; - int start; - int duration; - int numLoops; - bool playing; - } _cd; - }; /** Shortcut for accessing the audio CD manager. */ |