aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm/smush
diff options
context:
space:
mode:
authorMax Horn2006-10-28 00:18:13 +0000
committerMax Horn2006-10-28 00:18:13 +0000
commit48e5ec67ffcc3f45816507d53d7b276414a31867 (patch)
treecf4b88062da3f829b45aadb980c3bf25c64006cd /engines/scumm/smush
parentd90762c430d9ee20ca4137d324aac5dc8308fdd6 (diff)
downloadscummvm-rg350-48e5ec67ffcc3f45816507d53d7b276414a31867.tar.gz
scummvm-rg350-48e5ec67ffcc3f45816507d53d7b276414a31867.tar.bz2
scummvm-rg350-48e5ec67ffcc3f45816507d53d7b276414a31867.zip
SCUMM: Further SMUSH audio channel cleanup; this time unified some code, and got rid of one set of memory buffers
svn-id: r24542
Diffstat (limited to 'engines/scumm/smush')
-rw-r--r--engines/scumm/smush/channel.h15
-rw-r--r--engines/scumm/smush/imuse_channel.cpp30
-rw-r--r--engines/scumm/smush/saud_channel.cpp14
-rw-r--r--engines/scumm/smush/smush_mixer.cpp18
4 files changed, 22 insertions, 55 deletions
diff --git a/engines/scumm/smush/channel.h b/engines/scumm/smush/channel.h
index 633c87a8c4..97a0d65488 100644
--- a/engines/scumm/smush/channel.h
+++ b/engines/scumm/smush/channel.h
@@ -56,13 +56,12 @@ public:
virtual bool setParameters(int32, int32, int32, int32, int32) = 0;
virtual bool checkParameters(int32, int32, int32, int32, int32) = 0;
virtual bool isTerminated() const = 0;
- virtual int32 getAvailableSoundDataSize() const = 0;
- virtual void getSoundData(int16 *sound_buffer, int32 size) = 0;
- virtual void getSoundData(int8 *sound_buffer, int32 size) = 0;
+ virtual byte *getSoundData() = 0;
virtual int32 getRate() = 0;
virtual bool getParameters(bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) = 0;
- int32 getTrackIdentifier() const { return _track; };
+ int32 getAvailableSoundDataSize() const { return _sbufferSize; }
+ int32 getTrackIdentifier() const { return _track; }
};
class SaudChannel : public SmushChannel {
@@ -86,9 +85,7 @@ public:
bool setParameters(int32 duration, int32 flags, int32 vol1, int32 vol2, int32 index);
bool checkParameters(int32 index, int32 duration, int32 flags, int32 vol1, int32 vol2);
bool appendData(Chunk &b, int32 size);
- int32 getAvailableSoundDataSize() const;
- void getSoundData(int16 *sound_buffer, int32 size) { error("16bit request for SAUD channel should never happen"); };
- void getSoundData(int8 *sound_buffer, int32 size);
+ byte *getSoundData();
int32 getRate() { return 22050; }
bool getParameters(bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) {
stereo = false;
@@ -123,9 +120,7 @@ public:
bool setParameters(int32 nbframes, int32 size, int32 track_flags, int32 unk1, int32);
bool checkParameters(int32 index, int32 nbframes, int32 size, int32 track_flags, int32 unk1);
bool appendData(Chunk &b, int32 size);
- int32 getAvailableSoundDataSize() const;
- void getSoundData(int16 *sound_buffer, int32 size);
- void getSoundData(int8 *sound_buffer, int32 size);
+ byte *getSoundData();
int32 getRate() { return _rate; }
bool getParameters(bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) {
stereo = (_channels == 2);
diff --git a/engines/scumm/smush/imuse_channel.cpp b/engines/scumm/smush/imuse_channel.cpp
index d05192eadd..b9600f36e8 100644
--- a/engines/scumm/smush/imuse_channel.cpp
+++ b/engines/scumm/smush/imuse_channel.cpp
@@ -246,36 +246,16 @@ bool ImuseChannel::handleSubTags(int32 &offset) {
return false;
}
-int32 ImuseChannel::getAvailableSoundDataSize(void) const {
- int32 ret = _sbufferSize;
- if (_channels == 2) ret /= 2;
- if (_bitsize > 8) ret /= 2;
- return ret;
-}
-
-void ImuseChannel::getSoundData(int16 *snd, int32 size) {
- if (_dataSize <= 0 || _bitsize <= 8) error("invalid call to imuse_channel::read_sound_data()");
- if (_channels == 2) size *= 2;
-
- memcpy(snd, _sbuffer, size * 2);
+byte *ImuseChannel::getSoundData() {
+ byte *tmp = _sbuffer;
- delete []_sbuffer;
- assert(_sbufferSize == 2 * size);
- _sbuffer = 0;
- _sbufferSize = 0;
+ assert(_dataSize > 0);
_dataSize -= _srbufferSize;
-}
-
-void ImuseChannel::getSoundData(int8 *snd, int32 size) {
- if (_dataSize <= 0 || _bitsize > 8) error("invalid call to imuse_channel::read_sound_data()");
- if (_channels == 2) size *= 2;
-
- memcpy(snd, _sbuffer, size);
- delete []_sbuffer;
_sbuffer = 0;
_sbufferSize = 0;
- _dataSize -= _srbufferSize;
+
+ return tmp;
}
} // End of namespace Scumm
diff --git a/engines/scumm/smush/saud_channel.cpp b/engines/scumm/smush/saud_channel.cpp
index 86ed7811ca..befeadad91 100644
--- a/engines/scumm/smush/saud_channel.cpp
+++ b/engines/scumm/smush/saud_channel.cpp
@@ -180,17 +180,17 @@ bool SaudChannel::appendData(Chunk &b, int32 size) {
return true;
}
-int32 SaudChannel::getAvailableSoundDataSize(void) const {
- return _sbufferSize;
-}
+byte *SaudChannel::getSoundData() {
+ byte *tmp = _sbuffer;
-void SaudChannel::getSoundData(int8 *snd, int32 size) {
- memcpy(snd, _sbuffer, size);
+ assert(_dataSize > 0);
if (!_keepSize)
- _dataSize -= size;
- delete []_sbuffer;
+ _dataSize -= _sbufferSize;
+
_sbuffer = 0;
_sbufferSize = 0;
+
+ return tmp;
}
} // End of namespace Scumm
diff --git a/engines/scumm/smush/smush_mixer.cpp b/engines/scumm/smush/smush_mixer.cpp
index ea5d167193..9b0f67045f 100644
--- a/engines/scumm/smush/smush_mixer.cpp
+++ b/engines/scumm/smush/smush_mixer.cpp
@@ -106,24 +106,16 @@ bool SmushMixer::handleFrame() {
} else {
int32 vol, pan;
bool stereo, is_16bit;
- void *data;
_channels[i].chan->getParameters(stereo, is_16bit, vol, pan);
+
int32 size = _channels[i].chan->getAvailableSoundDataSize();
- byte flags = stereo ? Audio::Mixer::FLAG_STEREO : 0;
+ byte *data = _channels[i].chan->getSoundData();
+ byte flags = stereo ? Audio::Mixer::FLAG_STEREO : 0;
if (is_16bit) {
- data = malloc(size * (stereo ? 4 : 2));
- _channels[i].chan->getSoundData((int16 *)data, size);
- size *= stereo ? 4 : 2;
-
flags |= Audio::Mixer::FLAG_16BITS;
-
} else {
- data = malloc(size * (stereo ? 2 : 1));
- _channels[i].chan->getSoundData((int8 *)data, size);
- size *= stereo ? 2 : 1;
-
flags |= Audio::Mixer::FLAG_UNSIGNED;
}
@@ -134,9 +126,9 @@ bool SmushMixer::handleFrame() {
}
_mixer->setChannelVolume(_channels[i].handle, vol);
_mixer->setChannelBalance(_channels[i].handle, pan);
- _channels[i].stream->append((byte *)data, size);
+ _channels[i].stream->append(data, size);
}
- free(data);
+ delete[] data;
}
}
}