Here’s the first draft of my source files for Fourier Transform. Currently the swf expects a sound file named “test.mp3” in the same folder, but you can easily change that. It’s drawing the spectral analysis of the first couple of seconds of sound of that mp3 file. 

I have code lying around to load a file instead, and I’ll see if I can make some time to implement that so I can put up a working example, with paging etc.

Take note that the FFT.as class, which contains the hard core code for the Fourier Transform, is a port from C++, and is copyrighted by the original writer of that code. Please leave in his copyright note when using this code.

I heard that Andre Michelle uses linked lists instead of Vector to speed things up. I didn’t make it to his talk on FitC Amsterdam, unfortunately, so I don’t know the details about that yet, but that might give an extra speed boost here and there. Maybe the butterfly algorithm that FFT uses, can be implemented in this way…

1 Mar, 2009, 20:39 o'clock

One of the features of the Yala logging viewer is its low CPU load. I began to notice while looking at the Activity Monitor on my Mac that Yala was quite constant at roughly 3.5% CPU load. I also saw that the twitter client I just started using, DestroyTwitter, had an average load of around 7%, sometimes staying around 18% for minutes. That’s a lot of CPU power (and hence power draw & battery load). I began to wonder if a basic empty AIR application would show the same behaviour. And guess what? An empty AIR application draws 3% CPU load on a MacBookPro 3rd gen. For doing nothing, I find that quite rediculous.
The profiler doesn’t make me much wiser. It seems to spend quite some time doing [reap]. Did someone implement a grim reaper? Is the application desperately trying not to die? Maybe time for looking up the bug base for AIR.

19 Feb, 2009, 11:03 o'clock

 

Yalog output for loading an image

Yalog output for loading an image

Notice something strange in the log output in the image? Each line is a ProgressEvent as received from a Loader. Check the bytes loaded… Why do we get the event a second time for the old number of loaded bytes by the time the new number of bytes has been received? Is that a bug or a feature?

11 Feb, 2009, 12:15 o'clock

A few years ago I developed a logging class plus viewer application for debugging purposes. Main requirement was lightweightedness: the logging code should put as little pressure on the CPU as possible, and so should the viewer. At LBi Lost Boys, the company I’m working for, we’ve been using this utility over the last years, and it’s become an indispensible component of our work flow.
Last week I put out the source, both of the log utility and of the viewer, into open source space. Check the main page on Google Code for source code and downloads. 

 

Icon of Yala, the Yalog viewer AIR application

 Yalog consists of the logging utility, comprising one main class (Yalog.as) and a few helper classes, and a viewer. This viewer is basically a swf, so can be used in any context where a swf can be used. Currently it’s available for download as an AIR-application. If you just want to use this and not be bothered with the source of the viewer, download the Yalog source classes, and install the AIR application. 

 

The viewer can be seen in action at http://yala.acidcats.nl/. If you open a Yalog-enabled site (such as www.de.nl), you will see debug messages appear in the viewer. A nifty feature of Yalog is that it buffers the last 200 messages (number can be changed) until the viewer appears, so you can open the viewer after something has gone wrong, and still view the latest messages.

When I have more time, I’ll put up a page here with more info and details.

4 Feb, 2009, 13:05 o'clock

The presentation by Adobe’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’s, when I studied Sonology at the Kon. Conservatorium in Den Haag: spectral analysis & (re)synthesis of sound. This is usually done by means of the Fourier Transform, 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.

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 & 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.

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 & getting the lenght of vectors, which requires Math.sqrt), a back-and-forth transformation shouldn’t take more than 10 ms, leaving 40ms for doing fun stuff with the data. So even without a C-port it’s possible to do real time audio transformation in the frequency domain.

The first thing to do is plot the data in an image. Right now I’m only posting a screenshot, as I’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:

More about this (including source code) soon!

4 Dec, 2008, 14:01 o'clock

I’m experimenting a bit with flocking. Haven’t gotten as far a moving stuff in any interesting way yet, but it’s fun enough to fool around with maths I haven’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.

Click to make them start moving to the center, click again to stop the motion. Makes for a nice hedgehog at some point 😀

The source code is here. No fla file, code only.

And thanks to Arie for his tip about the Kimili WordPress Flash plugin

26 Dec, 2007, 23:28 o'clock

One of those things… The event ADDED_TO_STAGE, dispatched by any DisplayObject when it gets added to the stage (duh) as opposed to added to a parent, wasn’t available in Flash player 9 before 9.0.28. That basically means we can’t really trust it will be available until statistics prove that any and all minor releases prior to that one have disappeared from the face of the earth. So instead of that, we have to use Moock’s solution (but that’s a hell of a lot of work to be notified of just one little event), or check the event’s phase (also thanks to Moock): 

  1. private function handleAdded (e : Event) : void {
  2.     if (e.eventPhase != EventPhase.AT_TARGET) return;
  3.     // do something useful
  4. }
25 Dec, 2007, 0:42 o'clock

The function flash.utils.getDefinitionByName has been discussed in various other places (amongst others here and of course in the documentation), but it took a bit of a mental jump to use it as the solution for the problem that linked library instances without a class are not known inside FDT.Suppose we have a library item with a linkage id of “square”, and we decide not to attach a class to it. Flash CS3 reminds us that it will create one for us, and if we code inside the Flash IDE, we can happily write: var s:Sprite = new square(); addChild(s);However, FDT will show an error, because it doesn’t have a clue what you’re talking about. To solve this, use getDefinitionByName("square"), as shown in the following example:

  1.  
  2. package {
  3.     import flash.display.MovieClip;
  4.     import flash.display.Sprite;
  5.     import flash.utils.getDefinitionByName;
  6.    
  7.     public class Application extends MovieClip {
  8.        
  9.         private static const LINKAGE_SQUARE:String = "square";
  10.  
  11.         public function Application () {
  12.             var s:Sprite = new (getDefinitionByName(LINKAGE_SQUARE))();
  13.             addChild(s);
  14.         }
  15.     }
  16. }
  17.  
25 Nov, 2007, 22:48 o'clock

A true Pooh Bear level statement, taken from a review of a mobile phone: “If I were you then I would do what I have done, and buy the Samsung D900“. I don’t know about the Samsung, but the first part of the sentence just keeps throwing me into fits of laughter. Original can be found here: http://www.mobile-phones-uk.org.uk/sony-ericsson-z710i.htm

12 Sep, 2007, 23:05 o'clock

The one we (flight sim enthusiasts) have been waiting for: Google Earth 4.2 incorporates a flight simulator.
Google Earth Flight Simulator

On the plus side:

  •  physics pretty good
  • most realistic scenery available 😀
  • always blue skies 😛
  • amazing experience of the landscape
  • easily controllable with the mouse & keyboard

On the minus side:

  •  no sound
  • have to pause on a regular basis to allow imagery to be updated
  • the occasional crash (as in, program crash!)
  • well visible that height info & textures don’t always align
2 Sep, 2007, 20:40 o'clock

Twitter

Flickr

www.flickr.com
This is a Flickr badge showing public photos from AcidCats. Make your own badge here.