[Scummvm-cvs-logs] SF.net SVN: scummvm:[46836] scummvm/trunk/sound

sev at users.sourceforge.net sev at users.sourceforge.net
Fri Jan 1 17:28:22 CET 2010


Revision: 46836
          http://scummvm.svn.sourceforge.net/scummvm/?rev=46836&view=rev
Author:   sev
Date:     2010-01-01 16:28:22 +0000 (Fri, 01 Jan 2010)

Log Message:
-----------
Implemented setNumLoops() for common audio streams.
Implemented getNumPlayedLoops() for common audio streams.

Requested by m_kriewitz.

Modified Paths:
--------------
    scummvm/trunk/sound/audiostream.cpp
    scummvm/trunk/sound/audiostream.h
    scummvm/trunk/sound/flac.cpp
    scummvm/trunk/sound/mp3.cpp
    scummvm/trunk/sound/vorbis.cpp

Modified: scummvm/trunk/sound/audiostream.cpp
===================================================================
--- scummvm/trunk/sound/audiostream.cpp	2010-01-01 16:15:20 UTC (rev 46835)
+++ scummvm/trunk/sound/audiostream.cpp	2010-01-01 16:28:22 UTC (rev 46836)
@@ -130,6 +130,9 @@
 	const byte *_origPtr;
 	const int32 _playtime;
 
+	uint _numLoops;			///< Number of loops to play
+	uint _numPlayedLoops;	///< Number of loops which have been played
+
 public:
 	LinearMemoryStream(int rate, const byte *ptr, uint len, uint loopOffset, uint loopLen, bool autoFreeMemory)
 		: _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate), _playtime(calculatePlayTime(rate, len / (is16Bit ? 2 : 1) / (stereo ? 2 : 1))) {
@@ -153,6 +156,8 @@
 	int32 getTotalPlayTime() const	{ return _playtime; }
 
 	void setNumLoops(uint numLoops) {
+		_numLoops = numLoops;
+
 		if (numLoops == 1) {
 			_loopPtr = 0;
 			_loopEnd = 0;
@@ -161,6 +166,8 @@
 			_loopEnd = _end;
 		}
 	}
+
+	uint getNumPlayedLoops() { return _numPlayedLoops; }
 };
 
 template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
@@ -177,6 +184,8 @@
 		if (_loopPtr && _ptr >= _end) {
 			_ptr = _loopPtr;
 			_end = _loopEnd;
+
+			_numPlayedLoops++;
 		}
 	}
 	return numSamples-samples;
@@ -205,6 +214,9 @@
 	static const int32 BUFFER_SIZE = 16384;
 #endif
 
+	void setNumLoops(uint numLoops = 1) { _numLoops = numLoops; }
+	uint getNumPlayedLoops() { return _numPlayedLoops; }
+
 protected:
 	byte* _buffer;			///< Streaming buffer
 	const byte *_ptr;		///< Pointer to current position in stream buffer
@@ -224,11 +236,13 @@
 	int _beginLoop;			///< Loop start parameter
 	int _endLoop;			///< Loop end parameter, currently not implemented
 	bool _loop;				///< Determines if the stream should be looped when it finishes
+	uint _numLoops;			///< Number of loops to play
+	uint _numPlayedLoops;	///< Number of loops which have been played
 
 public:
 	LinearDiskStream(int rate, uint beginLoop, uint endLoop, bool disposeStream, Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block, uint numBlocks, bool loop)
 		: _rate(rate), _stream(stream), _beginLoop(beginLoop), _endLoop(endLoop), _disposeAfterUse(disposeStream),
-		  _audioBlockCount(numBlocks), _loop(loop) {
+		  _audioBlockCount(numBlocks), _loop(loop), _numPlayedLoops(0) {
 
 		assert(numBlocks > 0);
 
@@ -333,6 +347,8 @@
 			_currentBlock = 0;
 			_filePos = _audioBlock[_currentBlock].pos + _beginLoop;
 			_diskLeft = _audioBlock[_currentBlock].len;
+
+			_numPlayedLoops++;
 		}
 	}
 

Modified: scummvm/trunk/sound/audiostream.h
===================================================================
--- scummvm/trunk/sound/audiostream.h	2010-01-01 16:15:20 UTC (rev 46835)
+++ scummvm/trunk/sound/audiostream.h	2010-01-01 16:28:22 UTC (rev 46836)
@@ -106,8 +106,14 @@
 	 * Sets number of times the stream is supposed to get looped
 	 * @param numLoops number of loops to play, 0 - infinite
 	 */
-	virtual void setNumLoops(uint numLoops = 1) {};
+	virtual void setNumLoops(uint numLoops = 1) {}
 
+	/** 
+	 * Returns number of loops the stream has played.
+	 * @param numLoops number of loops to play, 0 - infinite
+	 */
+	virtual uint getNumPlayedLoops() { return 0; }
+
 	/**
 	 * Returns total playtime of the AudioStream object.
 	 * Note that this does not require to return an playtime, if the

Modified: scummvm/trunk/sound/flac.cpp
===================================================================
--- scummvm/trunk/sound/flac.cpp	2010-01-01 16:15:20 UTC (rev 46835)
+++ scummvm/trunk/sound/flac.cpp	2010-01-01 16:28:22 UTC (rev 46836)
@@ -87,8 +87,6 @@
 	Common::SeekableReadStream *_inStream;
 	bool _disposeAfterUse;
 
-	uint _numLoops;
-
 	::FLAC__SeekableStreamDecoder *_decoder;
 
 	/** Header of the stream */
@@ -103,6 +101,9 @@
 	/** total play time */
 	int32 _totalPlayTime;
 
+	uint _numLoops;			///< Number of loops to play
+	uint _numPlayedLoops;	///< Number of loops which have been played
+
 	/** true if the last sample was decoded from the FLAC-API - there might still be data in the buffer */
 	bool _lastSampleWritten;
 
@@ -146,6 +147,9 @@
 
 	bool isStreamDecoderReady() const { return getStreamDecoderState() == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC ; }
 
+	void setNumLoops(uint numLoops = 1) { _numLoops = numLoops; }
+	uint getNumPlayedLoops() { return _numPlayedLoops; }
+
 protected:
 	uint getChannels() const { return MIN<uint>(_streaminfo.channels, MAX_OUTPUT_CHANNELS); }
 
@@ -193,6 +197,7 @@
 		_inStream(inStream),
 		_disposeAfterUse(dispose),
 		_numLoops(numLoops),
+		_numPlayedLoops(0),
 		_firstSample(0), _lastSample(0),
 		_outBuffer(NULL), _requestedSamples(0), _lastSampleWritten(false),
 		_methodConvertBuffers(&FlacInputStream::convertBuffersGeneric)
@@ -373,6 +378,7 @@
 		if (_lastSampleWritten && _numLoops != 1) {
 			if (_numLoops != 0)
 				_numLoops--;
+			_numPlayedLoops++;
 			seekAbsolute(_firstSample);
 			state = getStreamDecoderState();
 		}

Modified: scummvm/trunk/sound/mp3.cpp
===================================================================
--- scummvm/trunk/sound/mp3.cpp	2010-01-01 16:15:20 UTC (rev 46835)
+++ scummvm/trunk/sound/mp3.cpp	2010-01-01 16:28:22 UTC (rev 46836)
@@ -56,7 +56,6 @@
 	Common::SeekableReadStream *_inStream;
 	bool _disposeAfterUse;
 
-	uint _numLoops;
 	uint _posInFrame;
 	State _state;
 
@@ -66,6 +65,9 @@
 
 	int32 _totalPlayTime;
 
+	uint _numLoops;			///< Number of loops to play
+	uint _numPlayedLoops;	///< Number of loops which have been played
+
 	mad_stream _stream;
 	mad_frame _frame;
 	mad_synth _synth;
@@ -92,6 +94,9 @@
 	int getRate() const			{ return _frame.header.samplerate; }
 	int32 getTotalPlayTime() const { return _totalPlayTime; }
 
+	void setNumLoops(uint numLoops = 1) { _numLoops = numLoops; }
+	uint getNumPlayedLoops() { return _numPlayedLoops; }
+
 protected:
 	void decodeMP3Data();
 	void readMP3Data();
@@ -285,6 +290,8 @@
 			if (_numLoops != 0)
 				_numLoops--;
 
+			_numPlayedLoops++;
+
 			// Deinit MAD
 			mad_synth_finish(&_synth);
 			mad_frame_finish(&_frame);

Modified: scummvm/trunk/sound/vorbis.cpp
===================================================================
--- scummvm/trunk/sound/vorbis.cpp	2010-01-01 16:15:20 UTC (rev 46835)
+++ scummvm/trunk/sound/vorbis.cpp	2010-01-01 16:28:22 UTC (rev 46836)
@@ -92,9 +92,11 @@
 
 	bool _isStereo;
 	int _rate;
-	uint _numLoops;
 	const uint _totalNumLoops;
 
+	uint _numLoops;			///< Number of loops to play
+	uint _numPlayedLoops;	///< Number of loops which have been played
+
 #ifdef USE_TREMOR
 	ogg_int64_t _startTime;
 	ogg_int64_t _endTime;
@@ -120,6 +122,9 @@
 	bool isStereo() const		{ return _isStereo; }
 	int getRate() const			{ return _rate; }
 
+	void setNumLoops(uint numLoops = 1) { _numLoops = numLoops; }
+	uint getNumPlayedLoops() { return _numPlayedLoops; }
+
 	int32 getTotalPlayTime() const {
 		if (!_totalNumLoops)
 			return AudioStream::kUnknownPlayTime;
@@ -220,6 +225,8 @@
 					if (_numLoops != 0)
 						_numLoops--;
 
+					_numPlayedLoops++;
+
 					res = ov_time_seek(&_ovFile, _startTime);
 					if (res < 0) {
 						warning("Error seeking in Vorbis stream (%d)", res);


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