aboutsummaryrefslogtreecommitdiff
path: root/audio
diff options
context:
space:
mode:
authordhewg2011-02-16 19:59:15 +0100
committerdhewg2011-02-27 09:04:36 +0100
commitbea57f695064c6f084ff26405d91b812848fee33 (patch)
treefbe032523835b05c2de6e4fd0ef504cff7b04af1 /audio
parent25d895b859af0df8ea6daa85ba6ec5a0acb81f9d (diff)
downloadscummvm-rg350-bea57f695064c6f084ff26405d91b812848fee33.tar.gz
scummvm-rg350-bea57f695064c6f084ff26405d91b812848fee33.tar.bz2
scummvm-rg350-bea57f695064c6f084ff26405d91b812848fee33.zip
AUDIO: Make mixCallback return the sample count
The RateConverter::flow result was never used, pipe it through Channel::mix to MixerImpl::mixCallback, so backends can decide if they want to waste cpu cycles while playing empty buffers.
Diffstat (limited to 'audio')
-rw-r--r--audio/mixer.cpp26
-rw-r--r--audio/mixer_intern.h4
2 files changed, 22 insertions, 8 deletions
diff --git a/audio/mixer.cpp b/audio/mixer.cpp
index c2271b1059..dc0287e3fb 100644
--- a/audio/mixer.cpp
+++ b/audio/mixer.cpp
@@ -54,8 +54,9 @@ public:
* @param len number of sample *pairs*. So a value of
* 10 means that the buffer contains twice 10 sample, each
* 16 bits, for a total of 40 bytes.
+ * @return number of sample pairs processed (which can still be silence!)
*/
- void mix(int16 *data, uint len);
+ int mix(int16 *data, uint len);
/**
* Queries whether the channel is still playing or not.
@@ -257,7 +258,7 @@ void MixerImpl::playStream(
insertChannel(handle, chan);
}
-void MixerImpl::mixCallback(byte *samples, uint len) {
+int MixerImpl::mixCallback(byte *samples, uint len) {
assert(samples);
Common::StackLock lock(_mutex);
@@ -272,14 +273,21 @@ void MixerImpl::mixCallback(byte *samples, uint len) {
memset(buf, 0, 2 * len * sizeof(int16));
// mix all channels
+ int res = 0, tmp;
for (int i = 0; i != NUM_CHANNELS; i++)
if (_channels[i]) {
if (_channels[i]->isFinished()) {
delete _channels[i];
_channels[i] = 0;
- } else if (!_channels[i]->isPaused())
- _channels[i]->mix(buf, len);
+ } else if (!_channels[i]->isPaused()) {
+ tmp = _channels[i]->mix(buf, len);
+
+ if (tmp > res)
+ res = tmp;
+ }
}
+
+ return res;
}
void MixerImpl::stopAll() {
@@ -538,19 +546,23 @@ Timestamp Channel::getElapsedTime() {
return ts;
}
-void Channel::mix(int16 *data, uint len) {
+int Channel::mix(int16 *data, uint len) {
assert(_stream);
+ int res = 0;
+
if (_stream->endOfData()) {
// TODO: call drain method
} else {
assert(_converter);
-
_samplesConsumed = _samplesDecoded;
_mixerTimeStamp = g_system->getMillis();
_pauseTime = 0;
- _samplesDecoded += _converter->flow(*_stream, data, len, _volL, _volR);
+ res = _converter->flow(*_stream, data, len, _volL, _volR);
+ _samplesDecoded += res;
}
+
+ return res;
}
} // End of namespace Audio
diff --git a/audio/mixer_intern.h b/audio/mixer_intern.h
index c8df9a594d..dd2746e9ea 100644
--- a/audio/mixer_intern.h
+++ b/audio/mixer_intern.h
@@ -118,8 +118,10 @@ public:
* The mixer callback function, to be called at regular intervals by
* the backend (e.g. from an audio mixing thread). All the actual mixing
* work is done from here.
+ *
+ * @return number of sample pairs processed (which can still be silence!)
*/
- void mixCallback(byte *samples, uint len);
+ int mixCallback(byte *samples, uint len);
/**
* Set the internal 'is ready' flag of the mixer.