aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2010-01-01 16:28:22 +0000
committerEugene Sandulenko2010-01-01 16:28:22 +0000
commit622dd0d16dbf735323a6fae985f0231a4ef5d393 (patch)
tree6b14067f8c501153e9b378a104ffcc91ff29647c
parentd1b844d3c36b9011442d3a6538bc35878b3b694e (diff)
downloadscummvm-rg350-622dd0d16dbf735323a6fae985f0231a4ef5d393.tar.gz
scummvm-rg350-622dd0d16dbf735323a6fae985f0231a4ef5d393.tar.bz2
scummvm-rg350-622dd0d16dbf735323a6fae985f0231a4ef5d393.zip
Implemented setNumLoops() for common audio streams.
Implemented getNumPlayedLoops() for common audio streams. Requested by m_kriewitz. svn-id: r46836
-rw-r--r--sound/audiostream.cpp18
-rw-r--r--sound/audiostream.h8
-rw-r--r--sound/flac.cpp10
-rw-r--r--sound/mp3.cpp9
-rw-r--r--sound/vorbis.cpp9
5 files changed, 48 insertions, 6 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index f2bd30b904..2915b38eec 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -130,6 +130,9 @@ protected:
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 @@ public:
int32 getTotalPlayTime() const { return _playtime; }
void setNumLoops(uint numLoops) {
+ _numLoops = numLoops;
+
if (numLoops == 1) {
_loopPtr = 0;
_loopEnd = 0;
@@ -161,6 +166,8 @@ public:
_loopEnd = _end;
}
}
+
+ uint getNumPlayedLoops() { return _numPlayedLoops; }
};
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
@@ -177,6 +184,8 @@ int LinearMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buf
if (_loopPtr && _ptr >= _end) {
_ptr = _loopPtr;
_end = _loopEnd;
+
+ _numPlayedLoops++;
}
}
return numSamples-samples;
@@ -205,6 +214,9 @@ class LinearDiskStream : public AudioStream {
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 @@ protected:
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 @@ int LinearDiskStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffe
_currentBlock = 0;
_filePos = _audioBlock[_currentBlock].pos + _beginLoop;
_diskLeft = _audioBlock[_currentBlock].len;
+
+ _numPlayedLoops++;
}
}
diff --git a/sound/audiostream.h b/sound/audiostream.h
index 5f3091292d..b0f49caaea 100644
--- a/sound/audiostream.h
+++ b/sound/audiostream.h
@@ -106,7 +106,13 @@ public:
* 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.
diff --git a/sound/flac.cpp b/sound/flac.cpp
index bb633b8352..8fc7440ff5 100644
--- a/sound/flac.cpp
+++ b/sound/flac.cpp
@@ -87,8 +87,6 @@ protected:
Common::SeekableReadStream *_inStream;
bool _disposeAfterUse;
- uint _numLoops;
-
::FLAC__SeekableStreamDecoder *_decoder;
/** Header of the stream */
@@ -103,6 +101,9 @@ protected:
/** 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 @@ public:
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 @@ FlacInputStream::FlacInputStream(Common::SeekableReadStream *inStream, bool disp
_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 @@ int FlacInputStream::readBuffer(int16 *buffer, const int numSamples) {
if (_lastSampleWritten && _numLoops != 1) {
if (_numLoops != 0)
_numLoops--;
+ _numPlayedLoops++;
seekAbsolute(_firstSample);
state = getStreamDecoderState();
}
diff --git a/sound/mp3.cpp b/sound/mp3.cpp
index c9cc5d33e7..02c6634999 100644
--- a/sound/mp3.cpp
+++ b/sound/mp3.cpp
@@ -56,7 +56,6 @@ protected:
Common::SeekableReadStream *_inStream;
bool _disposeAfterUse;
- uint _numLoops;
uint _posInFrame;
State _state;
@@ -66,6 +65,9 @@ protected:
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 @@ public:
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 @@ void MP3InputStream::decodeMP3Data() {
if (_numLoops != 0)
_numLoops--;
+ _numPlayedLoops++;
+
// Deinit MAD
mad_synth_finish(&_synth);
mad_frame_finish(&_frame);
diff --git a/sound/vorbis.cpp b/sound/vorbis.cpp
index cd5f77a8fd..1d265e6025 100644
--- a/sound/vorbis.cpp
+++ b/sound/vorbis.cpp
@@ -92,9 +92,11 @@ protected:
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 @@ public:
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 @@ int VorbisInputStream::readBuffer(int16 *buffer, const int numSamples) {
if (_numLoops != 0)
_numLoops--;
+ _numPlayedLoops++;
+
res = ov_time_seek(&_ovFile, _startTime);
if (res < 0) {
warning("Error seeking in Vorbis stream (%d)", res);