Community

Adobe Flash Music Visualization Help

Posted Sep 19, '08 at 10:37pm

jpx111

jpx111

251 posts

Gold - Squire

Hello fellow Flash users :D
Today, I was exploring the world of music visualization in flash and i came across a good tutorial thingy...i was modifying it and changing numbers around and i got a pretty cool effect :)...except you see, the whole thing is done on AS3 and doing a whole project on codes isn't my thing... I have a doubt...but first let me show you the script:

var url:String = "Mas Que Nada.mp3";
var request:URLRequest = new URLRequest(url); 
var s:Sound = new Sound(); 
s.addEventListener(Event.COMPLETE, completeHandler); 
s.load(request);  var song:SoundChannel = s.play(); 
song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler); 
var ba:ByteArray = new ByteArray(); 

var gr:Sprite = new Sprite(); 
gr.x = 150; 
gr.y = 400; 
var blur:BlurFilter = new BlurFilter(10,20, BitmapFilterQuality.HIGH);
gr.filters = [blur];
addChild(gr); 

var time:Timer = new Timer(50); 
time.addEventListener(TimerEvent.TIMER, timerHandler); 
time.start(); 
 
function completeHandler(event:Event):void {     
  event.target.play(); 

function soundCompleteHandler(event:Event):void {     
  time.stop(); 
}

function timerHandler(event:TimerEvent):void {     
  SoundMixer.computeSpectrum(ba,false);     
  var i:int;     
  gr.graphics.clear();     
   var mat:Matrix = new Matrix();
mat.rotate(1.57079633);
gr.graphics.beginGradientFill(GradientType.LINEAR, [0xFF0000, 0x0A7614], [1, 1], [10, 170], mat);

  gr.graphics.moveTo(0,0);     
  var w:int = 1;     
  for (i=0; i<512; i+=w) {         
    var t:Number = ba.readFloat();         
    var n:Number = (t * 500);         
   gr.graphics.drawRect(i, 0, w, -n);     
}
}

note that i did make this code...i just tweaked it :)
for it to work, you must change the address in the quotes in the first line to a website link to a song, OR the name of a music file placed in the same folder as the present flash file (and if i didn't mention it before, you have to save your flash file somewherefirst after you copy the code into it)...
you could hit play now and adore the prettiness :)...and then help me with my problem :D
now that you are on the same track as me, what i want to do is add another sprite on top of the present one...but each time i do it, it compiles it without any errors, but while playing it , it doesn't show the sprites...

Any help will be greatly appreciated :D

Thanks a lot
- jpx

Posted Sep 19, '08 at 10:38pm

jpx111

jpx111

251 posts

Gold - Squire

sorry for double post but:

note that i did make this code...i just tweaked it :)

its supposed to say i did NOT make it :P

 

Posted Sep 21, '08 at 11:51pm

IqAndreas

IqAndreas

287 posts

Gold - Squire

I tried out the code and it looked really neat. :))

I am but a beginner in Action Script, but I have worked a lot with VB and similar code, so I pretty much understand what this code is doing.

However, I do not get what you are trying to do. In what way do you mean create another sprite on top of the present?

If you are trying to create it directly on top of the other, one is blocking the other, which is the reason you do not see it.

I messed around with the code a bit and got this:

var url:String = "09 Hotel California.mp3";
var request:URLRequest = new URLRequest(url);
var s:Sound = new Sound();
s.addEventListener(Event.COMPLETE, completeHandler);
s.load(request);
var song:SoundChannel = s.play();
song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
var ba:ByteArray = new ByteArray();

var gr1:Sprite = new Sprite();
gr1.x = 0;
gr1.y = 400;
var blur:BlurFilter = new BlurFilter(10,20, BitmapFilterQuality.HIGH);
gr1.filters = [blur];
addChild(gr1);

var gr2:Sprite = new Sprite();
gr2.x = 0;
gr2.y = 400;
addChild(gr2);

var time:Timer = new Timer(50);
time.addEventListener(TimerEvent.TIMER, timerHandler);
time.start();

function completeHandler(event:Event):void {
    event.target.play();
}

function soundCompleteHandler(event:Event):void {
    time.stop();
}

function timerHandler(event:TimerEvent):void {
    SoundMixer.computeSpectrum(ba,false);
    var i:int;
    gr1.graphics.clear();
    gr2.graphics.clear();
    var mat:Matrix = new Matrix();
    mat.rotate(1.57079633);
    gr1.graphics.beginGradientFill(GradientType.LINEAR, [0xFF0000, 0x0A7614], [1, 1], [10, 170], mat);
    gr2.graphics.beginGradientFill(GradientType.LINEAR, [0xFF0000, 0x0A7614], [1, 1], [10, 170], mat);

    gr1.graphics.moveTo(0,0);
    gr2.graphics.moveTo(0,0);
    var w:int = 1;
    for (i=0; i<512; i+=w) {
        var t:Number = ba.readFloat();
        var n:Number = (t * 500);
        gr1.graphics.drawRect(i, 0, w, -n);
        gr2.graphics.drawRect(i, 0, w, -n);
    }
}

It turned out neat, because the blur applied to gr1 shows up behind the hard lines of gr2, so there is like a shadow or a blur outside of the outline.

Also, if you move up the effect a little more (like saying gr.y = 200; instead) you can see that there is really a top and a bottom to this wave, the wave is just moved down so you only see the top part.

Does this give you an idea of what to do? If not, please explain the question more, and I will be happy to help in any way I can.

 

Posted Sep 22, '08 at 4:45pm

jpx111

jpx111

251 posts

Gold - Squire

thank you very much Andreas. You helped me wrap my head around this... :D
Today I'm a happy kid :D ... I'll probably post a code of a finished piece later :)

 

Posted Sep 22, '08 at 7:51pm

jpx111

jpx111

251 posts

Gold - Squire

Hello Everyone :D
I've made a final product using the code. Thank you again Andreas for your help. This is the single best thing that I've made using only AS3. No drawn art is used.
I built this using this Flash tutorial:

http://www.communitymx.com/content/article.cfm?cid=8E9A0

And if you want to see what I did, download the following .zip file, then extract it, and then open either of the folders (Hotel California or Mas Que Nada) and double click on the .swf file.

http://www.datafilehost.com/download-681e0173.html

All music in the .zip folder belongs to their respective owners.

Hotel California - The Eagles
Mas Que Nada - Sergio Mendez

I do not mean to trespass upon any copyrights by doing this.

I've also added my .fla file for any curious creature who thinks this is pretty stuff. But of course, you need Flash to open it. Also, you can put any song into it by opening the .fla file, going to the first frame's script on the main time line and editing the green link in the double quotes. However, your mp3 file needs to be in the same folder as the .fla for this to work. The link in the double quotes could be a link to a song on the internet.

I'm taking any comments of any sort...so please, post away.

PS: Please do not take this stuff and claim it as your own...your guilt will haunt you if you do.

PPS: If you think this is great stuff, go to the following link:

http://www.gskinner.com/blog/archives/2006/10/as3_music_visua.html

 

Posted Sep 22, '08 at 8:17pm

IqAndreas

IqAndreas

287 posts

Gold - Squire

All music in the .zip folder belongs to their respective owners.

Hotel California - The Eagles
Mas Que Nada - Sergio Mendez

Just curious, how old are you?

It seems like (to my surprise) most people on here are around 13-15 years old. I assumed you were as well, and seeing that song, I assumed you had just gotten that track from a tutorial.

I was shocked there were other weirdos out there that had both The Eagles and Sergio Mendez on their computer. :P

Also, you stated on your page that you are an amateur 3d modeler. What program do you use?

 

Posted Sep 22, '08 at 8:25pm

jpx111

jpx111

251 posts

Gold - Squire

lol...I am 14...and I like classic rock, jazz, blues, etc... weird?...i thought so...but there's a bunch of people like me where I live...so its not so weird :P

and as relating to 3D modeling, i use any free software I can get my hands on :D ... i use Google SketchUP(most proficient in it), Gmax (pretty bad at it), Maya Personal Learning Edition (second most proficient in it)...do you do any 3D modeling?

 

Posted Sep 22, '08 at 8:32pm

IqAndreas

IqAndreas

287 posts

Gold - Squire

That's great that you are getting into computer programming that early on. It will definitely benefit you in the future, and you can really get some high paying jobs in the computer industry.

do you do any 3D modeling?

Yes. I am currently learning to use Blender (found at blender.org).

It is free and works fantastically well. The whole interface looks a little weird, but once you get used to it, it works wonders, and I wish all programs worked the same way. I sometimes accidentally use the convenient keyboard shortcuts in other programs, which, sadly, does not usually work.

I would really recommend giving it a try. It is open source, so it is constantly being worked on and made better.

Also, what about Simon & Garfunkel? Can't beat that, can you? ;-)

 

Posted Sep 22, '08 at 8:48pm

Zophia

Zophia

3,500 posts

Iron - Princess

Moderator

Well you asked me to leave a comment here, jpx111~

So, uhm, I don't understand any of the coding, but it sounds pretty cool. :) I should download the .zip?

Also, yay for Blender. :)

 

Posted Sep 22, '08 at 8:50pm

IqAndreas

IqAndreas

287 posts

Gold - Squire

Ooh. Looks nice.
Also, Mas Que Nada was a "spiced up jazz version". I like it.

It makes me want to create a music player in flash. :)

Good job. Perhaps you could mix around with it a bit and allow users to select a predefined visualization from a drop down list. Or perhaps being able to import music files or play them streaming from the internet.

 

Posted Sep 22, '08 at 8:54pm

jpx111

jpx111

251 posts

Gold - Squire

lol...i'm not really that much into programming...but yeah i do it cuz sometimes it produces crazy results...i especially love doing it in VB cuz everything is so easy there :D

I've used Blender...I have it on my computer presently...I tried to learn it, but...i sorta quit halfway...this was two years ago...i might just try doing it again :D

Simon and Garfunkel are pretty good...but I don't really listen to them much :( ...just a couple of songs I like from them...
btw have you heard the ukulele orchestra of great Britain? Do check it out...they do cover sort of things and medleys of other songs and stuff
and I think we are somewhat getting off topic :P... you could continue this conversation on my profile if you want to :)

Now back to my program...any comments...anyone?

 
Reply to Adobe Flash Music Visualization Help

You must be logged in to post a reply!