Sound Compute Spectrum. May 4, 2007 at 9:47 am
Visualising soundwaves with actionscript3 is pure fun. Inspired by an demo Joa Ebert released on the last flashforum conference in germany, i decided to build my own little sound-visualising demo, called “the brightWhite experience”.
Premium supported on getting some free sounds created by Philipp Weigl, i tought up some nice little effects for that visualiser, that react, interact or just feature the sound. It took me a bit to motivate my old scripting buddy thorsten werner, the guy behind rgblaster, to contribute some of his great as3-experiments too. The end result was a nice little flashdemo for sound-visualisation via compute spectrum.
Want a little snippet?
///////////////////////////////////
// analyse sound spectrum
///////////////////////////////////
getByte = 0;
SoundMixer.computeSpectrum(byteArr, true);
var i:int;
var w:uint = 2;
var num = undefined;
var type:String = undefined;
for (i=0; i<512; i+=w) {
var getByte:Number = byteArr.readFloat();
var n:Number = Math.floor(getByte * 100);
////////////////////////
// catch massiv amp
////////////////////////
if (i > 256 && n > 20) {
type = “massiv”;
}
}
paintTunnelizer(type);
///////////////////////////////////
// paint some effects
///////////////////////////////////
function paintTunnelizer(type:String) {
zIndex1++;
modulo++;
var mc:MovieClip = new MovieClip();
mc.name = “circle__” + String(zIndex1);
mc.x = 200;
mc.y = 200;
stage.addChild(mc);
if (modulo==2) {
modulo=0;
mc.graphics.lineStyle(5,0×000033,.1);
mc.graphics.drawCircle(0,0,50);
} else {
if (type == “massiv”) {
mc.graphics.lineStyle(5,0xffffff,5);
mc.graphics.drawCircle(0,0,50);
} else {
mc.graphics.lineStyle(5,0xffffff,.3);
mc.graphics.drawCircle(0,0,50);
}
}
dot0 = stage.getChildAt(1);
var getDotX:Number = Number(dot0.x);
var getDotY:Number = Number(dot0.y);
mc.x = getDotX;
mc.y = getDotY;
mc.sc = 1;
mc.alpha = 0.1;
for (var i:Number = 3; i < stage.numChildren; i++) {
var p = stage.getChildAt(i);
if (p.name.indexOf("circle__",0) != -1) {
var p1 = stage.getChildAt(i);
if (!tSwitch) {
p1.sc *= 1.2;
} else {
p1.sc *= .9;
}
p1.scaleX = p1.sc;
p1.scaleY = p1.sc;
p1.alpha+=.02;
if (type == "massiv") {
if (!tSwitch) {
tSwitch = true;
} else {
tSwitch = false;
}
}
if (p1.scaleX > 7) {
stage.removeChild(p1);
}
}
}
}
See that snippet in action



Just looking at the code, it looks like it’s using the SoundMixer. I can’t use that because it contains the final mix being sent to the speakers. I need to analyze individual sounds BEFORE they get sent to the mixer, so SoundMixer.computespectrum doesn’t work for me.
Hopefully it makes sense what I’m trying to do.