diff options
author | Max Horn | 2003-12-21 00:44:31 +0000 |
---|---|---|
committer | Max Horn | 2003-12-21 00:44:31 +0000 |
commit | ec0ebf5380d0f77715e40586243226676480deeb (patch) | |
tree | b124eff41a4645c2dc3c32fa78e6837ee9571cdc | |
parent | 676bf4d68326751eb3f1b487eb1d0265684c840d (diff) | |
download | scummvm-rg350-ec0ebf5380d0f77715e40586243226676480deeb.tar.gz scummvm-rg350-ec0ebf5380d0f77715e40586243226676480deeb.tar.bz2 scummvm-rg350-ec0ebf5380d0f77715e40586243226676480deeb.zip |
o Make use of the new LinearMemoryStream feature which allows auto-disposing the sound data
o This allows us to get rid of the ChannelRaw class
o Removed the sound index return value from several methods
o Removed all methods dealing with sound indices (i.e. stopChannel and pauseChannel)
svn-id: r11801
-rw-r--r-- | sound/audiocd.h | 2 | ||||
-rw-r--r-- | sound/mixer.cpp | 114 | ||||
-rw-r--r-- | sound/mixer.h | 20 | ||||
-rw-r--r-- | sound/mp3.cpp | 4 | ||||
-rw-r--r-- | sound/mp3.h | 2 | ||||
-rw-r--r-- | sound/vorbis.cpp | 4 | ||||
-rw-r--r-- | sound/vorbis.h | 2 |
7 files changed, 49 insertions, 99 deletions
diff --git a/sound/audiocd.h b/sound/audiocd.h index 346f5c1c63..012f582b0d 100644 --- a/sound/audiocd.h +++ b/sound/audiocd.h @@ -30,7 +30,7 @@ class DigitalTrackInfo { public: virtual bool error() = 0; - virtual int play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) = 0; + virtual void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) = 0; virtual ~DigitalTrackInfo() { } }; diff --git a/sound/mixer.cpp b/sound/mixer.cpp index 786c376099..a539cfc510 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -55,13 +55,13 @@ protected: public: int _id; - Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, byte volume, int8 pan) - : _mixer(mixer), _handle(handle), _isMusic(isMusic), _volume(volume), _pan(pan), _paused(false), _converter(0), _input(0), _id(-1) { + Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, byte volume, int8 pan, int id = -1) + : _mixer(mixer), _handle(handle), _isMusic(isMusic), _volume(volume), _pan(pan), _paused(false), _converter(0), _input(0), _id(id) { assert(mixer); } - Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume, int8 pan, bool reverseStereo = false) - : _mixer(mixer), _handle(handle), _isMusic(isMusic), _volume(volume), _pan(pan), _paused(false), _converter(0), _input(input), _id(-1) { + Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume, int8 pan, bool reverseStereo = false, int id = -1) + : _mixer(mixer), _handle(handle), _isMusic(isMusic), _volume(volume), _pan(pan), _paused(false), _converter(0), _input(input), _id(id) { assert(mixer); assert(input); @@ -92,13 +92,6 @@ public: } }; -class ChannelRaw : public Channel { - byte *_ptr; -public: - ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, byte volume, int8 pan, int id, uint32 loopStart, uint32 loopEnd); - ~ChannelRaw(); -}; - class ChannelStream : public Channel { public: ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, uint32 buffer_size, byte volume, int8 pan); @@ -156,9 +149,9 @@ void SoundMixer::setupPremix(PremixProc *proc, void *param) { _premixProc = proc; } -int SoundMixer::newStream(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, uint32 buffer_size, byte volume, int8 pan) { +void SoundMixer::newStream(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, uint32 buffer_size, byte volume, int8 pan) { Common::StackLock lock(_mutex); - return insertChannel(handle, new ChannelStream(this, handle, sound, size, rate, flags, buffer_size, volume, pan)); + insertChannel(handle, new ChannelStream(this, handle, sound, size, rate, flags, buffer_size, volume, pan)); } void SoundMixer::appendStream(PlayingSoundHandle handle, void *sound, uint32 size) { @@ -214,7 +207,7 @@ void SoundMixer::endStream(PlayingSoundHandle handle) { } } -int SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) { +void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) { int index = -1; for (int i = 0; i != NUM_CHANNELS; i++) { if (_channels[i] == NULL) { @@ -225,56 +218,70 @@ int SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) { if(index == -1) { warning("SoundMixer::out of mixer slots"); delete chan; - return -1; + return; } _channels[index] = chan; if (handle) *handle = index + 1; - return index; } -int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id, byte volume, int8 pan, uint32 loopStart, uint32 loopEnd) { +void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id, byte volume, int8 pan, uint32 loopStart, uint32 loopEnd) { Common::StackLock lock(_mutex); // Prevent duplicate sounds if (id != -1) { for (int i = 0; i != NUM_CHANNELS; i++) if (_channels[i] != NULL && _channels[i]->_id == id) - return -1; + return; + } + + // Create the input stream + AudioInputStream *input; + const bool autoFreeMemory = (flags & SoundMixer::FLAG_AUTOFREE) != 0; + if (flags & SoundMixer::FLAG_LOOP) { + if (loopEnd == 0) { + input = makeLinearInputStream(rate, flags, (byte *)sound, size, 0, size, autoFreeMemory); + } else { + assert(loopStart < loopEnd && loopEnd <= size); + input = makeLinearInputStream(rate, flags, (byte *)sound, size, loopStart, loopEnd - loopStart, autoFreeMemory); + } + } else { + input = makeLinearInputStream(rate, flags, (byte *)sound, size, 0, 0, autoFreeMemory); } - Channel *chan = new ChannelRaw(this, handle, sound, size, rate, flags, volume, pan, id, loopStart, loopEnd); - return insertChannel(handle, chan); + // Create the channel + Channel *chan = new Channel(this, handle, input, false, volume, pan, (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0, id); + insertChannel(handle, chan); } #ifdef USE_MAD -int SoundMixer::playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byte volume, int8 pan) { +void SoundMixer::playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byte volume, int8 pan) { // Create the input stream AudioInputStream *input = makeMP3Stream(file, mad_timer_zero, size); - return playInputStream(handle, input, false, volume, pan); + playInputStream(handle, input, false, volume, pan); } -int SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan) { +void SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan) { // Create the input stream AudioInputStream *input = makeMP3Stream(file, duration, 0); - return playInputStream(handle, input, true, volume, pan); + playInputStream(handle, input, true, volume, pan); } #endif #ifdef USE_VORBIS -int SoundMixer::playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume, int8 pan) { +void SoundMixer::playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume, int8 pan) { // Create the input stream AudioInputStream *input = makeVorbisStream(ov_file, duration); - return playInputStream(handle, input, is_cd_track, volume, pan); + playInputStream(handle, input, is_cd_track, volume, pan); } #endif -int SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume, int8 pan) { +void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume, int8 pan) { Common::StackLock lock(_mutex); // Create the channel Channel *chan = new Channel(this, handle, input, isMusic, volume, pan); - return insertChannel(handle, chan); + insertChannel(handle, chan); } void SoundMixer::mix(int16 *buf, uint len) { @@ -311,17 +318,6 @@ void SoundMixer::stopAll() { _channels[i]->destroy(); } -void SoundMixer::stopChannel(int index) { - if ((index < 0) || (index >= NUM_CHANNELS)) { - warning("soundMixer::stop has invalid index %d", index); - return; - } - - Common::StackLock lock(_mutex); - if (_channels[index]) - _channels[index]->destroy(); -} - void SoundMixer::stopID(int id) { Common::StackLock lock(_mutex); for (int i = 0; i != NUM_CHANNELS; i++) { @@ -388,17 +384,6 @@ void SoundMixer::pauseAll(bool paused) { _paused = paused; } -void SoundMixer::pauseChannel(int index, bool paused) { - if ((index < 0) || (index >= NUM_CHANNELS)) { - warning("soundMixer::pauseChannel has invalid index %d", index); - return; - } - - Common::StackLock lock(_mutex); - if (_channels[index]) - _channels[index]->pause(paused); -} - void SoundMixer::pauseID(int id, bool paused) { Common::StackLock lock(_mutex); for (int i = 0; i != NUM_CHANNELS; i++) { @@ -510,35 +495,6 @@ void Channel::mix(int16 *data, uint len) { } } -/* RAW mixer */ -ChannelRaw::ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, byte volume, int8 pan, int id, uint32 loopStart, uint32 loopEnd) - : Channel(mixer, handle, false, volume, pan) { - _id = id; - _ptr = (byte *)sound; - - // Create the input stream - if (flags & SoundMixer::FLAG_LOOP) { - if (loopEnd == 0) { - _input = makeLinearInputStream(rate, flags, _ptr, size, 0, size); - } else { - assert(loopStart < loopEnd && loopEnd <= size); - _input = makeLinearInputStream(rate, flags, _ptr, size, loopStart, loopEnd - loopStart); - } - } else { - _input = makeLinearInputStream(rate, flags, _ptr, size, 0, 0); - } - - if (!(flags & SoundMixer::FLAG_AUTOFREE)) - _ptr = 0; - - // Get a rate converter instance - _converter = makeRateConverter(_input->getRate(), mixer->getOutputRate(), _input->isStereo(), (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0); -} - -ChannelRaw::~ChannelRaw() { - free(_ptr); -} - ChannelStream::ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, uint32 buffer_size, byte volume, int8 pan) diff --git a/sound/mixer.h b/sound/mixer.h index 387883ce59..eda2df16ad 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -97,21 +97,21 @@ public: void setupPremix(PremixProc *proc, void *param); // start playing a raw sound - int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, + void playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id = -1, byte volume = 255, int8 pan = 0, uint32 loopStart = 0, uint32 loopEnd = 0); #ifdef USE_MAD - int playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byte volume = 255, int8 pan = 0); - int playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume = 255, int8 pan = 0); + void playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byte volume = 255, int8 pan = 0); + void playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume = 255, int8 pan = 0); #endif #ifdef USE_VORBIS - int playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume = 255, int8 pan = 0); + void playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume = 255, int8 pan = 0); #endif - int playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume = 255, int8 pan = 0); + void playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume = 255, int8 pan = 0); /** Start a new stream. */ - int newStream(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, uint32 buffer_size, byte volume = 255, int8 pan = 0); + void newStream(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, uint32 buffer_size, byte volume = 255, int8 pan = 0); /** Append to an existing stream. */ void appendStream(PlayingSoundHandle handle, void *sound, uint32 size); @@ -122,9 +122,6 @@ public: /** stop all currently playing sounds */ void stopAll(); - /** stop playing the given channel */ - void stopChannel(int channel); - /** stop playing the sound with given ID */ void stopID(int id); @@ -134,9 +131,6 @@ public: /** pause/unpause all channels */ void pauseAll(bool paused); - /** pause/unpause the given channel */ - void pauseChannel(int index, bool paused); - /** pause/unpause the sound with the given ID */ void pauseID(int id, bool paused); @@ -168,7 +162,7 @@ public: uint getOutputRate() const { return _outputRate; } private: - int insertChannel(PlayingSoundHandle *handle, Channel *chan); + void insertChannel(PlayingSoundHandle *handle, Channel *chan); /** main mixer method */ void mix(int16 * buf, uint len); diff --git a/sound/mp3.cpp b/sound/mp3.cpp index 96a096f3b8..dbdd44da58 100644 --- a/sound/mp3.cpp +++ b/sound/mp3.cpp @@ -97,7 +97,7 @@ error: delete file; } -int MP3TrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) { +void MP3TrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) { unsigned int offset; mad_timer_t durationTime; @@ -116,7 +116,7 @@ int MP3TrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startF } // Play it - return mixer->playMP3CDTrack(handle, _file, durationTime); + mixer->playMP3CDTrack(handle, _file, durationTime); } MP3TrackInfo::~MP3TrackInfo() { diff --git a/sound/mp3.h b/sound/mp3.h index bc19deca24..c5e93d290d 100644 --- a/sound/mp3.h +++ b/sound/mp3.h @@ -44,7 +44,7 @@ public: MP3TrackInfo(File *file); ~MP3TrackInfo(); bool error() { return _error_flag; } - int play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); + void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); }; AudioInputStream *makeMP3Stream(File *file, mad_timer_t duration, uint size = 0); diff --git a/sound/vorbis.cpp b/sound/vorbis.cpp index 5633ba4d75..b5c8e033fc 100644 --- a/sound/vorbis.cpp +++ b/sound/vorbis.cpp @@ -111,13 +111,13 @@ VorbisTrackInfo::VorbisTrackInfo(File *file) { #define VORBIS_TREMOR #endif -int VorbisTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) { +void VorbisTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) { #ifdef VORBIS_TREMOR ov_time_seek(&_ov_file, (ogg_int64_t)(startFrame / 75.0 * 1000)); #else ov_time_seek(&_ov_file, startFrame / 75.0); #endif - return mixer->playVorbis(handle, &_ov_file, + mixer->playVorbis(handle, &_ov_file, duration * ov_info(&_ov_file, -1)->rate / 75, true); } diff --git a/sound/vorbis.h b/sound/vorbis.h index 21d17f3667..93e548c8f5 100644 --- a/sound/vorbis.h +++ b/sound/vorbis.h @@ -43,7 +43,7 @@ public: VorbisTrackInfo(File *file); ~VorbisTrackInfo(); bool error() { return _error_flag; } - int play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); + void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); }; |