forked from: forked from: forked from: SoundVisualizer
Fingered from sadango's fFingered from: forked from: SoundVisualizer
fFingered from yd_niku's forked from: SoundVisualizer
fFingered from hiro_rec's SoundVisualizer
searching for a classic graphic equalizer
for an internet radio asx pls stream
is that possible>>>???
http://www.gravomaster.com/alarm/help/index.htm
http://www.gravomaster.com/alarm/
for a internet radio stream like
http://gravomaster.com/alarm/radio_qmusic.html
http://www.q-music.nl/asx/q-music.asx
http://livestreams.omroep.nl/npo/3fm-bb
// Fingered from sadango's fFingered from: forked from: SoundVisualizer
// fFingered from yd_niku's forked from: SoundVisualizer
// fFingered from hiro_rec's SoundVisualizer
// searching for a classic graphic equalizer
// for an internet radio asx pls stream
// is that possible>>>???
// http://www.gravomaster.com/alarm/help/index.htm
// http://www.gravomaster.com/alarm/
// for a internet radio stream like
// http://gravomaster.com/alarm/radio_qmusic.html
// http://www.q-music.nl/asx/q-music.asx
// http://livestreams.omroep.nl/npo/3fm-bb
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.GradientType;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.BlurFilter;
import flash.filters.DisplacementMapFilter;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.net.URLRequest;
import flash.system.Security;
import flash.utils.ByteArray;
[SWF( backgroundColor='#000000')]
public class Main extends Sprite
{
private var container:Sprite;
private var s:Sound;
private var sc:SoundChannel;
private var ba:ByteArray;
private var mode:Boolean;
private var max:int;
private var offset:Number;
private var bar:Sprite;
private var centerY:int;
private var grad:Shape;
private var gradBmd:BitmapData;
private var rect:Rectangle;
private var bmd:BitmapData;
private var bmp:Bitmap;
private var blur:BlurFilter;
private var target:Sprite;
private var radius:Number;
private var rot:Number;
private var vs:Number;
private var dm:DisplacementMapFilter;;
public function Main()
{
buttonMode = true;
Security.loadPolicyFile("http://www.gravomaster.com/alarm/crossdomain.xml");
container = new Sprite();
s = new Sound();
mode = false;
max = 512;
offset = stage.stageWidth/max;
bar = new Sprite();
centerY = stage.stageHeight/2;
grad = new Shape();
gradBmd = new BitmapData(stage.stageWidth, stage.stageHeight);
rect = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
bmd = new BitmapData(rect.width, rect.height, true, 0x00000000);
bmp = new Bitmap(bmd);
blur = new BlurFilter(4, 4, 4);
target = bar;
radius = 200;
rot = 0;
vs = 1.03 * -1;
dm = new DisplacementMapFilter(gradBmd, null, 0, 0, 0, 0, "wrap", 0xFF0000, 1);
//s.load(new URLRequest("http://www.gravomaster.com/alarm/sounds/Travie_Mccoy_Feat_Bruno_millionair_billionaire.mp3"));
//s.load(new URLRequest("http://www.gravomaster.com/alarm/sounds/racegeluid.mp3"));
s.load(new URLRequest("http://94.25.53.133:80/nashe-96")); // Icecast trunk
//s.load(new URLRequest("http://www.gravomaster.com/alarm/sounds/Scooter-MoveYourAss.mp3"));
// s.load(new URLRequest("http://stream.wort-fm.org:8000/high.mp3"));
sc = s.play(9,9888);
addChild(container);
addChild(bar);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
grad.graphics.beginGradientFill(GradientType.LINEAR, [0xFF0000, 0x0000FF], [100, 100], [0, 255]);
grad.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
grad.graphics.endFill();
gradBmd.draw(grad);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
}
private function enterFrameHandler(event:Event):void
{
spectrum();
render()
}
private function spectrum():void
{
var n:Number = 0;
var nn:Number = 255;
ba = new ByteArray();
SoundMixer.computeSpectrum(ba,mode, 1);
bar.graphics.clear();
bar.graphics.lineStyle(1, 0x00ff00);
bar.graphics.moveTo(-1, centerY);
for(var i:int=0; i < 255; i++)
{
n = ba.readFloat()*300;
//write n;
var px:int = offset * i;
bar.graphics.lineTo(px, centerY-n);
}
bar.graphics.lineStyle(1, 0xff0000);
for(var ii:int=255; ii < 512; ii++)
{
nn = ba.readFloat()*300;
//write n;
var pxx:int = offset * ii;
bar.graphics.lineTo(pxx, centerY-nn);
}
//bar.graphics.lineTo(stage.stageWidth, centerY);
}
private function render():void
{
var radian:Number = Math.PI/180 * rot;
var val:Number = Math.sin(radian) * radius;
rot += 1
var r:Number = -2;
var g:Number = Math.abs(val / 10) * -1;
var b:Number = val * 1.5;
container.transform.colorTransform = new ColorTransform(1, 1, 1, 1, r, g, b, 100)
var matrix:Matrix = new Matrix();
matrix.scale(vs, vs);
matrix.tx = (rect.width * vs - rect.width) / 2 * -1;
matrix.ty = (rect.height * vs - rect.height) / 2 * -1;
xRotateAt(matrix, rect.width/2, rect.height/2, 1)
//bmd.draw(stage, matrix);
//bmd.applyFilter(bmd, rect, new Point(), blur);
dm.componentX = rot;
container.filters = [dm];
container.addChild(bmp);
}
private function xRotateAt(m:Matrix, nx:Number, ny:Number, degree:Number):Matrix
{
var point:Point = new Point(nx, ny);
point = m.transformPoint(point);
m.tx -= point.x;
m.ty -= point.y;
m.rotate(degree * (Math.PI/180));
m.tx += point.x;
m.ty += point.y;
return m;
}
private function mouseDownHandler(event:MouseEvent):void
{
mode = !mode;
}
}
}