diff options
author | Max Horn | 2010-01-23 00:04:43 +0000 |
---|---|---|
committer | Max Horn | 2010-01-23 00:04:43 +0000 |
commit | 409e44e7c34ed901f884eeea2824fae6c5cad068 (patch) | |
tree | 6a39ca762a6f61f412e2c2fb2ee96d2ba06558e3 | |
parent | 151906f14bce8087aba45b8862b266bc2921ebb9 (diff) | |
download | scummvm-rg350-409e44e7c34ed901f884eeea2824fae6c5cad068.tar.gz scummvm-rg350-409e44e7c34ed901f884eeea2824fae6c5cad068.tar.bz2 scummvm-rg350-409e44e7c34ed901f884eeea2824fae6c5cad068.zip |
AGOS: Further unify code related to compressed sound
svn-id: r47458
-rw-r--r-- | engines/agos/sound.cpp | 125 |
1 files changed, 50 insertions, 75 deletions
diff --git a/engines/agos/sound.cpp b/engines/agos/sound.cpp index 9e8e3ba030..835851e9c2 100644 --- a/engines/agos/sound.cpp +++ b/engines/agos/sound.cpp @@ -258,6 +258,7 @@ public: }; Audio::AudioStream *VocSound::makeAudioStream(uint sound) { + assert(_offsets); _file->seek(_offsets[sound], SEEK_SET); return Audio::makeVOCStream(*_file, _flags); } @@ -303,109 +304,83 @@ void RawSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType typ /////////////////////////////////////////////////////////////////////////////// #pragma mark - -#ifdef USE_MAD -class MP3Sound : public BaseSound { +class CompressedSound : public BaseSound { public: - MP3Sound(Audio::Mixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base, false) {} - Audio::AudioStream *makeAudioStream(uint sound); - void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0); -}; + CompressedSound(Audio::Mixer *mixer, File *file, uint32 base) : BaseSound(mixer, file, base, false) {} -Audio::AudioStream *MP3Sound::makeAudioStream(uint sound) { - if (_offsets == NULL) - return NULL; + Common::MemoryReadStream *loadStream(uint sound) const { + if (_offsets == NULL) + return NULL; - _file->seek(_offsets[sound], SEEK_SET); + _file->seek(_offsets[sound], SEEK_SET); - int i = 1; - while (_offsets[sound + i] == _offsets[sound]) - i++; + int i = 1; + while (_offsets[sound + i] == _offsets[sound]) + i++; - uint32 size = _offsets[sound + i] - _offsets[sound]; + uint32 size = _offsets[sound + i] - _offsets[sound]; - Common::MemoryReadStream *tmp = _file->readStream(size); - assert(tmp); - return Audio::makeMP3Stream(tmp, DisposeAfterUse::YES); -} + return _file->readStream(size); + } -void MP3Sound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol) { - convertVolume(vol); - _mixer->playInputStream(type, handle, new LoopingAudioStream(this, sound, loopSound, loop), -1, vol); -} -#endif + void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0) { + convertVolume(vol); + _mixer->playInputStream(type, handle, new LoopingAudioStream(this, sound, loopSound, loop), -1, vol); + } +}; /////////////////////////////////////////////////////////////////////////////// #pragma mark - -#ifdef USE_VORBIS -class VorbisSound : public BaseSound { +#ifdef USE_MAD +class MP3Sound : public CompressedSound { public: - VorbisSound(Audio::Mixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base, false) {} - Audio::AudioStream *makeAudioStream(uint sound); - void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0); + MP3Sound(Audio::Mixer *mixer, File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {} + Audio::AudioStream *makeAudioStream(uint sound) { + Common::MemoryReadStream *tmp = loadStream(sound); + if (!tmp) + return NULL; + return Audio::makeMP3Stream(tmp, DisposeAfterUse::YES); + } }; +#endif -Audio::AudioStream *VorbisSound::makeAudioStream(uint sound) { - if (_offsets == NULL) - return NULL; - - _file->seek(_offsets[sound], SEEK_SET); - - int i = 1; - while (_offsets[sound + i] == _offsets[sound]) - i++; - - uint32 size = _offsets[sound + i] - _offsets[sound]; - - Common::MemoryReadStream *tmp = _file->readStream(size); - assert(tmp); - return Audio::makeVorbisStream(tmp, DisposeAfterUse::YES); -} +/////////////////////////////////////////////////////////////////////////////// +#pragma mark - -void VorbisSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol) { - convertVolume(vol); - _mixer->playInputStream(type, handle, new LoopingAudioStream(this, sound, loopSound, loop), -1, vol); -} +#ifdef USE_VORBIS +class VorbisSound : public CompressedSound { +public: + VorbisSound(Audio::Mixer *mixer, File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {} + Audio::AudioStream *makeAudioStream(uint sound) { + Common::MemoryReadStream *tmp = loadStream(sound); + if (!tmp) + return NULL; + return Audio::makeVorbisStream(tmp, DisposeAfterUse::YES); + } +}; #endif /////////////////////////////////////////////////////////////////////////////// #pragma mark - #ifdef USE_FLAC -class FlacSound : public BaseSound { +class FlacSound : public CompressedSound { public: - FlacSound(Audio::Mixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base, false) {} - Audio::AudioStream *makeAudioStream(uint sound); - void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0); + FlacSound(Audio::Mixer *mixer, File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {} + Audio::AudioStream *makeAudioStream(uint sound) { + Common::MemoryReadStream *tmp = loadStream(sound); + if (!tmp) + return NULL; + return Audio::makeFlacStream(tmp, DisposeAfterUse::YES); + } }; - -Audio::AudioStream *FlacSound::makeAudioStream(uint sound) { - if (_offsets == NULL) - return NULL; - - _file->seek(_offsets[sound], SEEK_SET); - - int i = 1; - while (_offsets[sound + i] == _offsets[sound]) - i++; - - uint32 size = _offsets[sound + i] - _offsets[sound]; - - Common::MemoryReadStream *tmp = _file->readStream(size); - assert(tmp); - return Audio::makeFlacStream(tmp, DisposeAfterUse::YES); -} - -void FlacSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol) { - convertVolume(vol); - _mixer->playInputStream(type, handle, new LoopingAudioStream(this, sound, loopSound, loop), -1, vol); -} #endif /////////////////////////////////////////////////////////////////////////////// #pragma mark - -static BaseSound *makeCompressedSound(Audio::Mixer *mixer, File *file, const Common::String &basename) { +static CompressedSound *makeCompressedSound(Audio::Mixer *mixer, File *file, const Common::String &basename) { #ifdef USE_FLAC file->open(basename + ".fla"); if (file->isOpen()) { |