diff options
Diffstat (limited to 'sound/audiostream.cpp')
-rw-r--r-- | sound/audiostream.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 57d2e097bf..783a5733b3 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -211,14 +211,14 @@ protected: int _audioBlockCount; ///< Number of blocks in _audioBlock int _currentBlock; ///< Current audio block number - int _beginLoop; ///< Loop parameter, currently not implemented - int _endLoop; ///< Loop parameter, currently not implemented - + 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 public: - LinearDiskStream(int rate, uint beginLoop, uint endLoop, bool disposeStream, Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block, uint numBlocks) + 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) { + _audioBlockCount(numBlocks), _loop(loop) { // Allocate streaming buffer if (is16Bit) { @@ -296,7 +296,6 @@ int LinearDiskStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffe _diskLeft = _audioBlock[_currentBlock].len; } - // Now read more data from disk if there is more to be read if ((_bufferLeft == 0) && (_diskLeft > 0)) { int32 readAmount = MIN(_diskLeft, BUFFER_SIZE); @@ -315,6 +314,14 @@ int LinearDiskStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffe // original position. restoreFilePosition = true; } + + // Looping + if (_diskLeft == 0 && _loop) { + // Reset the stream + _currentBlock = 0; + _filePos = _audioBlock[_currentBlock].pos + _beginLoop; + _diskLeft = _audioBlock[_currentBlock].len; + } } // In case calling code relies on the position of this stream staying @@ -399,19 +406,19 @@ AudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte f #define MAKE_LINEAR_DISK(STEREO, UNSIGNED) \ if (is16Bit) { \ if (isLE) \ - return new LinearDiskStream<STEREO, true, UNSIGNED, true>(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks); \ + return new LinearDiskStream<STEREO, true, UNSIGNED, true>(rate, loopStart, loopEnd, takeOwnership, stream, block, numBlocks, loop); \ else \ - return new LinearDiskStream<STEREO, true, UNSIGNED, false>(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks); \ + return new LinearDiskStream<STEREO, true, UNSIGNED, false>(rate, loopStart, loopEnd, takeOwnership, stream, block, numBlocks, loop); \ } else \ - return new LinearDiskStream<STEREO, false, UNSIGNED, false>(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks) + return new LinearDiskStream<STEREO, false, UNSIGNED, false>(rate, loopStart, loopEnd, takeOwnership, stream, block, numBlocks, loop) -AudioStream *makeLinearDiskStream(Common::SeekableReadStream& stream, LinearDiskStreamAudioBlock* block, int numBlocks, int rate, byte flags, bool takeOwnership, uint loopStart, uint loopEnd) { +AudioStream *makeLinearDiskStream(Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block, int numBlocks, int rate, byte flags, bool takeOwnership, uint loopStart, uint loopEnd) { const bool isStereo = (flags & Audio::Mixer::FLAG_STEREO) != 0; const bool is16Bit = (flags & Audio::Mixer::FLAG_16BITS) != 0; const bool isUnsigned = (flags & Audio::Mixer::FLAG_UNSIGNED) != 0; const bool isLE = (flags & Audio::Mixer::FLAG_LITTLE_ENDIAN) != 0; - + const bool loop = (flags & Audio::Mixer::FLAG_LOOP) != 0; if (isStereo) { if (isUnsigned) { |