# Audio wave visualizer for multiple songs

**URL:** https://forum.kirupa.com/t/audio-wave-visualizer-for-multiple-songs/295752
**Category:** Uncategorized
**Created:** [September 3, 2009, 7:40pm UTC](https://forum.kirupa.com/t/audio-wave-visualizer-for-multiple-songs/295752 "2009-09-03T19:40:12Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![leewebber](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@leewebber](https://forum.kirupa.com/u/leewebber)
#### Post date: [September 3, 2009, 7:40pm UTC](https://forum.kirupa.com/t/audio-wave-visualizer-for-multiple-songs/295752/1 "2009-09-03T19:40:12Z")

</div>

[COLOR=black]hi people im a bit lost i have a visualizer here which plays mp3 and creates the audiowave. i would like it to be able to play mutiple songs but the simple script is evading me.i know it shouldnt be too hard but im confused can someone help me please.[/COLOR]

Here is the script. I know its needs changing in the first 10 lines just dont know how or where. please help my stupid self  
[COLOR=black][/COLOR]  
[COLOR=black][/COLOR]  
[COLOR=black][/COLOR]  
[COLOR=black][/COLOR]  
[COLOR=black]//BUTTONS  
play\_mc.addEventListener(MouseEvent.CLICK,playSong);  
play\_mc.buttonMode = true;  
stop\_mc.addEventListener(MouseEvent.CLICK,stopSong);  
stop\_mc.buttonMode = true;  
update\_mc.addEventListener(MouseEvent.CLICK, updateColors);  
update\_mc.buttonMode = true;[/COLOR]  
[COLOR=black]//SOUND  
var songOne:Sound = new Sound(new URLRequest(“beat.mp3”));  
var sc1:SoundChannel = new SoundChannel();[/COLOR]  
[COLOR=black]function playSong(e:Event):void  
{  
sc1 = songOne.play(0,99);  
play\_mc.enabled = false;  
}  
function stopSong(e:Event):void  
{  
sc1.stop();  
play\_mc.enabled = true;  
}[/COLOR]  
[COLOR=black]sc1 = songOne.play(0,99);  
play\_mc.enabled = false;[/COLOR]

[COLOR=black]//VISUALIZER  
var lineAlpha:Number = 0.5; //how visible the line in the center of the wave will be. Values range from 0.0 - 1.0  
var lineColor:Number = 0x00ff66; //the initial line color, right now it’s a pink color  
var lineThickness:Number = 1.0; //how thick your line will be  
var red:String = red\_txt.text; //sets the red value to the initial value of red\_txt  
var green:String = green\_txt.text; //sets the green value to the initial value of green\_txt  
var blue:String = blue\_txt.text; //sets the blue value to the initial value of blue\_txt  
var strength:Number = 0.8; //how strong the glow is around the line  
var speedX:Number = 2.0; //how fast the blur flows by on the X axis - to change direction, give a negative number  
var speedY:Number = 0.0; //how fast the blur flows by on the Y axis - to change direction, give a negative number[/COLOR]  
[COLOR=black]//this function updates the colors when the “UPDATE” button is pressed  
function updateColors(e:MouseEvent):void  
{  
red = red\_txt.text;  
blue = blue\_txt.text;  
green = green\_txt.text;  
lineColor = colorPicker.selectedColor;  
visualizer();  
}[/COLOR]  
[COLOR=black]//this is the heart of the visualizer  
function visualizer()  
{  
var ba:ByteArray = new ByteArray();  
var bmd:BitmapData = new BitmapData(300, 100, true, 0x000000); //IMPORTANT! - You want to make sure the first two parameters are your stage width and height respectively  
var bm:Bitmap = new Bitmap(bmd);  
addChild(bm);  
var sp:Sprite = new Sprite();  
addChild(sp);  
var blur:BlurFilter = new BlurFilter(2,2,3); //the paramaters for the Blur Filter - ex: BlurFilter(blurX, blurY, Quality);  
//the ColorMatrix below I do not know much about. I do know you basically only want to alter the values I am altering.  
var colorMatrix:ColorMatrixFilter = new ColorMatrixFilter([  
red, 0, 0, 0, 0,  
0, green, 0, 0, 0,  
0, 0, blue, 0, 0,  
0, 0, 0, strength, 0  
]);  
addEventListener(Event.ENTER\_FRAME, loop); //sets up the loop function to run every frame per second[/COLOR]  
[COLOR=black] //the “loop” function below draws the center wave line based off of the sound spectrum of your audio  
function loop(e:Event):void  
{  
sp.graphics.clear();  
sp.graphics.lineStyle(lineThickness, lineColor);  
sp.graphics.moveTo(-1, stage.height/2);  
sp.alpha = lineAlpha;  
SoundMixer.computeSpectrum(ba);  
for (var i:uint=0; i\<256; i++)  
{  
var num:Number = -ba.readFloat()_200 + stage.height/2;  
sp.graphics.lineTo(i_2, num);  
}  
bmd.draw(sp);  
bmd.applyFilter(bmd,bmd.rect,new Point(),blur); //applies the Blur Filter  
bmd.applyFilter(bmd,bmd.rect,new Point(),colorMatrix); //applies the ColorMatrix Filter  
bmd.scroll(speedX,speedY); //this is where “speed” sets how fast the ‘flow’ of the filters will be

}  
}  
visualizer();  
[/COLOR]
