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
This commit is contained in:
Torbjörn Andersson 2008-11-09 13:28:59 +00:00
parent db3438f2c9
commit 2bbc958373

View File

@ -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