[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.36,1.37

Max Horn fingolfin at users.sourceforge.net
Sun Aug 24 14:55:08 CEST 2003


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

Modified Files:
	audiostream.cpp 
Log Message:
small cleanup for the Ogg playback code

Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- audiostream.cpp	7 Aug 2003 23:54:39 -0000	1.36
+++ audiostream.cpp	24 Aug 2003 21:54:46 -0000	1.37
@@ -458,10 +458,9 @@
 class VorbisInputStream : public MusicStream {
 	OggVorbis_File *_ov_file;
 	int _end_pos;
-	bool _eofFlag;
 	int _numChannels;
 	int16 _buffer[4096];
-	const int16 * const _bufferEnd;
+	const int16 *_bufferEnd;
 	const int16 *_pos;
 	
 	void refill();
@@ -486,43 +485,45 @@
 
 VorbisInputStream::VorbisInputStream(OggVorbis_File *file, int duration) 
 	: _ov_file(file), _bufferEnd(_buffer + ARRAYSIZE(_buffer)) {
-	_pos = _bufferEnd;
+
+	// Check the header, determine if this is a stereo stream
 	_numChannels = ov_info(_ov_file, -1)->channels;
 
+	// Determine the end position
 	if (duration)
 		_end_pos = ov_pcm_tell(_ov_file) + duration;
 	else
 		_end_pos = ov_pcm_total(_ov_file, -1);
-
-	_eofFlag = false;
+	
+	// Read in initial data
+	refill();
 }
 
 inline int16 VorbisInputStream::readIntern() {
+	assert(!eosIntern());
+
+	int16 sample = *_pos++;
 	if (_pos >= _bufferEnd) {
 		refill();
 	}
-	return *_pos++;
+	return sample;
 }
 
 inline bool VorbisInputStream::eosIntern() const {
-	if (_eofFlag)
-		return true;
-	if (_pos < _bufferEnd)
-		return false;
-	return (_end_pos <= ov_pcm_tell(_ov_file));
+	return _pos >= _bufferEnd;
 }
 
 int VorbisInputStream::readBuffer(int16 *buffer, const int numSamples) {
 	int samples = 0;
 	while (samples < numSamples && !eosIntern()) {
-		if (_pos >= _bufferEnd) {
-			refill();
-		}
 		const int len = MIN(numSamples, samples + (int)(_bufferEnd - _pos));
 		memcpy(buffer, _pos, len * 2);
 		buffer += len;
 		_pos += len;
 		samples += len;
+		if (_pos >= _bufferEnd) {
+			refill();
+		}
 	}
 	return samples;
 }
@@ -532,7 +533,7 @@
 	uint len_left = sizeof(_buffer);
 	char *read_pos = (char *)_buffer;
 
-	while (len_left > 0) {
+	while (len_left > 0 && _end_pos > ov_pcm_tell(_ov_file)) {
 		long result = ov_read(_ov_file, read_pos, len_left,
 #ifndef VORBIS_TREMOR
 #ifdef SCUMM_BIG_ENDIAN
@@ -544,18 +545,14 @@
 				      1,	// signed
 #endif
 					  NULL);
-		if (result == 0) {
-			_eofFlag = true;
-			memset(read_pos, 0, len_left);
-			break;
-		} else if (result == OV_HOLE) {
+		if (result == OV_HOLE) {
 			// Possibly recoverable, just warn about it
 			warning("Corrupted data in Vorbis file");
-		} else if (result < 0) {
-			debug(1, "Decode error %d in Vorbis file", result);
+		} else if (result <= 0) {
+			if (result < 0)
+				debug(1, "Decode error %d in Vorbis file", result);
 			// Don't delete it yet, that causes problems in
 			// the CD player emulation code.
-			_eofFlag = true;
 			memset(read_pos, 0, len_left);
 			break;
 		} else {
@@ -565,6 +562,7 @@
 	}
 
 	_pos = _buffer;
+	_bufferEnd = (int16 *)read_pos;
 }
 
 MusicStream *makeVorbisStream(OggVorbis_File *file, int duration) {
@@ -594,7 +592,6 @@
 	}
 }
 
-
 template<bool stereo>
 static WrappedAudioInputStream *makeWrappedInputStream(uint32 len, bool is16Bit, bool isUnsigned) {
 	if (isUnsigned) {
@@ -609,7 +606,6 @@
 			return new WrappedMemoryStream<stereo, false, false>(len);
 	}
 }
-
 
 AudioInputStream *makeLinearInputStream(byte _flags, const byte *ptr, uint32 len, uint loopOffset, uint loopLen) {
 	const bool is16Bit = (_flags & SoundMixer::FLAG_16BITS) != 0;





More information about the Scummvm-git-logs mailing list