<?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>Mental Notes &#187; experiments</title>
	<atom:link href="http://stephan.acidcats.nl/blog/category/experiments/feed/" rel="self" type="application/rss+xml" />
	<link>http://stephan.acidcats.nl/blog</link>
	<description>from the trenches of software development</description>
	<lastBuildDate>Sun, 01 Mar 2009 19:44:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spectral analysis with Fast Fourier Transform in Actionscript</title>
		<link>http://stephan.acidcats.nl/blog/2008/12/04/spectral-analysis-with-fast-fourier-transform-in-actionscript/</link>
		<comments>http://stephan.acidcats.nl/blog/2008/12/04/spectral-analysis-with-fast-fourier-transform-in-actionscript/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 13:01:34 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[FFT]]></category>
		<category><![CDATA[spectral analysis]]></category>

		<guid isPermaLink="false">http://stephan.acidcats.nl/blog/?p=23</guid>
		<description><![CDATA[The presentation by Adobe&#8217;s Jim Corbett on Alchemy at the Adobe MAX 2008 conference in Milan last Tuesday (2nd of December), got me thinking about something I used to spend quite some time on back in the early 90&#8217;s, when I studied Sonology at the Kon. Conservatorium in Den Haag: spectral analysis &#38; (re)synthesis of sound. [...]]]></description>
			<content:encoded><![CDATA[<p>The presentation by Adobe&#8217;s Jim Corbett on <a title="Alchemy C/C++ to Actionscript" href="http://labs.adobe.com/technologies/alchemy/" target="_blank">Alchemy</a> at the Adobe MAX 2008 conference in Milan last Tuesday (2nd of December), got me thinking about something I used to spend quite some time on back in the early 90&#8217;s, when I studied Sonology at the Kon. Conservatorium in Den Haag: spectral analysis &amp; (re)synthesis of sound. This is usually done by means of the <a title="Fourier Transform on Wikipedia" href="http://en.wikipedia.org/wiki/Fourier_transform" target="_blank">Fourier Transform</a>, which transforms time-based data such as sound to the frequency domain. The most used algorithm for this is the Fast Fourier Transform, or FFT, which requires the number of samples per transformation to be a power of 2. Usually a block of 1024 samples is used, which equals roughly 50ms of sound at 44.1kHz.</p>
<p>Now the FFT algorithm is quite CPU-intensive, and as Alchemy is put forward as useful for large number-crunching operations, I thought this could be a very interesting case. In order to allow for proper comparison, I decided to first port the FFT code from C to Actionscript, and do some testing. It took some refactoring of the C-code in Actionscript to allow for specific bottlenecks popping up, such as multiple lookup of the same value from a Vector, which turns out to be an expensive operation. Also the calculation of sine &amp; cosine was done beforehand, to allow for a lookup table to be used in the actual FFT algorithm. All in all I managed to gain some 50% speed increase by these optimizations.</p>
<p>To my surprise, a single transformation of one block of 1024 samples takes only 5 ms in Actionscript. Even when performing the necessary after-calculations (normalizing &amp; getting the lenght of vectors, which requires Math.sqrt), a back-and-forth transformation shouldn&#8217;t take more than 10 ms, leaving 40ms for doing fun stuff with the data. So even without a C-port it&#8217;s possible to do real time audio transformation in the frequency domain.</p>
<p>The first thing to do is plot the data in an image. Right now I&#8217;m only posting a screenshot, as I&#8217;d like to polish the example a bit more before putting out the actual code, but this is what a frequency plot of a short piece of music looks like:</p>
<p><a href="http://stephan.acidcats.nl/blog/wp-content/picture-1.jpg" rel="lightbox"><img class="alignnone size-medium wp-image-24" title="Spectral analysis" src="http://stephan.acidcats.nl/blog/wp-content/picture-1-300x154.jpg" alt="" width="300" height="154" /></a></p>
<p>More about this (including source code) soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://stephan.acidcats.nl/blog/2008/12/04/spectral-analysis-with-fast-fourier-transform-in-actionscript/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Flocking</title>
		<link>http://stephan.acidcats.nl/blog/2007/12/26/19/</link>
		<comments>http://stephan.acidcats.nl/blog/2007/12/26/19/#comments</comments>
		<pubDate>Wed, 26 Dec 2007 22:28:32 +0000</pubDate>
		<dc:creator>stephan</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[experiments]]></category>

		<guid isPermaLink="false">http://stephan.acidcats.nl/blog/2007/12/26/19/</guid>
		<description><![CDATA[I&#8217;m experimenting a bit with flocking. Haven&#8217;t gotten as far a moving stuff in any interesting way yet, but it&#8217;s fun enough to fool around with maths I haven&#8217;t looked at for decades. In the sample below you can see how the vectors of attraction pull the birds (yeah right!) to the common center, while [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m experimenting a bit with <a href="http://en.wikipedia.org/wiki/Flocking_(behavior)" title="Flocking on WikiPedia" target="_blank">flocking</a>. Haven&#8217;t gotten as far a moving stuff in any interesting way yet, but it&#8217;s fun enough to fool around with maths I haven&#8217;t looked at for decades. In the sample below you can see how the vectors of attraction pull the birds (yeah right!) to the common center, while birdies that are close to each other get nasty long green repulsion vectors.</p>
<p>Click to make them start moving to the center, click again to stop the motion. Makes for a nice hedgehog at some point <img src='http://stephan.acidcats.nl/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>The source code is <a href="http://stephan.acidcats.nl/blog/wp-content/flocking_source.zip" title="Source code for flocking experiment">here</a>. No fla file, code only.</p>
<p>And thanks to <a href="http://www.bonth.nl/" target="_blank" title="Arie de Bonth">Arie</a> for his <a href="http://www.bonth.nl/eerste-pagina/" target="_blank" title="Post on Kimili">tip</a> about the <a href="http://kimili.com/plugins/kimili-flash-embed-for-wordpress" title="Kimili Flash plugin for WordPress" target="_blank">Kimili Wordpress Flash plugin</a></p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_flocking_2106691292"
			class="flashmovie"
			width="440"
			height="440">
	<param name="movie" value="http://stephan.acidcats.nl/blog/wp-content/flocking.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://stephan.acidcats.nl/blog/wp-content/flocking.swf"
			name="fm_flocking_2106691292"
			width="440"
			height="440">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://stephan.acidcats.nl/blog/2007/12/26/19/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

