forked from: visualizer
forked from visualizer (diff: 272)
ActionScript3 source code
/**
* Copyright jokehn9 ( http://wonderfl.net/user/jokehn9 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1yNa
*/
// forked from codeonwort's visualizer
package {
import flash.text.TextField;
import flash.display.Graphics;
import flash.utils.ByteArray;
import flash.media.SoundChannel;
import flash.media.Sound;
import flash.net.URLRequest
import flash.media.SoundLoaderContext
import flash.media.SoundChannel
import flash.media.SoundMixer;
import flash.display.Sprite
import flash.events.Event
public class FlashTest extends Sprite {
private var s:Sound
private var channel:SoundChannel;
private const PLOT_HEIGHT:int = 200;
private const CHANNEL_LENGTH:int = 226;
private var bytes:ByteArray = new ByteArray()
private var txt:TextField = new TextField();
public function FlashTest() {
// write as3 code here..
stage.addEventListener("rightClick", function($:Event):void{})
txt.text = "No";
txt.x = 200;
txt.y = 50;
addChild(txt);
s = new Sound(new URLRequest('http://clug.kr/~codeonwort/file_pool/old_elvengard.mp3'), new SoundLoaderContext(1000, true));
s.addEventListener(Event.COMPLETE, comp)
s.addEventListener(Event.SOUND_COMPLETE, onPbc);
}
private function comp(e:Event):void {
channel = s.play();
addEventListener("enterFrame", loop)
}
private function loop(e:Event):void {
SoundMixer.computeSpectrum(bytes, false, 0);
var g:Graphics = this.graphics;
var n:Number = 0;
g.clear();
g.lineStyle(0, 0x6600cc);
g.beginFill(0xffcc);
g.moveTo(0,PLOT_HEIGHT);
for(var i:int = 0; i<CHANNEL_LENGTH; i++) {
n = (bytes.readFloat() * PLOT_HEIGHT);
g.lineTo(i*2,PLOT_HEIGHT - n);
if(n>0.4 * PLOT_HEIGHT) {
txt.text = "Yes";
}
}
g.lineTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);
g.endFill();
/*
g.lineStyle(0,0xcc0066);
g.beginFill(0xcc0066, 0.5);
g.moveTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);
for(i = CHANNEL_LENGTH;i > 0 ; i--) {
n = (bytes.readFloat() * PLOT_HEIGHT);
g.lineTo(i*2,PLOT_HEIGHT - n);
}
g.lineTo(0,PLOT_HEIGHT);
g.endFill();
*/
}
private function onPbc(event:Event):void
{
removeEventListener(Event.ENTER_FRAME, loop);
}
}
}
/*
class MP3Button {
public static var channel:SoundChannel
}
*/