aboutsummaryrefslogtreecommitdiff
path: root/sound/mixer.cpp
diff options
context:
space:
mode:
authorTorbjörn Andersson2008-11-09 13:28:59 +0000
committerTorbjörn Andersson2008-11-09 13:28:59 +0000
commit2bbc958373d687ab8ced1def67d30be420dc6827 (patch)
tree2651c818b10b3d04add45e087a5948156ba9a888 /sound/mixer.cpp
parentdb3438f2c9f7cf1f745eb5f7c3b05c0399f846cf (diff)
downloadscummvm-rg350-2bbc958373d687ab8ced1def67d30be420dc6827.tar.gz
scummvm-rg350-2bbc958373d687ab8ced1def67d30be420dc6827.tar.bz2
scummvm-rg350-2bbc958373d687ab8ced1def67d30be420dc6827.zip
Made getSoundElapseTime() work better when the sound has been paused. A new
variable, _pauseTime, keeps track of how long the sound has been paused since the last mixer time stamp. svn-id: r34955
Diffstat (limited to 'sound/mixer.cpp')
-rw-r--r--sound/mixer.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index 824143d829..4826d2b044 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -56,6 +56,8 @@ private:
uint32 _samplesConsumed;
uint32 _samplesDecoded;
uint32 _mixerTimeStamp;
+ uint32 _pauseStartTime;
+ uint32 _pauseTime;
protected:
RateConverter *_converter;
@@ -80,6 +82,11 @@ public:
_pauseLevel++;
else if (_pauseLevel > 0)
_pauseLevel--;
+
+ if (_pauseLevel > 0)
+ _pauseStartTime = g_system->getMillis();
+ else
+ _pauseTime += (g_system->getMillis() - _pauseStartTime);
}
bool isPaused() {
return _pauseLevel != 0;
@@ -381,7 +388,8 @@ Channel::Channel(Mixer *mixer, Mixer::SoundType type, AudioStream *input,
bool autofreeStream, bool reverseStereo, int id, bool permanent)
: _type(type), _mixer(mixer), _autofreeStream(autofreeStream),
_volume(Mixer::kMaxChannelVolume), _balance(0), _pauseLevel(0), _id(id), _samplesConsumed(0),
- _samplesDecoded(0), _mixerTimeStamp(0), _converter(0), _input(input), _permanent(permanent) {
+ _samplesDecoded(0), _mixerTimeStamp(0), _pauseStartTime(0), _pauseTime(0), _converter(0),
+ _input(input), _permanent(permanent) {
assert(mixer);
assert(input);
@@ -431,6 +439,7 @@ void Channel::mix(int16 *data, uint len) {
_samplesConsumed = _samplesDecoded;
_mixerTimeStamp = g_system->getMillis();
+ _pauseTime = 0;
_converter->flow(*_input, data, len, vol_l, vol_r);
@@ -450,7 +459,7 @@ uint32 Channel::getElapsedTime() {
uint32 seconds = _samplesConsumed / rate;
uint32 milliseconds = (1000 * (_samplesConsumed % rate)) / rate;
- uint32 delta = g_system->getMillis() - _mixerTimeStamp;
+ uint32 delta = g_system->getMillis() - _mixerTimeStamp - _pauseTime;
// In theory it would seem like a good idea to limit the approximation
// so that it never exceeds the theoretical upper bound set by