From 3ad14b06f507d056da5c8e1506d95e607029f75e Mon Sep 17 00:00:00 2001 From: Joost Peters Date: Fri, 24 Oct 2003 23:09:01 +0000 Subject: added extra flag to mixer so we don't use free() on new'd pointers svn-id: r10958 --- queen/sound.cpp | 2 +- sound/mixer.cpp | 7 ++++++- sound/mixer.h | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/queen/sound.cpp b/queen/sound.cpp index 15a831b89e..50768ed804 100644 --- a/queen/sound.cpp +++ b/queen/sound.cpp @@ -62,7 +62,7 @@ bool Sound::isPlaying() { } int SBSound::playSound(byte *sound, uint32 size) { - byte flags = 0 | SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE; + byte flags = 0 | SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTODELETE; return _mixer->playRaw(&_sfxHandle, sound, size, 11025, flags); } diff --git a/sound/mixer.cpp b/sound/mixer.cpp index a46ad18db7..21439a648e 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -44,6 +44,7 @@ protected: RateConverter *_converter; AudioInputStream *_input; byte _volume; + byte _flags; int8 _pan; bool _paused; @@ -510,6 +511,7 @@ ChannelRaw::ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *soun : Channel(mixer, handle) { _id = id; _ptr = (byte *)sound; + _flags = flags; _volume = volume; _pan = pan; @@ -533,7 +535,10 @@ ChannelRaw::ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *soun } ChannelRaw::~ChannelRaw() { - free(_ptr); + if (_flags & SoundMixer::FLAG_AUTOFREE) + free(_ptr); + else if (_flags & SoundMixer::FLAG_AUTODELETE) + delete _ptr; } ChannelStream::ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle, diff --git a/sound/mixer.h b/sound/mixer.h index 03e8b46385..12b51b705c 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -55,7 +55,9 @@ public: FLAG_16BITS = 1 << 2, // sound is 16 bits wide (default: 8bit) FLAG_AUTOFREE = 1 << 3, // sound buffer is freed automagically at the end of playing FLAG_REVERSE_STEREO = 1 << 4, // reverse the left and right stereo channel - FLAG_LOOP = 1 << 5 // loop the audio + FLAG_LOOP = 1 << 5, // loop the audio + FLAG_AUTODELETE = 1 << 6 // same as AUTOFREE, but uses delete instead of free() + }; private: -- cgit v1.2.3