[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.42,1.43 mixer.cpp,1.132,1.133

Max Horn fingolfin at users.sourceforge.net
Tue Dec 16 17:33:00 CET 2003


Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv23141

Modified Files:
	audiostream.cpp mixer.cpp 
Log Message:
some cleanup

Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- audiostream.cpp	16 Dec 2003 02:11:04 -0000	1.42
+++ audiostream.cpp	17 Dec 2003 01:32:00 -0000	1.43
@@ -51,16 +51,6 @@
 	const byte *_loopPtr;
 	const byte *_loopEnd;
 
-	inline int16 readIntern() {
-		//assert(_ptr < _end);
-		int16 val = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE);
-		_ptr += (is16Bit ? 2 : 1);
-		if (_loopPtr && eosIntern()) {
-			_ptr = _loopPtr;
-			_end = _loopEnd;
-		}
-		return val;
-	}
 	inline bool eosIntern() const	{ return _ptr >= _end; };
 public:
 	LinearMemoryStream(const byte *ptr, uint len, uint loopOffset, uint loopLen)
@@ -81,7 +71,16 @@
 	}
 	int readBuffer(int16 *buffer, const int numSamples);
 
-	int16 read()				{ return readIntern(); }
+	int16 read() {
+		//assert(_ptr < _end);
+		int16 val = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE);
+		_ptr += (is16Bit ? 2 : 1);
+		if (_loopPtr && eosIntern()) {
+			_ptr = _loopPtr;
+			_end = _loopEnd;
+		}
+		return val;
+	}
 	bool eos() const			{ return eosIntern(); }
 	bool isStereo() const		{ return stereo; }
 };
@@ -120,14 +119,13 @@
 	byte *_pos;
 	byte *_end;
 
-	inline int16 readIntern();
 	inline bool eosIntern() const { return _end == _pos; };
 public:
 	WrappedMemoryStream(uint bufferSize);
 	~WrappedMemoryStream()		{ free(_bufferStart); }
 	int readBuffer(int16 *buffer, const int numSamples);
 
-	int16 read()				{ return readIntern(); }
+	int16 read();
 	bool eos() const			{ return eosIntern(); }
 	bool isStereo() const		{ return stereo; }
 
@@ -150,8 +148,11 @@
 }
 
 template<bool stereo, bool is16Bit, bool isUnsigned>
-inline int16 WrappedMemoryStream<stereo, is16Bit, isUnsigned>::readIntern() {
-	//assert(_pos != _end);
+inline int16 WrappedMemoryStream<stereo, is16Bit, isUnsigned>::read() {
+	if (eosIntern()) {
+		// If the stream contains no more data, it is silent...
+		return 0;
+	}
 	int16 val = READSAMPLE(is16Bit, isUnsigned, _pos);
 	_pos += (is16Bit ? 2 : 1);
 
@@ -232,14 +233,13 @@
 
 	bool init();
 	void refill(bool first = false);
-	inline int16 readIntern();
 	inline bool eosIntern() const;
 public:
 	MP3InputStream(File *file, mad_timer_t duration, uint size = 0);
 	~MP3InputStream();
 	int readBuffer(int16 *buffer, const int numSamples);
 
-	int16 read()				{ return readIntern(); }
+	int16 read();
 	bool eos() const			{ return eosIntern(); }
 	bool isStereo() const		{ return _isStereo; }
 	
@@ -397,7 +397,7 @@
 	return sample >> (MAD_F_FRACBITS + 1 - 16);
 }
 
-inline int16 MP3InputStream::readIntern() {
+inline int16 MP3InputStream::read() {
 	assert(!eosIntern());
 
 	int16 sample;
@@ -465,13 +465,12 @@
 	const int16 *_pos;
 	
 	void refill();
-	inline int16 readIntern();
 	inline bool eosIntern() const;
 public:
 	VorbisInputStream(OggVorbis_File *file, int duration);
 	int readBuffer(int16 *buffer, const int numSamples);
 
-	int16 read()				{ return readIntern(); }
+	int16 read();
 	bool eos() const			{ return eosIntern(); }
 	bool isStereo() const		{ return _numChannels >= 2; }
 	
@@ -500,7 +499,7 @@
 	refill();
 }
 
-inline int16 VorbisInputStream::readIntern() {
+inline int16 VorbisInputStream::read() {
 	assert(!eosIntern());
 
 	int16 sample = *_pos++;

Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -d -r1.132 -r1.133
--- mixer.cpp	16 Dec 2003 15:34:16 -0000	1.132
+++ mixer.cpp	17 Dec 2003 01:32:00 -0000	1.133
@@ -38,20 +38,22 @@
  * Channels used by the sound mixer.
  */
 class Channel {
-protected:
+private:
 	SoundMixer *_mixer;
 	PlayingSoundHandle *_handle;
-	RateConverter *_converter;
-	AudioInputStream *_input;
 	byte _volume;
 	int8 _pan;
 	bool _paused;
 
+protected:
+	RateConverter *_converter;
+	AudioInputStream *_input;
+
 public:
 	int _id;
 
-	Channel(SoundMixer *mixer, PlayingSoundHandle *handle)
-		: _mixer(mixer), _handle(handle), _converter(0), _input(0), _volume(0), _pan(0), _paused(false), _id(-1) {
+	Channel(SoundMixer *mixer, PlayingSoundHandle *handle, byte volume, int8 pan)
+		: _mixer(mixer), _handle(handle), _converter(0), _input(0), _volume(volume), _pan(pan), _paused(false), _id(-1) {
 		assert(mixer);
 	}
 	virtual ~Channel();
@@ -97,24 +99,20 @@
 
 #ifdef USE_MAD
 class ChannelMP3 : public Channel {
+	const bool _isMusic;
 public:
 	ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, uint size, byte volume, int8 pan);
-	bool isMusicChannel() const		{ return false; }
-};
-
-class ChannelMP3CDMusic : public Channel {
-public:
-	ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan);
-	bool isMusicChannel() const		{ return true; }
+	ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan);
+	bool isMusicChannel() const		{ return _isMusic; }
 };
 #endif // USE_MAD
 
 #ifdef USE_VORBIS
 class ChannelVorbis : public Channel {
-	bool _is_cd_track;
+	const bool _isMusic;
 public:
-	ChannelVorbis(SoundMixer *mixer, PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume, int8 pan);
-	bool isMusicChannel() const		{ return _is_cd_track; }
+	ChannelVorbis(SoundMixer *mixer, PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool isMusic, byte volume, int8 pan);
+	bool isMusicChannel() const		{ return _isMusic; }
 };
 #endif // USE_VORBIS
 
@@ -266,7 +264,7 @@
 }
 int SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan) {
 	Common::StackLock lock(_mutex);
-	return insertChannel(handle, new ChannelMP3CDMusic(this, handle, file, duration, volume, pan));
+	return insertChannel(handle, new ChannelMP3(this, handle, file, duration, volume, pan));
 }
 #endif
 
@@ -509,11 +507,9 @@
 
 /* RAW mixer */
 ChannelRaw::ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, byte volume, int8 pan, int id, uint32 loopStart, uint32 loopEnd)
-	: Channel(mixer, handle) {
+	: Channel(mixer, handle, volume, pan) {
 	_id = id;
 	_ptr = (byte *)sound;
-	_volume = volume;
-	_pan = pan;
 	
 	// Create the input stream
 	if (flags & SoundMixer::FLAG_LOOP) {
@@ -541,9 +537,7 @@
 ChannelStream::ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle,
 							void *sound, uint32 size, uint rate,
 							byte flags, uint32 buffer_size, byte volume, int8 pan)
-	: Channel(mixer, handle) {
-	_volume = volume;
-	_pan = pan;
+	: Channel(mixer, handle, volume, pan) {
 	assert(size <= buffer_size);
 
 	// Create the input stream
@@ -583,9 +577,7 @@
 
 #ifdef USE_MAD
 ChannelMP3::ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, uint size, byte volume, int8 pan)
-	: Channel(mixer, handle) {
-	_volume = volume;
-	_pan = pan;
+	: Channel(mixer, handle, volume, pan), _isMusic(false) {
 	// Create the input stream
 	_input = makeMP3Stream(file, mad_timer_zero, size);
 
@@ -593,10 +585,8 @@
 	_converter = makeRateConverter(_input->getRate(), mixer->getOutputRate(), _input->isStereo());
 }
 
-ChannelMP3CDMusic::ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan) 
-	: Channel(mixer, handle) {
-	_volume = volume;
-	_pan = pan;
+ChannelMP3::ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan) 
+	: Channel(mixer, handle, volume, pan), _isMusic(true) {
 	// Create the input stream
 	_input = makeMP3Stream(file, duration, 0);
 
@@ -606,15 +596,12 @@
 #endif // USE_MAD
 
 #ifdef USE_VORBIS
-ChannelVorbis::ChannelVorbis(SoundMixer *mixer, PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume, int8 pan)
-	: Channel(mixer, handle) {
-	_volume = volume;
-	_pan = pan;
+ChannelVorbis::ChannelVorbis(SoundMixer *mixer, PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool isMusic, byte volume, int8 pan)
+	: Channel(mixer, handle, volume, pan), _isMusic(isMusic) {
 	// Create the input stream
 	_input = makeVorbisStream(ov_file, duration);
 
 	// Get a rate converter instance
 	_converter = makeRateConverter(_input->getRate(), mixer->getOutputRate(), _input->isStereo());
-	_is_cd_track = is_cd_track;
 }
 #endif // USE_VORBIS





More information about the Scummvm-git-logs mailing list