Live audio visualization in flash pt I
- June 22nd, 2009
- Write comment

Just for a short overview,
I sometimes play drum and bass on parties. To improve the audience experience, I use flash to visualize the digital culture I’m living. For this, I wrote some applications in flash and air. These apps are more experiments to find out how my sound can influence visual media to generate a special atmosphere.
Sometimes some people notice what I am doing or know what is happening. Therefore, questions came up and it is difficult to have a productive conversation at a party….
So why flash?
I think the main reason was that I wanted to experiment with Flash and later on with the new features of the player 10.
So let us get started.
The first step to reach the stuff I had in mind was to grab the audio signal. I have a line-in, so let us take a look what possibilities I have in flash to use this. I found the flash.media package providing some classes to access the microphone and the sound spectrum. I found out that it was not really easy to get apply the computeSpectrum method on the microphone. So I thought. O.K. I’ll code a Java app that catches the audio signal, computes spectrum and send this data as bytearray to flash. However, this was not very cool, even having some java code, I could re use and I wanted to stay with flash.
I explored the possibilities and none of them were easy and latency efficient for my purposes. I really needed some time to find the solution and it was sooo simple !
Setup a streaming Server on your computer. My choice after some tests was Icecast2 here is a sample of my config:
| xml | | copy | | ? |
| 01 | |
| 02 | |
| 03 | |
| 04 |
|
| 05 |
|
| 06 |
|
| 07 |
|
| 08 | |
| 09 | |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 | |
| 15 | |
| 16 |
|
| 17 | |
| 18 |
|
| 19 | |
| 20 |
|
| 21 | |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 | |
| 26 | |
| 27 | |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
Setup a streaming client on your computer like Edcast and choose the right audio in.
When you get this programs running you will have a streaming server running under the following URL:
or if you are using shoutcast :
….. /;stream.nsv
So now, you can catch this audio stream from your flash app like this:
| actionscript | | copy | | ? |
| 1 | |
| 2 | this._sfx = new Sound(); |
| 3 | var req:URLRequest = new URLRequest("http://localhost:6666/stream");// /;stream.nsv
|
| 4 | var context:SoundLoaderContext = new SoundLoaderContext(0, false); |
| 5 | this._sfx.load(req, context); |
| 6 | this._channel = this._sfx.play(); |
| 7 | SoundMixer.bufferTime=0; // works for me locally |
| 8 |
Now you can get the spectrum over an onEnterFrame Event with SoundMixer.computeSpectrum. I am going to explain this in part II






