diff options
-rw-r--r-- | scumm/sound.cpp | 59 | ||||
-rw-r--r-- | scumm/sound.h | 1 | ||||
-rw-r--r-- | simon/sound.cpp | 28 | ||||
-rw-r--r-- | sound/audiostream.cpp | 4 | ||||
-rw-r--r-- | sound/mixer.cpp | 25 | ||||
-rw-r--r-- | sound/mixer.h | 2 |
6 files changed, 51 insertions, 68 deletions
diff --git a/scumm/sound.cpp b/scumm/sound.cpp index 8a308c3d69..d822211928 100644 --- a/scumm/sound.cpp +++ b/scumm/sound.cpp @@ -943,25 +943,24 @@ void Sound::startSfxSound(File *file, int file_size, PlayingSoundHandle *handle) int rate, comp; byte *data; - if (_scumm->_noDigitalSamples) + if (_soundsPaused || _scumm->_noDigitalSamples) return; if (file_size > 0) { int alloc_size = file_size; + if (_vorbis_mode) { + data = (byte *)calloc(alloc_size, 1); + + if (file->read(data, file_size) != (uint)file_size) { + // no need to free the memory since error will shut down + error("startSfxSound: cannot read %d bytes", size); + } + playSfxSound_Vorbis(data, file_size, handle); + } else { #ifdef USE_MAD - if (!_vorbis_mode) - alloc_size += MAD_BUFFER_GUARD; + _scumm->_mixer->playMP3(handle, file, file_size); #endif - data = (byte *)calloc(alloc_size, 1); - - if (file->read(data, file_size) != (uint)file_size) { - /* no need to free the memory since error will shut down */ - error("startSfxSound: cannot read %d bytes", size); } - if (_vorbis_mode) - playSfxSound_Vorbis(data, file_size, handle); - else - playSfxSound_MP3(data, file_size, handle); return; } @@ -1429,21 +1428,12 @@ bail: } void Sound::playSfxSound(void *sound, uint32 size, uint rate, bool isUnsigned, PlayingSoundHandle *handle) { - if (_soundsPaused) - return; byte flags = SoundMixer::FLAG_AUTOFREE; if (isUnsigned) flags |= SoundMixer::FLAG_UNSIGNED; _scumm->_mixer->playRaw(handle, sound, size, rate, flags); } -void Sound::playSfxSound_MP3(void *sound, uint32 size, PlayingSoundHandle *handle) { -#ifdef USE_MAD - if (!_soundsPaused && !_scumm->_noDigitalSamples) - _scumm->_mixer->playMP3(handle, sound, size, SoundMixer::FLAG_AUTOFREE); -#endif -} - #ifdef USE_VORBIS // Provide a virtual file to vorbisfile based on preloaded data struct data_file_info { @@ -1508,20 +1498,19 @@ static ov_callbacks data_wrap = { void Sound::playSfxSound_Vorbis(void *sound, uint32 size, PlayingSoundHandle *handle) { #ifdef USE_VORBIS - if (!_soundsPaused && !_scumm->_noDigitalSamples) { - OggVorbis_File *ov_file = new OggVorbis_File; - data_file_info *f = new data_file_info; - f->data = (char *) sound; - f->size = size; - f->curr_pos = 0; - - if (ov_open_callbacks((void *) f, ov_file, NULL, 0, data_wrap) < 0) { - warning("Invalid file format"); - delete ov_file; - delete f; - } else - _scumm->_mixer->playVorbis(handle, ov_file, 0, false); - } + OggVorbis_File *ov_file = new OggVorbis_File; + data_file_info *f = new data_file_info; + f->data = (char *) sound; + f->size = size; + f->curr_pos = 0; + + if (ov_open_callbacks((void *) f, ov_file, NULL, 0, data_wrap) < 0) { + warning("Invalid file format"); + delete ov_file; + delete f; + free(sound); + } else + _scumm->_mixer->playVorbis(handle, ov_file, 0, false); #endif } diff --git a/scumm/sound.h b/scumm/sound.h index 77e8e3e056..1bb765770c 100644 --- a/scumm/sound.h +++ b/scumm/sound.h @@ -159,7 +159,6 @@ protected: void stopSfxSound(); bool isSfxFinished() const; void playSfxSound(void *sound, uint32 size, uint rate, bool isUnsigned, PlayingSoundHandle *handle); - void playSfxSound_MP3(void *sound, uint32 size, PlayingSoundHandle *handle); void playSfxSound_Vorbis(void *sound, uint32 size, PlayingSoundHandle *handle); int getCachedTrack(int track); diff --git a/simon/sound.cpp b/simon/sound.cpp index 32b3a452bf..2aca4b955c 100644 --- a/simon/sound.cpp +++ b/simon/sound.cpp @@ -23,7 +23,6 @@ #include "common/engine.h" #define SOUND_BIG_ENDIAN true -#define FLAG_SIGNED 0 class BaseSound { protected: @@ -35,25 +34,25 @@ public: BaseSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false); BaseSound(SoundMixer *mixer, File *file, uint32 *offsets, bool bigendian = false); virtual ~BaseSound(); - virtual int playSound(uint sound, PlayingSoundHandle *handle, byte flags = SoundMixer::FLAG_UNSIGNED) = 0; + virtual int playSound(uint sound, PlayingSoundHandle *handle, byte flags) = 0; }; class WavSound : public BaseSound { public: WavSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {}; WavSound(SoundMixer *mixer, File *file, uint32 *offsets) : BaseSound(mixer, file, offsets) {}; - int playSound(uint sound, PlayingSoundHandle *handle, byte flags = SoundMixer::FLAG_UNSIGNED); + int playSound(uint sound, PlayingSoundHandle *handle, byte flags); }; class VocSound : public BaseSound { public: VocSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {}; - int playSound(uint sound, PlayingSoundHandle *handle, byte flags = SoundMixer::FLAG_UNSIGNED); + int playSound(uint sound, PlayingSoundHandle *handle, byte flags); }; class RawSound : public BaseSound { public: RawSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {}; - int playSound(uint sound, PlayingSoundHandle *handle, byte flags = SoundMixer::FLAG_UNSIGNED); + int playSound(uint sound, PlayingSoundHandle *handle, byte flags); }; @@ -234,7 +233,7 @@ int RawSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) { class MP3Sound : public BaseSound { public: MP3Sound(SoundMixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {}; - int playSound(uint sound, PlayingSoundHandle *handle, byte flags = SoundMixer::FLAG_UNSIGNED); + int playSound(uint sound, PlayingSoundHandle *handle, byte flags); }; int MP3Sound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) @@ -242,16 +241,11 @@ int MP3Sound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) if (_offsets == NULL) return 0; - flags |= SoundMixer::FLAG_AUTOFREE; - _file->seek(_offsets[sound], SEEK_SET); uint32 size = _offsets[sound+1] - _offsets[sound]; - byte *buffer = (byte *)malloc(size); - _file->read(buffer, size); - - return _mixer->playMP3(handle, buffer, size, flags); + return _mixer->playMP3(handle, _file, size); } #endif @@ -449,10 +443,7 @@ void SimonSound::playVoice(uint sound) { if (_voice_handle) _mixer->stop(_voice_index); - if (_game == GAME_SIMON1CD32) - _voice_index = _voice->playSound(sound, &_voice_handle, FLAG_SIGNED); - else - _voice_index = _voice->playSound(sound, &_voice_handle); + _voice_index = _voice->playSound(sound, &_voice_handle, (_game == GAME_SIMON1CD32) ? 0 : SoundMixer::FLAG_UNSIGNED); } void SimonSound::playEffects(uint sound) { @@ -462,10 +453,7 @@ void SimonSound::playEffects(uint sound) { if (_effects_paused) return; - if (_game == GAME_SIMON1CD32) - _effects->playSound(sound, &_effects_handle, FLAG_SIGNED); - else - _effects->playSound(sound, &_effects_handle); + _effects->playSound(sound, &_effects_handle, (_game == GAME_SIMON1CD32) ? 0 : SoundMixer::FLAG_UNSIGNED); } void SimonSound::playAmbient(uint sound) { diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 78a20d6e2a..ef96c2594b 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -166,7 +166,11 @@ class MP3InputStream : public AudioInputStream { uint32 _posInFrame; public: // TODO + MP3InputStream(); }; + +MP3InputStream::MP3InputStream() { +} #endif diff --git a/sound/mixer.cpp b/sound/mixer.cpp index 5f6b6629ba..0e43073213 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -122,7 +122,6 @@ public: class ChannelMP3Common : public Channel { protected: byte *_ptr; - bool _releasePtr; struct mad_stream _stream; struct mad_frame _frame; struct mad_synth _synth; @@ -139,7 +138,7 @@ class ChannelMP3 : public ChannelMP3Common { uint32 _position; public: - ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint size, byte flags); + ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, uint size); void mix(int16 *data, uint len); bool isMusicChannel() { return false; } @@ -283,9 +282,9 @@ int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, ui } #ifdef USE_MAD -int SoundMixer::playMP3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags) { +int SoundMixer::playMP3(PlayingSoundHandle *handle, File *file, uint32 size) { StackLock lock(_mutex); - return insertChannel(handle, new ChannelMP3(this, handle, sound, size, flags)); + return insertChannel(handle, new ChannelMP3(this, handle, file, size)); } int SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration) { StackLock lock(_mutex); @@ -924,8 +923,7 @@ ChannelMP3Common::ChannelMP3Common(SoundMixer *mixer, PlayingSoundHandle *handle } ChannelMP3Common::~ChannelMP3Common() { - if (_releasePtr) - free(_ptr); + free(_ptr); mad_synth_finish(&_synth); mad_frame_finish(&_frame); mad_stream_finish(&_stream); @@ -945,18 +943,24 @@ static inline int scale_sample(mad_fixed_t sample) { return sample >> (MAD_F_FRACBITS + 1 - 16); } -ChannelMP3::ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint size, byte flags) +ChannelMP3::ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, uint size) : ChannelMP3Common(mixer, handle) { _posInFrame = 0xFFFFFFFF; _position = 0; - _size = size; - _ptr = (byte *)sound; - _releasePtr = (flags & SoundMixer::FLAG_AUTOFREE) != 0; + _ptr = (byte *)malloc(size + MAD_BUFFER_GUARD); + + _size = file->read(_ptr, size); } void ChannelMP3::mix(int16 *data, uint len) { const int volume = _mixer->getVolume(); + // Exit if all data is used up (this also covers the case were reading from the file failed). + if (_position >= _size) { + destroy(); + return; + } + while (1) { int16 sample; @@ -1003,7 +1007,6 @@ ChannelMP3CDMusic::ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *hand _duration = duration; _bufferSize = MP3CD_BUFFERING_SIZE; _ptr = (byte *)malloc(MP3CD_BUFFERING_SIZE); - _releasePtr = true; } void ChannelMP3CDMusic::mix(int16 *data, uint len) { diff --git a/sound/mixer.h b/sound/mixer.h index 6c7e8edf97..47acf99d66 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -84,7 +84,7 @@ public: // start playing a raw sound int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id = -1); #ifdef USE_MAD - int playMP3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags); + int playMP3(PlayingSoundHandle *handle, File *file, uint32 size); int playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration); #endif #ifdef USE_VORBIS |