aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2003-06-21 21:17:08 +0000
committerMax Horn2003-06-21 21:17:08 +0000
commit7c332d7fdb8ae0356ab21368c4903aea4b9b8640 (patch)
tree2276c452371b804477d3d2083e4d9d80accfca47
parent1733bafbda15665dad525eb1d0be8ae4a71efd21 (diff)
downloadscummvm-rg350-7c332d7fdb8ae0356ab21368c4903aea4b9b8640.tar.gz
scummvm-rg350-7c332d7fdb8ae0356ab21368c4903aea4b9b8640.tar.bz2
scummvm-rg350-7c332d7fdb8ae0356ab21368c4903aea4b9b8640.zip
modified & cleaned up the playStream/append code a bit; but this API really could stand some refinement
svn-id: r8592
-rw-r--r--scumm/imuse_digi.cpp9
-rw-r--r--scumm/smush/smush_mixer.cpp4
-rw-r--r--scumm/smush/smush_player.cpp5
-rw-r--r--scumm/sound.cpp10
-rw-r--r--sound/mixer.cpp20
-rw-r--r--sound/mixer.h6
6 files changed, 21 insertions, 33 deletions
diff --git a/scumm/imuse_digi.cpp b/scumm/imuse_digi.cpp
index fec6a1f2f1..f2bab909da 100644
--- a/scumm/imuse_digi.cpp
+++ b/scumm/imuse_digi.cpp
@@ -821,13 +821,14 @@ void IMuseDigital::handler() {
if (_scumm->_silentDigitalImuse == false) {
if (_channel[l]._initialized == false) {
- _scumm->_mixer->playStream(NULL, l, buf, mixer_size,
+ _scumm->_mixer->playStream(l, buf, mixer_size,
_channel[l]._freq, _channel[l]._mixerFlags, 3, 100000);
_channel[l]._initialized = true;
} else {
- _scumm->_mixer->append(l, buf, mixer_size, _channel[l]._freq, _channel[l]._mixerFlags);
+ _scumm->_mixer->append(l, buf, mixer_size);
}
}
+ free(buf);
}
}
}
@@ -860,7 +861,7 @@ void IMuseDigital::startSound(int sound) {
_channel[l]._bits = 8;
_channel[l]._channels = 2;
_channel[l]._mixerSize = (22050 / 5) * 2;
- _channel[l]._mixerFlags = SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO | SoundMixer::FLAG_UNSIGNED;
+ _channel[l]._mixerFlags = SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO | SoundMixer::FLAG_UNSIGNED;
byte * t_ptr= readCreativeVocFile(ptr, size, _channel[l]._freq, _channel[l]._numLoops);
if (_channel[l]._freq == 22222) {
@@ -960,7 +961,7 @@ void IMuseDigital::startSound(int sound) {
}
}
_channel[l]._mixerSize = (22050 / 5) * 2;
- _channel[l]._mixerFlags = SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO;
+ _channel[l]._mixerFlags = SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO;
if (_channel[l]._bits == 12) {
_channel[l]._mixerSize *= 2;
_channel[l]._mixerFlags |= SoundMixer::FLAG_16BITS;
diff --git a/scumm/smush/smush_mixer.cpp b/scumm/smush/smush_mixer.cpp
index 78f6c02e51..96a0a00ef0 100644
--- a/scumm/smush/smush_mixer.cpp
+++ b/scumm/smush/smush_mixer.cpp
@@ -131,9 +131,9 @@ bool SmushMixer::handleFrame() {
if (_silentMixer == false) {
if (_channels[i].mixer_index == -1) {
- _channels[i].mixer_index = _mixer->playStream(NULL, -1, data, size, rate, flags);
+ _channels[i].mixer_index = _mixer->playStream(-1, data, size, rate, flags);
} else {
- _mixer->append(_channels[i].mixer_index, data, size, rate, flags);
+ _mixer->append(_channels[i].mixer_index, data, size);
}
}
free(data);
diff --git a/scumm/smush/smush_player.cpp b/scumm/smush/smush_player.cpp
index c9be3863f8..928dbc8f25 100644
--- a/scumm/smush/smush_player.cpp
+++ b/scumm/smush/smush_player.cpp
@@ -451,11 +451,10 @@ void SmushPlayer::handleImuseAction(Chunk &b) {
} while (--count);
if (_IACTchannel == -1) {
- _IACTchannel = _scumm->_mixer->playStream(NULL, -1, output_data, 0x1000, 22050,
+ _IACTchannel = _scumm->_mixer->playStream(-1, output_data, 0x1000, 22050,
SoundMixer::FLAG_STEREO | SoundMixer::FLAG_16BITS, -1, 200000);
} else {
- _scumm->_mixer->append(_IACTchannel, output_data, 0x1000, 22050,
- SoundMixer::FLAG_STEREO | SoundMixer::FLAG_16BITS);
+ _scumm->_mixer->append(_IACTchannel, output_data, 0x1000);
}
bsize -= len;
diff --git a/scumm/sound.cpp b/scumm/sound.cpp
index ae9331a6a3..61daedd78c 100644
--- a/scumm/sound.cpp
+++ b/scumm/sound.cpp
@@ -1170,18 +1170,18 @@ void Sound::bundleMusicHandler(Scumm *scumm) {
final_size = _outputMixerSize;
memcpy(buffer, ptr, _outputMixerSize);
} else {
- warning("Sound::bundleMusicHandler to do more playStream options...");
+ warning("Sound::bundleMusicHandler TODO: more playStream options...");
return;
}
_bundleMusicPosition += final_size;
if (_bundleMusicTrack == -1) {
- _bundleMusicTrack = _scumm->_mixer->playStream(NULL, _scumm->_mixer->_beginSlots - 1, buffer, final_size, rate,
- SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_16BITS | SoundMixer::FLAG_STEREO, -1, 300000);
+ _bundleMusicTrack = _scumm->_mixer->playStream(_scumm->_mixer->_beginSlots - 1, buffer, final_size, rate,
+ SoundMixer::FLAG_16BITS | SoundMixer::FLAG_STEREO, -1, 300000);
} else {
- _scumm->_mixer->append(_bundleMusicTrack, buffer, final_size, rate,
- SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_16BITS | SoundMixer::FLAG_STEREO);
+ _scumm->_mixer->append(_bundleMusicTrack, buffer, final_size);
}
+ free(buffer);
}
int Sound::playBundleSound(char *sound) {
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index 27cdd7bca1..fffb623257 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -157,18 +157,14 @@ void SoundMixer::unInsert(Channel *chan) {
error("SoundMixer::channel_deleted chan not found");
}
-int SoundMixer::append(int index, void *sound, uint32 size, uint rate, byte flags) {
+int SoundMixer::append(int index, void *sound, uint32 size) {
_syst->lock_mutex(_mutex);
Channel *chan = _channels[index];
if (!chan) {
- debug(2, "Trying to stream to an unexistant streamer : %d", index);
- playStream(NULL, index, sound, size, rate, flags);
- chan = _channels[index];
+ error("Trying to stream to a nonexistant streamer : %d", index);
} else {
- chan->append(sound, size);
- if (flags & FLAG_AUTOFREE)
- free(sound);
+ dynamic_cast<ChannelStream *>(chan)->append(sound, size);
}
_syst->unlock_mutex(_mutex);
@@ -205,9 +201,9 @@ int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, ui
return -1;
}
-int SoundMixer::playStream(PlayingSoundHandle *handle, int idx, void *sound, uint32 size,
+int SoundMixer::playStream(int idx, void *sound, uint32 size,
uint rate, byte flags, int32 timeout, int32 buffer_size) {
- return insertAt(handle, idx, new ChannelStream(this, sound, size, rate, flags, timeout, buffer_size));
+ return insertAt(NULL, idx, new ChannelStream(this, sound, size, rate, flags, timeout, buffer_size));
}
void SoundMixer::beginSlots(int index) {
@@ -648,10 +644,6 @@ bool Channel::soundFinished() {
return false;
}
-void Channel::append(void *sound, uint32 size) {
- error("append method should never be called on something else than a _STREAM mixer ");
-}
-
/* RAW mixer */
ChannelRaw::ChannelRaw(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags, int id) {
_id = id;
@@ -734,8 +726,6 @@ ChannelStream::ChannelStream(SoundMixer *mixer, void *sound, uint32 size, uint r
memcpy(_ptr, sound, size);
_endOfData = _ptr + size;
_endOfBuffer = _ptr + _bufferSize;
- if (_flags & SoundMixer::FLAG_AUTOFREE)
- free(sound);
_pos = _ptr;
_fpPos = 0;
_fpSpeed = (1 << 16) * rate / mixer->_outputRate;
diff --git a/sound/mixer.h b/sound/mixer.h
index cb5a4f220c..1abfcc4935 100644
--- a/sound/mixer.h
+++ b/sound/mixer.h
@@ -54,7 +54,6 @@ public:
_toBeDestroyed = true;
}
virtual void realDestroy() = 0;
- virtual void append(void *sound, uint32 size);
virtual bool soundFinished();
};
@@ -94,7 +93,6 @@ public:
~SoundMixer();
int insertAt(PlayingSoundHandle *handle, int index, Channel *chan);
- void append(void *data, uint32 len);
void unInsert(Channel *chan);
void beginSlots(int index);
@@ -109,7 +107,7 @@ public:
FLAG_LOOP = 1 << 5 // loop the audio
};
int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id = -1);
- int playStream(PlayingSoundHandle *handle, int index, void *sound, uint32 size, uint rate,
+ int playStream(int index, void *sound, uint32 size, uint rate,
byte flags, int32 timeout = 3, int32 buffer_size = 2000000);
#ifdef USE_MAD
int playMP3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags);
@@ -135,7 +133,7 @@ public:
void stopID(int id);
/** append to existing sound */
- int append(int index, void * sound, uint32 size, uint rate, byte flags);
+ int append(int index, void * sound, uint32 size);
/** is any channel active? */
bool hasActiveChannel();