[Scummvm-cvs-logs] SF.net SVN: scummvm: [24536] scummvm/trunk/engines/scumm/smush

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Oct 28 00:26:51 CEST 2006


Revision: 24536
          http://svn.sourceforge.net/scummvm/?rev=24536&view=rev
Author:   fingolfin
Date:     2006-10-27 15:26:33 -0700 (Fri, 27 Oct 2006)

Log Message:
-----------
SCUMM: Unified some SMUSH audio channel code

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/smush/channel.h
    scummvm/trunk/engines/scumm/smush/imuse_channel.cpp
    scummvm/trunk/engines/scumm/smush/saud_channel.cpp
    scummvm/trunk/engines/scumm/smush/smush_mixer.cpp
    scummvm/trunk/engines/scumm/smush/smush_player.cpp
    scummvm/trunk/engines/scumm/smush/smush_player.h

Modified: scummvm/trunk/engines/scumm/smush/channel.h
===================================================================
--- scummvm/trunk/engines/scumm/smush/channel.h	2006-10-27 15:02:40 UTC (rev 24535)
+++ scummvm/trunk/engines/scumm/smush/channel.h	2006-10-27 22:26:33 UTC (rev 24536)
@@ -31,9 +31,36 @@
 class ContChunk;
 
 class SmushChannel {
+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;
+
 public:
-
-	virtual ~SmushChannel() {};
+	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 @@
 	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 @@
 	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 @@
 	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 @@
 
 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 @@
 	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 @@
 	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;

Modified: scummvm/trunk/engines/scumm/smush/imuse_channel.cpp
===================================================================
--- scummvm/trunk/engines/scumm/smush/imuse_channel.cpp	2006-10-27 15:02:40 UTC (rev 24535)
+++ scummvm/trunk/engines/scumm/smush/imuse_channel.cpp	2006-10-27 22:26:33 UTC (rev 24536)
@@ -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 @@
 
 	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 @@
 		}
 	} 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;

Modified: scummvm/trunk/engines/scumm/smush/saud_channel.cpp
===================================================================
--- scummvm/trunk/engines/scumm/smush/saud_channel.cpp	2006-10-27 15:02:40 UTC (rev 24535)
+++ scummvm/trunk/engines/scumm/smush/saud_channel.cpp	2006-10-27 22:26:33 UTC (rev 24536)
@@ -106,7 +106,8 @@
 	} 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 @@
 		}
 	} else {
 		int32 offset = 0;
-		while (handleSubTags(offset));
+		while (handleSubTags(offset))
+			;
 		if (_inData) {
 			_sbufferSize = _tbufferSize - offset;
 			assert(_sbufferSize);
@@ -159,18 +161,10 @@
 	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 @@
 	_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;
 }
 

Modified: scummvm/trunk/engines/scumm/smush/smush_mixer.cpp
===================================================================
--- scummvm/trunk/engines/scumm/smush/smush_mixer.cpp	2006-10-27 15:02:40 UTC (rev 24535)
+++ scummvm/trunk/engines/scumm/smush/smush_mixer.cpp	2006-10-27 22:26:33 UTC (rev 24536)
@@ -104,11 +104,11 @@
 					_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 @@
 
 				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);

Modified: scummvm/trunk/engines/scumm/smush/smush_player.cpp
===================================================================
--- scummvm/trunk/engines/scumm/smush/smush_player.cpp	2006-10-27 15:02:40 UTC (rev 24535)
+++ scummvm/trunk/engines/scumm/smush/smush_player.cpp	2006-10-27 22:26:33 UTC (rev 24536)
@@ -261,7 +261,6 @@
 	_width = 0;
 	_height = 0;
 	_IACTpos = 0;
-	_soundFrequency = 22050;
 	_initDone = false;
 	_speed = -1;
 	_insanity = false;
@@ -377,7 +376,7 @@
 //	}
 	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 @@
 		} 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)

Modified: scummvm/trunk/engines/scumm/smush/smush_player.h
===================================================================
--- scummvm/trunk/engines/scumm/smush/smush_player.h	2006-10-27 15:02:40 UTC (rev 24535)
+++ scummvm/trunk/engines/scumm/smush/smush_player.h	2006-10-27 22:26:33 UTC (rev 24536)
@@ -68,7 +68,6 @@
 	byte _IACToutput[4096];
 	int32 _IACTpos;
 	bool _storeFrame;
-	int _soundFrequency;
 	bool _alreadyInit;
 	bool _initDone;
 	int _speed;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list