<?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/"
	>

<channel>
	<title>RichMedia+ &#187; SampleDataEvent.SAMPLE_DATA</title>
	<atom:link href="http://blog.richmediaplus.com/tag/sampledataevent-sample_data/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.richmediaplus.com</link>
	<description>About the Adobe&#039;s RIA related solution and technology, like Adobe Air, Adobe Flex, Mobile Dev. You also can find the SEO for Flex, RIA, User Ex in this blog.</description>
	<lastBuildDate>Fri, 16 Dec 2011 09:33:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Adobe Flex 改變聲音速度例子2則比較</title>
		<link>http://blog.richmediaplus.com/2010/03/compare-with-change-adobe-flex-sound-speed-method/</link>
		<comments>http://blog.richmediaplus.com/2010/03/compare-with-change-adobe-flex-sound-speed-method/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 09:22:19 +0000</pubDate>
		<dc:creator>Alvin / Aedis.Ju</dc:creator>
				<category><![CDATA[ActionScript Library]]></category>
		<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[richmediaplus Lab]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[extract]]></category>
		<category><![CDATA[SampleDataEvent.SAMPLE_DATA]]></category>
		<category><![CDATA[Sound]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=502</guid>
		<description><![CDATA[flash.media.sound 在Flash Player version 10 及更高版本中，可以處理動態生成的聲音。這種情況下，Sound 對象將使用向 flash.events.SampleDataEvent 事件處理函數分配的函數來輪詢聲音數據。從用聲音數據填充的 ByteArray 對象檢索聲音的同時播放聲音。可以使用 Sound.extract() 從 Sound 對像中提取聲音數據，然後在將聲音數據寫回到流以進行播放之前可以對其進行操作。 因此按照例子寫了2種不同版本的改變聲音速度的例子，2個例子區別在于 SampleDataEvent 處理方式得不同。 一個是改變了音速（帶有“piapia”聲） 一個是改變了音頻（像以前的磁帶） 改變了音速（帶有“piapia”聲）的SampleDataEvent 處理方式 /** * mp3Real.SampleDataEvent.SAMPLE_DATA **/ private function onSampleData&#40;e:SampleDataEvent&#41;:void &#123; currentPosition = uint&#40;_position&#41;; &#160; var currentTimeIntDiff_1:uint = uint&#40;_position&#41; / 44100; currentTime = toDoubleString&#40;uint&#40;currentTimeIntDiff_1 / 60&#41;&#41; + &#34;:&#34; + toDoubleString&#40;currentTimeIntDiff_1 % 60&#41;; &#160; var bytes:ByteArray = [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2010/07/richmediaplus-utils-alertutils/' rel='bookmark' title='richmediaplus.utils.AlertUtils'>richmediaplus.utils.AlertUtils</a></li>
<li><a href='http://blog.richmediaplus.com/2009/07/seo-for-flex-flash/' rel='bookmark' title='SEO For Flex/Flash'>SEO For Flex/Flash</a></li>
<li><a href='http://blog.richmediaplus.com/2010/04/bytearray-base64/' rel='bookmark' title='ByteArray &amp; Base64'>ByteArray &#038; Base64</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>flash.media.sound 在Flash Player version 10 及更高版本中，可以處理動態生成的聲音。這種情況下，Sound 對象將使用向 flash.events.SampleDataEvent 事件處理函數分配的函數來輪詢聲音數據。從用聲音數據填充的 ByteArray 對象檢索聲音的同時播放聲音。可以使用 Sound.extract() 從 Sound 對像中提取聲音數據，然後在將聲音數據寫回到流以進行播放之前可以對其進行操作。</p>
<p>因此按照例子寫了2種不同版本的改變聲音速度的例子，2個例子區別在于<br />
SampleDataEvent 處理方式得不同。<br />
<a href="http://code.richmediaplus.com/SoundSpeedChangePlayerMethod1/SoundSpeedChangePlayerMethod1.html" target="_blank">一個是改變了音速（帶有“piapia”聲）</a><br />

<object width="480" height="300">
<param name="movie" value="http://code.richmediaplus.com/SoundSpeedChangePlayerMethod1/SoundSpeedChangePlayerMethod1.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<param name="allowScriptAccess" value="always"></param>
<embed type="application/x-shockwave-flash" width="480" height="300" src="http://code.richmediaplus.com/SoundSpeedChangePlayerMethod1/SoundSpeedChangePlayerMethod1.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p><a href="http://code.richmediaplus.com/SoundSpeedChangePlayerMethod2/SoundSpeedChangePlayerMethod2.html" target="_blank">一個是改變了音頻（像以前的磁帶）</a><br />

<object width="480" height="300">
<param name="movie" value="http://code.richmediaplus.com/SoundSpeedChangePlayerMethod2/SoundSpeedChangePlayerMethod2.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<param name="allowScriptAccess" value="always"></param>
<embed type="application/x-shockwave-flash" width="480" height="300" src="http://code.richmediaplus.com/SoundSpeedChangePlayerMethod2/SoundSpeedChangePlayerMethod2.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>改變了音速（帶有“piapia”聲）的SampleDataEvent 處理方式</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #3f5fbf;">/**
 * mp3Real.SampleDataEvent.SAMPLE_DATA
 **/</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onSampleData<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>SampleDataEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	currentPosition = <span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>_position<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> currentTimeIntDiff_1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>_position<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">44100</span><span style="color: #000066; font-weight: bold;">;</span>
	currentTime = toDoubleString<span style="color: #000000;">&#40;</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>currentTimeIntDiff_1 <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;:&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> toDoubleString<span style="color: #000000;">&#40;</span>currentTimeIntDiff_1 <span style="color: #000066; font-weight: bold;">%</span> <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> bytes<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ByteArray</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ByteArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	mp3Proxy<span style="color: #000066; font-weight: bold;">.</span>extract<span style="color: #000000;">&#40;</span>bytes<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">4096</span><span style="color: #000066; font-weight: bold;">,</span> _position<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	bytes<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
	e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeBytes</span><span style="color: #000000;">&#40;</span>bytes<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>isThumbPress<span style="color: #000000;">&#41;</span>
		hs_time<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span> = _position <span style="color: #000066; font-weight: bold;">/</span> maxPosition<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	bytesSpeed = playbackSpeed <span style="color: #000066; font-weight: bold;">*</span> BYTES_PER_CALLBACK<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	_position <span style="color: #000066; font-weight: bold;">+</span>= bytesSpeed<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>改變了音頻（像以前的磁帶）的SampleDataEvent 處理方式</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #3f5fbf;">/**
 * mp3Real.SampleDataEvent.SAMPLE_DATA
 **/</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onSampleData<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>SampleDataEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> l<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> r<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> p<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> loadedSamples<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ByteArray</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ByteArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	currentPosition = <span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>_phase<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	bytesSpeed = playbackSpeed <span style="color: #000066; font-weight: bold;">*</span> BYTES_PER_CALLBACK<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> currentTimeIntDiff_2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = currentPosition <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">44100</span><span style="color: #000066; font-weight: bold;">;</span>
	currentTime = toDoubleString<span style="color: #000000;">&#40;</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>currentTimeIntDiff_2 <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;:&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> toDoubleString<span style="color: #000000;">&#40;</span>currentTimeIntDiff_2 <span style="color: #000066; font-weight: bold;">%</span> <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_isPlayingSound <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> currentTime == maxTime<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_isPlayingSound = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span> 
&nbsp;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>isThumbPress<span style="color: #000000;">&#41;</span>
		hs_time<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span> = _phase <span style="color: #000066; font-weight: bold;">/</span> maxPosition<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	mp3Proxy<span style="color: #000066; font-weight: bold;">.</span>extract<span style="color: #000000;">&#40;</span>loadedSamples<span style="color: #000066; font-weight: bold;">,</span> BYTES_PER_CALLBACK <span style="color: #000066; font-weight: bold;">*</span> playbackSpeed<span style="color: #000066; font-weight: bold;">,</span> currentPosition<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	loadedSamples<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>loadedSamples<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesAvailable</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		p = <span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>_phase <span style="color: #000066; font-weight: bold;">-</span> currentPosition<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>p <span style="color: #000066; font-weight: bold;">&lt;</span> loadedSamples<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">8</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">&lt;</span>= BYTES_PER_CALLBACK <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">8</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			loadedSamples<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span> = p<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			l = loadedSamples<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readFloat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			r = loadedSamples<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readFloat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeFloat</span><span style="color: #000000;">&#40;</span>l<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeFloat</span><span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">else</span>
		<span style="color: #000000;">&#123;</span>
			loadedSamples<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span> = loadedSamples<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		_phase <span style="color: #000066; font-weight: bold;">+</span>= playbackSpeed<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>不知道各位有沒有既能改變速度又不會調高音頻的辦法，請賜教。</p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2010/07/richmediaplus-utils-alertutils/' rel='bookmark' title='richmediaplus.utils.AlertUtils'>richmediaplus.utils.AlertUtils</a></li>
<li><a href='http://blog.richmediaplus.com/2009/07/seo-for-flex-flash/' rel='bookmark' title='SEO For Flex/Flash'>SEO For Flex/Flash</a></li>
<li><a href='http://blog.richmediaplus.com/2010/04/bytearray-base64/' rel='bookmark' title='ByteArray &amp; Base64'>ByteArray &#038; Base64</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2010/03/compare-with-change-adobe-flex-sound-speed-method/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

