diff options
author | Filippos Karapetis | 2009-11-04 11:22:46 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-11-04 11:22:46 +0000 |
commit | 7d00c4a7f1932e21e69c0f032f82a72e5c089a47 (patch) | |
tree | f69d91c0e8bfc5d92d672a38ad3cc199fae38171 /engines/sci/sfx | |
parent | 2dbf6662fce6e1c0b72bf860d1573aa05fadf850 (diff) | |
download | scummvm-rg350-7d00c4a7f1932e21e69c0f032f82a72e5c089a47.tar.gz scummvm-rg350-7d00c4a7f1932e21e69c0f032f82a72e5c089a47.tar.bz2 scummvm-rg350-7d00c4a7f1932e21e69c0f032f82a72e5c089a47.zip |
Moved the audio CD handling code inside the AudioPlayer class. Some cleanup
svn-id: r45656
Diffstat (limited to 'engines/sci/sfx')
-rw-r--r-- | engines/sci/sfx/audio.cpp | 85 | ||||
-rw-r--r-- | engines/sci/sfx/audio.h | 18 |
2 files changed, 95 insertions, 8 deletions
diff --git a/engines/sci/sfx/audio.cpp b/engines/sci/sfx/audio.cpp index f68ee37c18..b550aabafb 100644 --- a/engines/sci/sfx/audio.cpp +++ b/engines/sci/sfx/audio.cpp @@ -31,17 +31,26 @@ #include "common/system.h" #include "sound/audiostream.h" +#include "sound/audiocd.h" #include "sound/mixer.h" namespace Sci { AudioPlayer::AudioPlayer(ResourceManager *resMan) : _resMan(resMan), _audioRate(11025), - _syncResource(NULL), _syncOffset(0) { + _syncResource(NULL), _syncOffset(0), _audioCdStart(0) { + + _mixer = g_system->getMixer(); } AudioPlayer::~AudioPlayer() { + stopAllAudio(); +} + +void AudioPlayer::stopAllAudio() { stopSoundSync(); stopAudio(); + if (_audioCdStart > 0) + audioCdStop(); } int AudioPlayer::startAudio(uint16 module, uint32 number) { @@ -49,16 +58,28 @@ int AudioPlayer::startAudio(uint16 module, uint32 number) { Audio::AudioStream *audioStream = getAudioStream(number, module, &sampleLen); if (audioStream) { - g_system->getMixer()->playInputStream(Audio::Mixer::kSpeechSoundType, &_audioHandle, audioStream); + _mixer->playInputStream(Audio::Mixer::kSpeechSoundType, &_audioHandle, audioStream); return sampleLen; } return 0; } +void AudioPlayer::stopAudio() { + _mixer->stopHandle(_audioHandle); +} + +void AudioPlayer::pauseAudio() { + _mixer->pauseHandle(_audioHandle, true); +} + +void AudioPlayer::resumeAudio() { + _mixer->pauseHandle(_audioHandle, false); +} + int AudioPlayer::getAudioPosition() { - if (g_system->getMixer()->isSoundHandleActive(_audioHandle)) - return g_system->getMixer()->getSoundElapsedTime(_audioHandle) * 6 / 100; // return elapsed time in ticks + if (_mixer->isSoundHandleActive(_audioHandle)) + return _mixer->getSoundElapsedTime(_audioHandle) * 6 / 100; // return elapsed time in ticks else return -1; // Sound finished } @@ -261,4 +282,60 @@ void AudioPlayer::stopSoundSync() { } } +int AudioPlayer::audioCdPlay(int track, int start, int duration) { + if (getSciVersion() == SCI_VERSION_1_1) { + // King's Quest VI CD Audio format + _audioCdStart = g_system->getMillis(); + AudioCD.play(track, 1, start, duration); + return 1; + } else { + // Jones in the Fast Lane CD Audio format + uint32 length = 0; + + audioCdStop(); + + Common::File audioMap; + if(!audioMap.open("cdaudio.map")) + error("Could not open cdaudio.map"); + + while (audioMap.pos() < audioMap.size()) { + uint16 res = audioMap.readUint16LE(); + uint32 startFrame = audioMap.readUint16LE(); + startFrame += audioMap.readByte() << 16; + audioMap.readByte(); // Unknown, always 0x20 + length = audioMap.readUint16LE(); + length += audioMap.readByte() << 16; + audioMap.readByte(); // Unknown, always 0x00 + + if (res == track) { + AudioCD.play(1, 1, startFrame, length); + _audioCdStart = g_system->getMillis(); + break; + } + } + + audioMap.close(); + + return length * 60 / 75; // return sample length in ticks + } +} + +void AudioPlayer::audioCdStop() { + _audioCdStart = 0; + AudioCD.stop(); +} + +void AudioPlayer::audioCdUpdate() { + AudioCD.updateCD(); +} + +int AudioPlayer::audioCdPosition() { + // Return -1 if the sample is done playing. Converting to frames to compare. + if (((g_system->getMillis() - _audioCdStart) * 75 / 1000) >= (uint32)AudioCD.getStatus().duration) + return -1; + + // Return the position otherwise (in ticks). + return (g_system->getMillis() - _audioCdStart) * 60 / 1000; +} + } // End of namespace Sci diff --git a/engines/sci/sfx/audio.h b/engines/sci/sfx/audio.h index 043189a922..a767315cd3 100644 --- a/engines/sci/sfx/audio.h +++ b/engines/sci/sfx/audio.h @@ -41,21 +41,31 @@ public: Audio::SoundHandle* getAudioHandle() { return &_audioHandle; } int getAudioPosition(); int startAudio(uint16 module, uint32 tuple); - void stopAudio() { g_system->getMixer()->stopHandle(_audioHandle); } - void pauseAudio() { g_system->getMixer()->pauseHandle(_audioHandle, true); } - void resumeAudio() { g_system->getMixer()->pauseHandle(_audioHandle, false); } + void stopAudio(); + void pauseAudio(); + void resumeAudio(); void setSoundSync(ResourceId id, reg_t syncObjAddr, SegManager *segMan); void doSoundSync(reg_t syncObjAddr, SegManager *segMan); void stopSoundSync(); + int audioCdPlay(int track, int start, int duration); + void audioCdStop(); + void audioCdUpdate(); + int audioCdPosition(); + + void stopAllAudio(); + private: ResourceManager *_resMan; uint16 _audioRate; Audio::SoundHandle _audioHandle; - Audio::AudioStream* getAudioStream(uint32 number, uint32 volume, int *sampleLen); + Audio::Mixer* _mixer; Resource *_syncResource; /**< Used by kDoSync for speech syncing in CD talkie games */ uint _syncOffset; + uint32 _audioCdStart; + + Audio::AudioStream* getAudioStream(uint32 number, uint32 volume, int *sampleLen); }; } // End of namespace Sci |