Pages

Wednesday, 11 January 2012

Embedding Fonts In Actionscript 3

I hardly use the Flash IDE at all any more. Pretty much all of my coding is done in FlashDevelop. One thing that the IDE does very well is the embedding of fonts but there are certainly ways of doing it using purely code. People seem to have found many ways of embedding fonts but this one has always worked for me:

This class is my font library - I embed all fonts that I use in here. The two things to note are the embed code for the fonts and public constants to allow me to access them using FontLibrary.FONT...


This is the main class of my application. Here I create a sample text field and set the text format to one of my embedded fonts.

Easy! You can download all of the source files for this and my other projects from: http://experimentalized.com/blog/sourcezip/Blog.zip.

Two Dimensional Water Simulation

This is my first blog post in a while so I thought I'd try something interesting. A few years ago I took a look at some discrete cell methods for simulating water in 2D. I decided to take a new approach and use a particle based method to simulate particles interacting. The image below shows the simulation running with 6000 particles at a reasonable framerate. All the particles in the scene repulse one another, and are accelerated earthward by gravity. If a naive approach were taken, the number of tests performed on each iteration of the program would be 6000 * 6000 = 3600000 distance calculations. This would be a large number of square roots for even the best CPU. In order to get around this I make use of some simple image filters to approximate the same result. Each particle is rendered to a bitmap buffer as a single pixel (I took this approach for a previous experiment). These pixel values are then blurred and the gradients at each point on the bitmap calculated using Sobel operators. At this stage calculating particles updated trajectories is just a case of subtracting the value of the gradient at each point from their velocity. Because the blur filter naturally falls off the repulsive force is proportional to the kernal used in the filtering process.

As usual just click to try out the demo!

The source code for all projects from now on will be added to a single flash project which can be found at:


Monday, 8 August 2011

Voice Recognition in Flash

This evening I thought I'd take a crack at looking at voice recognition in flash. The idea for this came after the realisation that when using my phone I have almost entirely given up on using the keypad. Instead I simply utter a few words (When passers by are out of ear shot) and a voice appears at the other end. Wonderful! I haven't read up on voice recognition at all so in part I am using the knowledge I've gained by looking at image recognition and tracking software. Being a big Aphex Twin fan and having written a spectrograph to visualize this song in flash before I had at least a bit of a grounding. The idea would be to record a small sample of voice, using some microphone thresholding, draw a spectograph of the sample and then compare the spectograph to a database of possible patterns and determine which command or whatever is most similar. I'm pleased to say that I have completed the first half of this today and you can click to see a demo below (The top image will launch it):




The images are of a whistling sequence, a glass being rung, and me saying hello. Interestingly you can see the harmonics of the glass being rung (a few set frequencies). My voice is a bit harder to translate but using some analysis I'm sure it will be possible.

Anyway as usual the source code can be downloaded here and let me know if you come up with anything using it. How about auto-tuning?!

The plan from here is to save single voice clips as images, and train a neural network to find patterns in both the volume and the spectograph for a set number of commands. I will report my findings shortly!