<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Swingpant&#039;s Game Lab &#187; lip synchronisation</title>
	<atom:link href="http://swingpants.com/tag/lip-synchronisation/feed/" rel="self" type="application/rss+xml" />
	<link>http://swingpants.com</link>
	<description>Swingpant&#039;s Code Nurdlings</description>
	<lastBuildDate>Wed, 08 Feb 2012 08:02:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='swingpants.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/4a88693aa17d6b5e1d453a6684bc1c68?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Swingpant&#039;s Game Lab &#187; lip synchronisation</title>
		<link>http://swingpants.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://swingpants.com/osd.xml" title="Swingpant&#039;s Game Lab" />
	<atom:link rel='hub' href='http://swingpants.com/?pushpress=hub'/>
		<item>
		<title>Keeping Lip-Sync in Sync</title>
		<link>http://swingpants.com/2009/03/02/keeping-lip-sync-in-sync/</link>
		<comments>http://swingpants.com/2009/03/02/keeping-lip-sync-in-sync/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 23:03:14 +0000</pubDate>
		<dc:creator>swingpants</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[lip synchronisation]]></category>
		<category><![CDATA[lip sync]]></category>

		<guid isPermaLink="false">http://flashlabs.wordpress.com/?p=48</guid>
		<description><![CDATA[I&#8217;m currently working on a project where I have been handed a lot of movieclips with animated mouths to be sync-ed with spoken audio triggered from the library. Each sentence had been put together in a separate movieclip. Obviously this method exposes the frame rate on slow computers leading to loss of lip-synchronisation. I was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=swingpants.com&amp;blog=5703708&amp;post=48&amp;subd=flashlabs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a project where I have been handed a lot of movieclips with animated mouths to be sync-ed with spoken audio triggered from the library. Each sentence had been put together in a separate movieclip. Obviously this method exposes the frame rate on slow computers leading to loss of lip-synchronisation. I was told to go through all of the moveiclips and add the audio to the timeline &#8211; a very inelegant solution that would take a lot of time with poor results.</p>
<p>I came up with a simple solution that basically just pushes the playhead forward everytime it drops out of sync. I use the frame rate and getTimer to work out where the playhead should be on each iteration. If the playhead drops then it is moved to the position it should be at. </p>
<p>Very simple &#8211; saved me a lot of time.</p>
<blockquote>
<p>private const FPS:int = 30//Current frame rate<br />
private const ERROR_MARGIN:int=1<br />
private var start_time:int<br />
private var last_frame:int=0//Keep track of last frame to see if mc has stopped playing<br />
private var loop_started:Boolean=false</p>
<p>public function sayPhrase(phrase:String) : void<br />
	 {<br />
		  mouth_mc.mouth.gotoAndPlay(phrase)<br />
		  last_frame=0 //reset last frame<br />
		  loop_started=false<br />
		  start_time = getTimer()<br />
		  addEventListener(Event.ENTER_FRAME,lipSyncTracking)<br />
	 }</p>
<p>private function lipSyncTracking(e:Event = null):void<br />
	 {<br />
		  if (mouth_mc.mouth)<br />
			   {<br />
				    var cframe:int = mouth_mc.mouth.currentFrame //get the current frame<br />
				    var ctime:int = getTimer() //current time<br />
				    var time_expired:Number = (ctime &#8211; start_time )<br />
				    var target_frame:int = Math.floor((FPS/1000)*time_expired)<br />
				    if(target_frame&gt;1 &amp;&amp; cframe&gt;1)loop_started=true //need to check for looping<br />
				    if (cframe == last_frame || (cframe==1 &amp;&amp; loop_started))<br />
					     {//MC must have stopped or looped back to beginning<br />
						      removeEventListener(Event.ENTER_FRAME,lipSyncTracking)<br />
					     }<br />
					     else<br />
					     {//If frame is out by the margin of error then correct<br />
					  	      if (target_frame &gt;= cframe + ERROR_MARGIN)<br />
							      {<br />
								       mouth_mc.mouth.gotoAndPlay(target_frame)<br />
							      }<br />
					     }</p>
<p>				    last_frame = cframe<br />
			   }<br />
	  }</p>
</blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/flashlabs.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/flashlabs.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/flashlabs.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/flashlabs.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/flashlabs.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/flashlabs.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/flashlabs.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/flashlabs.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/flashlabs.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/flashlabs.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/flashlabs.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/flashlabs.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/flashlabs.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/flashlabs.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=swingpants.com&amp;blog=5703708&amp;post=48&amp;subd=flashlabs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://swingpants.com/2009/03/02/keeping-lip-sync-in-sync/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cebf29489913586137c5bdad0414c88?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">swingpants</media:title>
		</media:content>
	</item>
	</channel>
</rss>
