Flash Audio - Sound Visualisation & New Audio API
INSPIRATION
A long time ago I remember being inspired by the Dub Selector project at Infinite Wheel, a series of Flash movies that play heavy dub reggae loops, and incorporate various ways of triggering a selection of dub sound effects, drum rolls and keyboard notes. The project gave me the idea to create a more in-depth Flash music production tool, with many preset sounds and loops, and potentially audio sequencing tools too.
MY PREVIOUS EXPERIMENTS WITH FLASH AND SOUND
This was back in the days of Flash 5 and I was a novice with Flash, I had only a basic grasp of actionscript. My first experiment was called ATG Beatbox. Here it is in all it's lo-fi glory!
Pretty basic, but quite fun to play with too! The main problem I had was getting the samples to loop properly, and to get 2 or more samples to play in sync with each other. These restrictions made the possibility of sequencing very limited, so I ended up creating it so that the user could trigger the samples manually and had to time it right to get the 2 beats in sync.
The only way I could get the samples to loop cleanly was by importing them into the fla and attaching them to keyframes in the timeline.
I later made a few other experiments, such as a piano arpeggiator which used actionscript to play different arpeggio patterns. The timing was always an issue, and I concluded that Flash makes a lousy metronome! Unfortunately I seem to have lost the source files for this project
so I can't provide an example.
Other more recent Flash projects I have done which include an element of sound are the SoundFX Player and Artanoid Game for 76 Creative. Artanoid uses the as2 attachSound method to load the mp3 files dynamically from the server.
SOUND VISUALISATION
New to actionscript 3 is the SoundMixer.computeSpectrum method, which takes a snapshot of the current sound wave and places it into the specified ByteArray object. The values are formatted as normalized floating-point values, in the range -1.0 to 1.0. The ByteArray object passed to the outputArray parameter is overwritten with the new values. The size of the ByteArray object created is fixed to 512 floating-point values, where the first 256 values represent the left audio channel, and the second 256 values represent the right audio channel.
It is explained in more depth in the article Sound Visualization in Flash CS3 by Tom Green, which is where I found out about it in the first place.
This is something I'm still experimenting with, but here's a basic example of what it can do:
Notice that because the audio sample is being loaded from the server using the Sound.load() method, the looping of the sample is still not satisfactory. The only way to make a sample loop properly still seems to be to import it and attach it to a keyframe. Here's another more abstract example:
There are a lot more cool examples of this type of Sound Visualisation at the AS3 Sound Spectrum Contest Results Be sure to check out the winning entry, which really demonstrates the scope of what can be done using computeSpectrum.
NEW SOUND API FOR FLASH 10
I recently discovered the Hobnox AudioTool, which is exactly the type of Flash based audio tool I imagined. It's actually amazing! As it features effects, like distortion, delay & reverb, phaser, etc. I could tell that, although the interface was flash, something else was being used to process the audio. The other thing I noticed was that the timing of it's drum machines was perfect! Something I've never been able to achieve with Flash.
Further investigation of the new sound API led me to these three articles by Adobe Engineer Tinic Uro, which seem to be a direct response to the Adobe, Make Some Noise campaign:
- Adobe Is Making Some Noise Part 1
- Adobe Is Making Some Noise Part 2
- Adobe Is Making Some Noise Part 3
In Part 3 of the article he provides some code for a 'seamless loop' using the new extract() method with the samplesCallback event handler. I will put this code to the test as I am sure it will lead to new projects and experiments for me, the results of which will surely appear on my site in the near future!
Other Flash projects that utilise the new sound API are Tenoran, a sampling and basic sequencing instrument, and Noteflight, a a full-featured application that displays, edits, prints and plays back music notation.













Excellent, excellent, excellent! spectacular! stupendous!
Was exactly what I was looking for.
And does exactly what you said it would do!
Can’t say that about many other things I’ve downloaded - including stuff I’ve paid for!
Good show!
Great tool - well done. One issue however: how can I prevent my video from repeating / looping continuiously. I have tried setting &loop=false as part of passing the swf filename and I have set it in the calling code as well but it ignores them. See the code below:
I have the same problem as Wayne Moran. I would like the flash to run only once, as the constant repeating would detract from the sight and prevent the point of the flash from being made.
Works perfectly… Amazingly simple…see http://www.hotmix.org
Excellent work !.
Its working fine. But I have placed my own swf insted of yours (test.swf). That is not working. Can you suggest a solution.
So, if I understood this:
I have a webpage, I want it to download the page files that are not flash files first, so clients be able of start reading stuff and see some light weight images, so once the files be downloaded say 5 secs, as it is rather light stuff, then I would like the flash file to start being downloaded, because clients will be busy reading and watching other stuff while the flash file downloads, is that correct????????
Great tool.
@ Wayne Moran and Nathan: This is not a problem of the swf file from Sam, it must be a problem of your swf, which loops.
Bye
George
I cannot get this to work on a LAMP server. Any ideas?
I am a total noob at times, more an artist than a webmaster. I’m trying to plug this in with no success. Could I get a hand with this, I’m plunking it in to a div cause I have a heavily layerd page. Thanks.
what is the function of the “8″ in the string? it seems to be a variable, but for what?
thanks.
Hi Sam, Sorry but I’m being very dumb… I follow the logic but can’t seem to apply it to my situation!
I’m using a javascript call on a swf music player.
Happy to send a donation to a fellow Brit to get it working
Thanks,
Peter
var options = {};
options.mediaPath = “images/stories/audio/lifestyle_mono.mp3″;
options.firstColor = “b7b7b7″;
options.backColor = “3E2D23″;
options.strokeColor = “3E2D23″;
options.autoPlay = “true”;
var params = {};
params.allowScriptAccess = “always”;
swfobject.embedSWF(”images/stories/audio/LWMusicPlayer.swf”, “player-holder”, “45″, “21″, “9.0.0″,false, options, {}, {});
Fabulous! You rock man, quick question, is there a way i can have a background image displayed until it starts showing the movie?
I am trying to implement this on my site and everything works great except there is a giant black box in the space where my movie will be once it loads. Is there a way to have an image there instead, that will then be replaced once the movie loads? How would I do this…
Thanks! <3
I have links on my flash file (set with .xml file). They don’t work with flash_timer.swf. Do you have any ideas why?