diff options
author | Max Horn | 2003-12-26 02:19:31 +0000 |
---|---|---|
committer | Max Horn | 2003-12-26 02:19:31 +0000 |
commit | 2755d9c00af078e610160c6a976b331170970a80 (patch) | |
tree | 67001fb27dfe5e6708951f020b6e630423e0b4cd /sound | |
parent | 91f5f1687cc40f1385c62655973c3dd65266e250 (diff) | |
download | scummvm-rg350-2755d9c00af078e610160c6a976b331170970a80.tar.gz scummvm-rg350-2755d9c00af078e610160c6a976b331170970a80.tar.bz2 scummvm-rg350-2755d9c00af078e610160c6a976b331170970a80.zip |
add param to playInputStream which makes it possible to retain an input stream even after it has been given to the mixer for playback
svn-id: r11933
Diffstat (limited to 'sound')
-rw-r--r-- | sound/mixer.cpp | 27 | ||||
-rw-r--r-- | sound/mixer.h | 2 |
2 files changed, 18 insertions, 11 deletions
diff --git a/sound/mixer.cpp b/sound/mixer.cpp index 815aa9d347..28b7183665 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -43,6 +43,7 @@ class Channel { private: SoundMixer *_mixer; PlayingSoundHandle *_handle; + bool _autofreeStream; const bool _isMusic; byte _volume; int8 _pan; @@ -56,7 +57,7 @@ protected: public: Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, byte volume, int8 pan, int id = -1); - Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume, int8 pan, bool reverseStereo = false, int id = -1); + Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioInputStream *input, bool autofreeStream, bool isMusic, byte volume, int8 pan, bool reverseStereo = false, int id = -1); virtual ~Channel(); void mix(int16 *data, uint len); @@ -243,7 +244,7 @@ void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, u } // Create the channel - Channel *chan = new Channel(this, handle, input, false, volume, pan, (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0, id); + Channel *chan = new Channel(this, handle, input, true, false, volume, pan, (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0, id); insertChannel(handle, chan); } @@ -273,7 +274,7 @@ void SoundMixer::playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, } #endif -void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume, int8 pan, int id) { +void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume, int8 pan, int id, bool autofreeStream) { Common::StackLock lock(_mutex); if (input == 0) { @@ -285,13 +286,14 @@ void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioInputStream *i if (id != -1) { for (int i = 0; i != NUM_CHANNELS; i++) if (_channels[i] != 0 && _channels[i]->getId() == id) { - delete input; + if (autofreeStream) + delete input; return; } } // Create the channel - Channel *chan = new Channel(this, handle, input, isMusic, volume, pan, false, id); + Channel *chan = new Channel(this, handle, input, autofreeStream, isMusic, volume, pan, false, id); insertChannel(handle, chan); } @@ -470,13 +472,17 @@ void SoundMixer::setMusicVolume(int volume) { #pragma mark - -Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, byte volume, int8 pan, int id) - : _mixer(mixer), _handle(handle), _isMusic(isMusic), _volume(volume), _pan(pan), _paused(false), _id(id), _converter(0), _input(0) { +Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, bool isMusic, + byte volume, int8 pan, int id) + : _mixer(mixer), _handle(handle), _autofreeStream(true), _isMusic(isMusic), + _volume(volume), _pan(pan), _paused(false), _id(id), _converter(0), _input(0) { assert(mixer); } -Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume, int8 pan, bool reverseStereo, int id) - : _mixer(mixer), _handle(handle), _isMusic(isMusic), _volume(volume), _pan(pan), _paused(false), _id(id), _converter(0), _input(input) { +Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioInputStream *input, + bool autofreeStream, bool isMusic, byte volume, int8 pan, bool reverseStereo, int id) + : _mixer(mixer), _handle(handle), _autofreeStream(autofreeStream), _isMusic(isMusic), + _volume(volume), _pan(pan), _paused(false), _id(id), _converter(0), _input(input) { assert(mixer); assert(input); @@ -486,7 +492,8 @@ Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, AudioInputStream Channel::~Channel() { delete _converter; - delete _input; + if (_autofreeStream) + delete _input; if (_handle) _handle->resetIndex(); } diff --git a/sound/mixer.h b/sound/mixer.h index 9001245e0e..372bad4fc0 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -122,7 +122,7 @@ public: void playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume = 255, int8 pan = 0, int id = -1); #endif - void playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume = 255, int8 pan = 0, int id = -1); + void playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume = 255, int8 pan = 0, int id = -1, bool autofreeStream = true); /** Start a new stream. */ |