mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-05 00:36:57 +00:00
Implemented setNumLoops() for common audio streams.
Implemented getNumPlayedLoops() for common audio streams. Requested by m_kriewitz. svn-id: r46836
This commit is contained in:
parent
d1b844d3c3
commit
622dd0d16d
@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user