aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sound/flac.cpp6
-rw-r--r--sound/mp3.cpp24
-rw-r--r--sound/vorbis.cpp10
3 files changed, 16 insertions, 24 deletions
diff --git a/sound/flac.cpp b/sound/flac.cpp
index d06402e192..8699e8cfce 100644
--- a/sound/flac.cpp
+++ b/sound/flac.cpp
@@ -379,13 +379,11 @@ int FlacInputStream::readBuffer(int16 *buffer, const int numSamples) {
if (state == FLAC__STREAM_DECODER_END_OF_STREAM) {
_lastSampleWritten = true;
+ ++_numPlayedLoops;
}
// If we reached the end of the stream, and looping is enabled: Try to rewind
- if (_lastSampleWritten && _numLoops != 1) {
- if (_numLoops != 0)
- _numLoops--;
- _numPlayedLoops++;
+ if (_lastSampleWritten && (!_numLoops || _numPlayedLoops < _numLoops)) {
seekAbsolute(_firstSample);
state = getStreamDecoderState();
}
diff --git a/sound/mp3.cpp b/sound/mp3.cpp
index 4ed68a3586..fede2a32cb 100644
--- a/sound/mp3.cpp
+++ b/sound/mp3.cpp
@@ -290,20 +290,18 @@ void MP3InputStream::decodeMP3Data() {
break;
}
- if (_state == MP3_STATE_EOS && _numLoops != 1) {
+ if (_state == MP3_STATE_EOS) {
+ ++_numPlayedLoops;
// If looping is on and there are loops left, rewind to the start
- if (_numLoops != 0)
- _numLoops--;
-
- _numPlayedLoops++;
-
- // Deinit MAD
- mad_synth_finish(&_synth);
- mad_frame_finish(&_frame);
- mad_stream_finish(&_stream);
-
- // Reset the decoder state to indicate we should start over
- _state = MP3_STATE_INIT;
+ if (!_numLoops || _numPlayedLoops < _numLoops) {
+ // Deinit MAD
+ mad_synth_finish(&_synth);
+ mad_frame_finish(&_frame);
+ mad_stream_finish(&_stream);
+
+ // Reset the decoder state to indicate we should start over
+ _state = MP3_STATE_INIT;
+ }
}
} while (_state != MP3_STATE_EOS && _stream.error == MAD_ERROR_BUFLEN);
diff --git a/sound/vorbis.cpp b/sound/vorbis.cpp
index 8e0cda06c9..bb73a26d06 100644
--- a/sound/vorbis.cpp
+++ b/sound/vorbis.cpp
@@ -221,13 +221,9 @@ int VorbisInputStream::readBuffer(int16 *buffer, const int numSamples) {
// If we are still out of data, and also past the end of specified
// time range, check whether looping is enabled...
if (_pos >= _bufferEnd && ov_time_tell(&_ovFile) >= _endTime) {
- if (_numLoops != 1) {
- // If looping is on and there are loops left, rewind to the start
- if (_numLoops != 0)
- _numLoops--;
-
- _numPlayedLoops++;
-
+ ++_numPlayedLoops;
+ // If looping is on and there are loops left, rewind to the start
+ if (!_numLoops || _numPlayedLoops < _numLoops) {
res = ov_time_seek(&_ovFile, _startTime);
if (res < 0) {
warning("Error seeking in Vorbis stream (%d)", res);