[Scummvm-cvs-logs] SF.net SVN: scummvm:[47213] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Jan 9 23:37:10 CET 2010


Revision: 47213
          http://scummvm.svn.sourceforge.net/scummvm/?rev=47213&view=rev
Author:   fingolfin
Date:     2010-01-09 22:37:10 +0000 (Sat, 09 Jan 2010)

Log Message:
-----------
Add Mixer::getElapsedTime() method returning a Timestamp, thus offering a higher precision than Mixer::getSoundElapsedTime(). Convert some video code to use it.

Modified Paths:
--------------
    scummvm/trunk/engines/sword1/animation.cpp
    scummvm/trunk/engines/sword2/animation.cpp
    scummvm/trunk/graphics/video/avi_decoder.cpp
    scummvm/trunk/graphics/video/smk_decoder.cpp
    scummvm/trunk/sound/mixer.cpp
    scummvm/trunk/sound/mixer.h
    scummvm/trunk/sound/mixer_intern.h

Modified: scummvm/trunk/engines/sword1/animation.cpp
===================================================================
--- scummvm/trunk/engines/sword1/animation.cpp	2010-01-09 22:36:32 UTC (rev 47212)
+++ scummvm/trunk/engines/sword1/animation.cpp	2010-01-09 22:37:10 UTC (rev 47213)
@@ -259,7 +259,8 @@
 	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;
 }

Modified: scummvm/trunk/engines/sword2/animation.cpp
===================================================================
--- scummvm/trunk/engines/sword2/animation.cpp	2010-01-09 22:36:32 UTC (rev 47212)
+++ scummvm/trunk/engines/sword2/animation.cpp	2010-01-09 22:37:10 UTC (rev 47213)
@@ -287,7 +287,8 @@
 	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;
 }

Modified: scummvm/trunk/graphics/video/avi_decoder.cpp
===================================================================
--- scummvm/trunk/graphics/video/avi_decoder.cpp	2010-01-09 22:36:32 UTC (rev 47212)
+++ scummvm/trunk/graphics/video/avi_decoder.cpp	2010-01-09 22:37:10 UTC (rev 47213)
@@ -412,8 +412,10 @@
 		*/
 
 		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;
 }

Modified: scummvm/trunk/graphics/video/smk_decoder.cpp
===================================================================
--- scummvm/trunk/graphics/video/smk_decoder.cpp	2010-01-09 22:36:32 UTC (rev 47212)
+++ scummvm/trunk/graphics/video/smk_decoder.cpp	2010-01-09 22:37:10 UTC (rev 47213)
@@ -377,8 +377,10 @@
 		*/
 
 		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;
 }

Modified: scummvm/trunk/sound/mixer.cpp
===================================================================
--- scummvm/trunk/sound/mixer.cpp	2010-01-09 22:36:32 UTC (rev 47212)
+++ scummvm/trunk/sound/mixer.cpp	2010-01-09 22:37:10 UTC (rev 47213)
@@ -108,10 +108,9 @@
 	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 @@
 }
 
 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 @@
 	}
 }
 
-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 @@
 
 	// 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 @@
 	// 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) {

Modified: scummvm/trunk/sound/mixer.h
===================================================================
--- scummvm/trunk/sound/mixer.h	2010-01-09 22:36:32 UTC (rev 47212)
+++ scummvm/trunk/sound/mixer.h	2010-01-09 22:37:10 UTC (rev 47213)
@@ -266,6 +266,11 @@
 	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.

Modified: scummvm/trunk/sound/mixer_intern.h
===================================================================
--- scummvm/trunk/sound/mixer_intern.h	2010-01-09 22:36:32 UTC (rev 47212)
+++ scummvm/trunk/sound/mixer_intern.h	2010-01-09 22:37:10 UTC (rev 47213)
@@ -107,6 +107,7 @@
 	virtual void setChannelBalance(SoundHandle handle, int8 balance);
 
 	virtual uint32 getSoundElapsedTime(SoundHandle handle);
+	virtual Timestamp getElapsedTime(SoundHandle handle);
 
 	virtual bool hasActiveChannelOfType(SoundType type);
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list