aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2006-10-27 22:26:33 +0000
committerMax Horn2006-10-27 22:26:33 +0000
commitec653efc8bee4068046889456b1f25433dffe30f (patch)
treea6c8f64355d42703958482e92bccd766a2c653b5
parent9f85511537f460d70bf8b3b22ff77327554e752d (diff)
downloadscummvm-rg350-ec653efc8bee4068046889456b1f25433dffe30f.tar.gz
scummvm-rg350-ec653efc8bee4068046889456b1f25433dffe30f.tar.bz2
scummvm-rg350-ec653efc8bee4068046889456b1f25433dffe30f.zip
SCUMM: Unified some SMUSH audio channel code
svn-id: r24536
-rw-r--r--engines/scumm/smush/channel.h65
-rw-r--r--engines/scumm/smush/imuse_channel.cpp33
-rw-r--r--engines/scumm/smush/saud_channel.cpp22
-rw-r--r--engines/scumm/smush/smush_mixer.cpp6
-rw-r--r--engines/scumm/smush/smush_player.cpp7
-rw-r--r--engines/scumm/smush/smush_player.h1
6 files changed, 57 insertions, 77 deletions
diff --git a/engines/scumm/smush/channel.h b/engines/scumm/smush/channel.h
index 52e64c8b2d..4303006561 100644
--- a/engines/scumm/smush/channel.h
+++ b/engines/scumm/smush/channel.h
@@ -31,9 +31,36 @@ class Chunk;
class ContChunk;
class SmushChannel {
-public:
+protected:
+ int32 _track; //!< the track number
+ byte *_tbuffer; //!< data temporary buffer
+ int32 _tbufferSize; //!< temporary buffer size
+ byte *_sbuffer; //!< sound buffer
+ int32 _sbufferSize; //!< sound buffer size
+
+ int32 _dataSize; //!< remaining size of sound data in the iMUS buffer
+
+ bool _inData;
+
+ int32 _volume;
+ int32 _pan;
- virtual ~SmushChannel() {};
+public:
+ SmushChannel(int32 track) :
+ _track(track),
+ _tbuffer(0),
+ _tbufferSize(0),
+ _sbuffer(0),
+ _sbufferSize(0),
+ _dataSize(-1),
+ _inData(false),
+ _volume(0),
+ _pan(0) {
+ }
+ virtual ~SmushChannel() {
+ delete[] _tbuffer;
+ delete[] _sbuffer;
+ }
virtual bool appendData(Chunk &b, int32 size) = 0;
virtual bool setParameters(int32, int32, int32, int32, int32) = 0;
virtual bool checkParameters(int32, int32, int32, int32, int32) = 0;
@@ -42,26 +69,16 @@ public:
virtual void getSoundData(int16 *sound_buffer, int32 size) = 0;
virtual void getSoundData(int8 *sound_buffer, int32 size) = 0;
virtual int32 getRate() = 0;
- virtual bool getParameters(int32 &rate, bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) = 0;
+ virtual bool getParameters(bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) = 0;
virtual int32 getTrackIdentifier() const = 0;
};
class SaudChannel : public SmushChannel {
private:
- int32 _track;
int32 _nbframes;
- int32 _dataSize;
- int32 _frequency;
- bool _inData;
bool _markReached;
int32 _flags;
- int32 _volume;
- int32 _pan;
int32 _index;
- byte *_tbuffer;
- int32 _tbufferSize;
- byte *_sbuffer;
- int32 _sbufferSize;
bool _keepSize;
protected:
@@ -72,7 +89,7 @@ protected:
bool processBuffer();
public:
- SaudChannel(int32 track, int32 freq);
+ SaudChannel(int32 track);
virtual ~SaudChannel();
bool isTerminated() const;
bool setParameters(int32 duration, int32 flags, int32 vol1, int32 vol2, int32 index);
@@ -81,9 +98,8 @@ public:
int32 availableSoundData() const;
void getSoundData(int16 *sound_buffer, int32 size);
void getSoundData(int8 *sound_buffer, int32 size) { error("8bit request for SAUD channel should never happen"); };
- int32 getRate() { return _frequency; }
- bool getParameters(int32 &rate, bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) {
- rate = _frequency;
+ int32 getRate() { return 22050; }
+ bool getParameters(bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) {
stereo = true;
is_16bit = true;
vol = _volume;
@@ -95,17 +111,7 @@ public:
class ImuseChannel : public SmushChannel {
private:
- int32 _track; //!< the track number
- byte *_tbuffer; //!< data temporary buffer
- int32 _tbufferSize; //!< temporary buffer size
- byte *_sbuffer; //!< sound buffer
- int32 _sbufferSize; //!< sound buffer size
int32 _srbufferSize;
- int32 _frequency; //!< the target frequency of the ::mixer
- int32 _dataSize; //!< remaining size of sound data in the iMUS buffer
- bool _inData;
- int32 _volume;
- int32 _pan;
int32 _bitsize; //!< the bitsize of the original data
int32 _rate; //!< the sampling rate of the original data
@@ -122,7 +128,7 @@ protected:
bool handleSubTags(int32 & offset);
public:
- ImuseChannel(int32 track, int32 freq);
+ ImuseChannel(int32 track);
virtual ~ImuseChannel();
bool isTerminated() const;
bool setParameters(int32 nbframes, int32 size, int32 track_flags, int32 unk1, int32);
@@ -132,8 +138,7 @@ public:
void getSoundData(int16 *sound_buffer, int32 size);
void getSoundData(int8 *sound_buffer, int32 size);
int32 getRate() { return _rate; }
- bool getParameters(int32 &rate, bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) {
- rate = _rate;
+ bool getParameters(bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) {
stereo = (_channels == 2);
is_16bit = (_bitsize > 8);
vol = _volume;
diff --git a/engines/scumm/smush/imuse_channel.cpp b/engines/scumm/smush/imuse_channel.cpp
index c679c3f6ff..aca8bf6d4a 100644
--- a/engines/scumm/smush/imuse_channel.cpp
+++ b/engines/scumm/smush/imuse_channel.cpp
@@ -29,25 +29,10 @@
namespace Scumm {
-ImuseChannel::ImuseChannel(int32 track, int32 freq) :
- _track(track),
- _tbuffer(0),
- _tbufferSize(0),
- _sbuffer(0),
- _sbufferSize(0),
- _frequency(freq),
- _dataSize(-1),
- _inData(false) {
+ImuseChannel::ImuseChannel(int32 track) : SmushChannel(track) {
}
ImuseChannel::~ImuseChannel() {
- if (_tbuffer) {
- delete []_tbuffer;
- }
- if (_sbuffer) {
- warning("_sbuffer should be 0 !!!");
- delete []_sbuffer;
- }
}
bool ImuseChannel::isTerminated() const {
@@ -260,14 +245,16 @@ bool ImuseChannel::processBuffer() {
if (_inData) {
if (_dataSize < _tbufferSize) {
- int32 offset= _dataSize;
- while (handleSubTags(offset));
+ int32 offset = _dataSize;
+ while (handleSubTags(offset))
+ ;
_sbufferSize = _dataSize;
_sbuffer = _tbuffer;
if (offset < _tbufferSize) {
- int32 new_size = _tbufferSize - offset;
+ int new_size = _tbufferSize - offset;
_tbuffer = new byte[new_size];
- if (!_tbuffer) error("imuse_channel failed to allocate memory");
+ if (!_tbuffer)
+ error("imuse_channel failed to allocate memory");
memcpy(_tbuffer, _sbuffer + offset, new_size);
_tbufferSize = new_size;
} else {
@@ -286,12 +273,14 @@ bool ImuseChannel::processBuffer() {
}
} else {
int32 offset = 0;
- while (handleSubTags(offset));
+ while (handleSubTags(offset))
+ ;
if (_inData) {
_sbufferSize = _tbufferSize - offset;
assert(_sbufferSize);
_sbuffer = new byte[_sbufferSize];
- if (!_sbuffer) error("imuse_channel failed to allocate memory");
+ if (!_sbuffer)
+ error("imuse_channel failed to allocate memory");
memcpy(_sbuffer, _tbuffer + offset, _sbufferSize);
delete []_tbuffer;
_tbuffer = 0;
diff --git a/engines/scumm/smush/saud_channel.cpp b/engines/scumm/smush/saud_channel.cpp
index 77bc4c89e2..cb05a759ac 100644
--- a/engines/scumm/smush/saud_channel.cpp
+++ b/engines/scumm/smush/saud_channel.cpp
@@ -106,7 +106,8 @@ bool SaudChannel::processBuffer() {
} else if (_inData) {
if (_dataSize < _tbufferSize) {
int32 offset = _dataSize;
- while (handleSubTags(offset)) ;
+ while (handleSubTags(offset))
+ ;
_sbufferSize = _dataSize;
_sbuffer = _tbuffer;
if (offset < _tbufferSize) {
@@ -132,7 +133,8 @@ bool SaudChannel::processBuffer() {
}
} else {
int32 offset = 0;
- while (handleSubTags(offset));
+ while (handleSubTags(offset))
+ ;
if (_inData) {
_sbufferSize = _tbufferSize - offset;
assert(_sbufferSize);
@@ -159,18 +161,10 @@ bool SaudChannel::processBuffer() {
return true;
}
-SaudChannel::SaudChannel(int32 track, int32 freq) :
- _track(track),
+SaudChannel::SaudChannel(int32 track) : SmushChannel(track),
_nbframes(0),
- _dataSize(-1),
- _frequency(freq),
- _inData(false),
_markReached(false),
_index(0),
- _tbuffer(0),
- _tbufferSize(0),
- _sbuffer(0),
- _sbufferSize(0),
_keepSize(false) {
}
@@ -179,12 +173,6 @@ SaudChannel::~SaudChannel() {
_tbufferSize = 0;
_sbufferSize = 0;
_markReached = true;
- if (_tbuffer)
- delete []_tbuffer;
- if (_sbuffer) {
- // _sbuffer can be not empty here with insane when it seeks in video
- delete []_sbuffer;
- }
_sbuffer = 0;
}
diff --git a/engines/scumm/smush/smush_mixer.cpp b/engines/scumm/smush/smush_mixer.cpp
index b5002609df..b078181735 100644
--- a/engines/scumm/smush/smush_mixer.cpp
+++ b/engines/scumm/smush/smush_mixer.cpp
@@ -104,11 +104,11 @@ bool SmushMixer::handleFrame() {
_channels[i].stream = 0;
}
} else {
- int32 rate, vol, pan;
+ int32 vol, pan;
bool stereo, is_16bit;
void *data;
- _channels[i].chan->getParameters(rate, stereo, is_16bit, vol, pan);
+ _channels[i].chan->getParameters(stereo, is_16bit, vol, pan);
int32 size = _channels[i].chan->availableSoundData();
byte flags = stereo ? Audio::Mixer::FLAG_STEREO : 0;
@@ -129,7 +129,7 @@ bool SmushMixer::handleFrame() {
if (_mixer->isReady()) {
if (!_channels[i].stream) {
- _channels[i].stream = Audio::makeAppendableAudioStream(rate, flags, 500000);
+ _channels[i].stream = Audio::makeAppendableAudioStream(_channels[i].chan->getRate(), flags, 500000);
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_channels[i].handle, _channels[i].stream);
}
_mixer->setChannelVolume(_channels[i].handle, vol);
diff --git a/engines/scumm/smush/smush_player.cpp b/engines/scumm/smush/smush_player.cpp
index 8dd4451627..ae59c63a02 100644
--- a/engines/scumm/smush/smush_player.cpp
+++ b/engines/scumm/smush/smush_player.cpp
@@ -261,7 +261,6 @@ SmushPlayer::SmushPlayer(ScummEngine_v7 *scumm) {
_width = 0;
_height = 0;
_IACTpos = 0;
- _soundFrequency = 22050;
_initDone = false;
_speed = -1;
_insanity = false;
@@ -377,7 +376,7 @@ void SmushPlayer::handleSoundBuffer(int32 track_id, int32 index, int32 max_frame
// }
SmushChannel *c = _smixer->findChannel(track_id);
if (c == NULL) {
- c = new SaudChannel(track_id, _soundFrequency);
+ c = new SaudChannel(track_id);
_smixer->addChannel(c);
}
@@ -462,13 +461,13 @@ void SmushPlayer::handleIACT(Chunk &b) {
} else if ((track_flags >= 300) && (track_flags <= 363)) {
track = track_id + 600;
} else {
- error("ImuseChannel::handleIACT(): bad track_flags: %d", track_flags);
+ error("SmushPlayer::handleIACT(): bad track_flags: %d", track_flags);
}
debugC(DEBUG_SMUSH, "SmushPlayer::handleIACT(): %d, %d, %d", track, index, track_flags);
SmushChannel *c = _smixer->findChannel(track);
if (c == 0) {
- c = new ImuseChannel(track, _soundFrequency);
+ c = new ImuseChannel(track);
_smixer->addChannel(c);
}
if (index == 0)
diff --git a/engines/scumm/smush/smush_player.h b/engines/scumm/smush/smush_player.h
index 34728b9e4f..53fee75f9c 100644
--- a/engines/scumm/smush/smush_player.h
+++ b/engines/scumm/smush/smush_player.h
@@ -68,7 +68,6 @@ private:
byte _IACToutput[4096];
int32 _IACTpos;
bool _storeFrame;
- int _soundFrequency;
bool _alreadyInit;
bool _initDone;
int _speed;