[Scummvm-git-logs] scummvm master -> 0263447aa1fac9de5cb276bdf7e29d733f308fa6
fracturehill
noreply at scummvm.org
Wed Aug 16 17:43:29 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
0263447aa1 AUDIO: Drain leftover RateConverter buffer data
Commit: 0263447aa1fac9de5cb276bdf7e29d733f308fa6
https://github.com/scummvm/scummvm/commit/0263447aa1fac9de5cb276bdf7e29d733f308fa6
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2023-08-16T20:41:58+03:00
Commit Message:
AUDIO: Drain leftover RateConverter buffer data
This commit fixes an issue where RateConverter would
sometimes chop off the very end of an audio stream. This
happened when the RateConverter would have some
data left in its internal buffer, but the source stream was
already fully read. The base RateConverter class now has
a needsDraining() function which indicates leftover data,
and relevant code now uses it when needed.
Changed paths:
audio/mixer.cpp
audio/rate.cpp
audio/rate.h
diff --git a/audio/mixer.cpp b/audio/mixer.cpp
index 87a778967c8..ec3ffeeac2d 100644
--- a/audio/mixer.cpp
+++ b/audio/mixer.cpp
@@ -59,7 +59,7 @@ public:
/**
* Queries whether the channel is still playing or not.
*/
- bool isFinished() const { return _stream->endOfStream(); }
+ bool isFinished() const { return _stream->endOfStream() && !_converter->needsDraining(); }
/**
* Queries whether the channel is a permanent channel.
@@ -709,12 +709,10 @@ void Channel::loop() {
int Channel::mix(int16 *data, uint len) {
assert(_stream);
+ assert(_converter);
int res = 0;
- if (_stream->endOfData()) {
- // TODO: call drain method
- } else {
- assert(_converter);
+ if (!_stream->endOfData() || _converter->needsDraining()) {
_samplesConsumed = _samplesDecoded;
_mixerTimeStamp = g_system->getMillis(true);
_pauseTime = 0;
diff --git a/audio/rate.cpp b/audio/rate.cpp
index 6c38fc74ab0..a9770977162 100644
--- a/audio/rate.cpp
+++ b/audio/rate.cpp
@@ -91,6 +91,8 @@ public:
st_rate_t getInputRate() const override { return _inRate; }
st_rate_t getOutputRate() const override { return _outRate; }
+
+ bool needsDraining() const override { return _bufferSize != 0; }
};
template<bool inStereo, bool outStereo, bool reverseStereo>
diff --git a/audio/rate.h b/audio/rate.h
index 6a70da25cfd..7b0658c893b 100644
--- a/audio/rate.h
+++ b/audio/rate.h
@@ -95,6 +95,13 @@ public:
virtual st_rate_t getInputRate() const = 0;
virtual st_rate_t getOutputRate() const = 0;
+
+ /**
+ * Does the internal buffer still have some leftover data?
+ *
+ * @return True if we need to drain, false otherwise
+ */
+ virtual bool needsDraining() const = 0;
};
RateConverter *makeRateConverter(st_rate_t inRate, st_rate_t outRate, bool inStereo, bool outStereo, bool reverseStereo);
More information about the Scummvm-git-logs
mailing list