diff options
| author | Max Horn | 2010-01-09 22:37:10 +0000 | 
|---|---|---|
| committer | Max Horn | 2010-01-09 22:37:10 +0000 | 
| commit | a44c6e43233ffd4b89fb6a6a96e156cd43412c3d (patch) | |
| tree | 4c0ee8aa9344980aca973eb1b18edfaa8350afc5 | |
| parent | 4a832ceb0179d280a5baca9db462cf9124d088e2 (diff) | |
| download | scummvm-rg350-a44c6e43233ffd4b89fb6a6a96e156cd43412c3d.tar.gz scummvm-rg350-a44c6e43233ffd4b89fb6a6a96e156cd43412c3d.tar.bz2 scummvm-rg350-a44c6e43233ffd4b89fb6a6a96e156cd43412c3d.zip | |
Add Mixer::getElapsedTime() method returning a Timestamp, thus offering a higher precision than Mixer::getSoundElapsedTime(). Convert some video code to use it.
svn-id: r47213
| -rw-r--r-- | engines/sword1/animation.cpp | 3 | ||||
| -rw-r--r-- | engines/sword2/animation.cpp | 3 | ||||
| -rw-r--r-- | graphics/video/avi_decoder.cpp | 6 | ||||
| -rw-r--r-- | graphics/video/smk_decoder.cpp | 6 | ||||
| -rw-r--r-- | sound/mixer.cpp | 25 | ||||
| -rw-r--r-- | sound/mixer.h | 5 | ||||
| -rw-r--r-- | sound/mixer_intern.h | 1 | 
7 files changed, 32 insertions, 17 deletions
| diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp index 706bee4b92..b3c90e3204 100644 --- a/engines/sword1/animation.cpp +++ b/engines/sword1/animation.cpp @@ -259,7 +259,8 @@ int32 DXADecoderWithSound::getAudioLag() {  	int32 videoTime = _videoInfo.currentFrame * frameDelay;  	int32 audioTime; -	audioTime = (((int32) _mixer->getSoundElapsedTime(*_bgSoundHandle)) * 100); +	const Audio::Timestamp ts = _mixer->getElapsedTime(*_bgSoundHandle); +	audioTime = ts.convertToFramerate(100000).totalNumberOfFrames();  	return videoTime - audioTime;  } diff --git a/engines/sword2/animation.cpp b/engines/sword2/animation.cpp index 2c4b9e0d98..3429ab8683 100644 --- a/engines/sword2/animation.cpp +++ b/engines/sword2/animation.cpp @@ -287,7 +287,8 @@ int32 DXADecoderWithSound::getAudioLag() {  	int32 videoTime = _videoInfo.currentFrame * frameDelay;  	int32 audioTime; -	audioTime = (((int32) _mixer->getSoundElapsedTime(*_bgSoundHandle)) * 100); +	const Audio::Timestamp ts = _mixer->getElapsedTime(*_bgSoundHandle); +	audioTime = ts.convertToFramerate(100000).totalNumberOfFrames();  	return videoTime - audioTime;  } diff --git a/graphics/video/avi_decoder.cpp b/graphics/video/avi_decoder.cpp index 7416d86310..f54de46731 100644 --- a/graphics/video/avi_decoder.cpp +++ b/graphics/video/avi_decoder.cpp @@ -412,8 +412,10 @@ int32 AviDecoder::getAudioLag() {  		*/  		audioTime = (g_system->getMillis() - _videoInfo.startTime) * 100; -	} else -		audioTime = (((int32)_mixer->getSoundElapsedTime(*_audHandle)) * 100); +	} else { +		const Audio::Timestamp ts = _mixer->getElapsedTime(*_audHandle); +		audioTime = ts.convertToFramerate(100000).totalNumberOfFrames(); +	}  	return videoTime - audioTime;  } diff --git a/graphics/video/smk_decoder.cpp b/graphics/video/smk_decoder.cpp index 1a313b9f2e..a3b056b6a3 100644 --- a/graphics/video/smk_decoder.cpp +++ b/graphics/video/smk_decoder.cpp @@ -377,8 +377,10 @@ int32 SmackerDecoder::getAudioLag() {  		*/  		audioTime = (g_system->getMillis() - _videoInfo.startTime) * 100; -	} else -		audioTime = (((int32) _mixer->getSoundElapsedTime(_audioHandle)) * 100); +	} else { +		const Audio::Timestamp ts = _mixer->getElapsedTime(_audioHandle); +		audioTime = ts.convertToFramerate(100000).totalNumberOfFrames(); +	}  	return videoTime - audioTime;  } diff --git a/sound/mixer.cpp b/sound/mixer.cpp index b27bf87c89..7a09715c62 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -108,10 +108,9 @@ public:  	void notifyGlobalVolChange() { updateChannelVolumes(); }  	/** -	 * Queries how many milliseconds the channel has -	 * been playing. +	 * Queries how long the channel has been playing.  	 */ -	uint32 getElapsedTime(); +	Timestamp getElapsedTime();  	/**  	 * Queries the channel's sound type. @@ -342,11 +341,15 @@ void MixerImpl::setChannelBalance(SoundHandle handle, int8 balance) {  }  uint32 MixerImpl::getSoundElapsedTime(SoundHandle handle) { +	return getElapsedTime(handle).msecs(); +} + +Timestamp MixerImpl::getElapsedTime(SoundHandle handle) {  	Common::StackLock lock(_mutex);  	const int index = handle._val % NUM_CHANNELS;  	if (!_channels[index] || _channels[index]->getHandle()._val != handle._val) -		return 0; +		return Timestamp(0, _sampleRate);  	return _channels[index]->getElapsedTime();  } @@ -513,13 +516,15 @@ void Channel::pause(bool paused) {  	}  } -uint32 Channel::getElapsedTime() { -	if (_mixerTimeStamp == 0) -		return 0; - +Timestamp Channel::getElapsedTime() {  	const uint32 rate = _mixer->getOutputRate();  	uint32 delta = 0; +	Audio::Timestamp ts(0, rate); + +	if (_mixerTimeStamp == 0) +		return ts; +  	if (isPaused())  		delta = _pauseStartTime - _mixerTimeStamp;  	else @@ -527,8 +532,6 @@ uint32 Channel::getElapsedTime() {  	// Convert the number of samples into a time duration. -	Audio::Timestamp ts(0, rate); -  	ts = ts.addFrames(_samplesConsumed);  	ts = ts.addMsecs(delta); @@ -538,7 +541,7 @@ uint32 Channel::getElapsedTime() {  	// the Broken Sword cutscenes noticeably jerkier. I guess the mixer  	// isn't invoked at the regular intervals that I first imagined. -	return ts.msecs(); +	return ts;  }  void Channel::mix(int16 *data, uint len) { diff --git a/sound/mixer.h b/sound/mixer.h index 97daa839f1..b13e8606e9 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -266,6 +266,11 @@ public:  	virtual uint32 getSoundElapsedTime(SoundHandle handle) = 0;  	/** +	 * Get approximation of for how long the channel has been playing. +	 */ +	virtual Timestamp getElapsedTime(SoundHandle handle) = 0; + +	/**  	 * Check whether any channel of the given sound type is active.  	 * For example, this can be used to check whether any SFX sound  	 * is currently playing, by checking for type kSFXSoundType. diff --git a/sound/mixer_intern.h b/sound/mixer_intern.h index be47f0c163..b206396bf8 100644 --- a/sound/mixer_intern.h +++ b/sound/mixer_intern.h @@ -107,6 +107,7 @@ public:  	virtual void setChannelBalance(SoundHandle handle, int8 balance);  	virtual uint32 getSoundElapsedTime(SoundHandle handle); +	virtual Timestamp getElapsedTime(SoundHandle handle);  	virtual bool hasActiveChannelOfType(SoundType type); | 
