2007年12月10日月曜日

sound spectrum



Actionscript: SoundMixer.computeSpectrum()
Source: The Flash blog[link]

Action Sclipt video tutorial[link]

//////////////////////code sample /////////////////////////
  1. var s:Sound = new Sound();
  2. var sc:SoundChannel;
  3. var ba:ByteArray = new ByteArray();
  4. var array:Array;
  5. s.load(new URLRequest("mix.mp3"));
  6. sc = s.play(0,1000);
  7. this.addEventListener(Event.ENTER_FRAME, spectrum);
  8. var a:Number = 0;
  9. function spectrum(event:Event)
  10. {
  11. a = 0;
  12. graphics.clear();
  13. SoundMixer.computeSpectrum(ba,true,0);
  14. for(var i=0; i <256; i=i+8)
  15. {
  16. a = ba.readFloat();
  17. var num:Number = a*360;
  18. graphics.lineStyle(num/15,0x0066FF|(num <<8));
  19. graphics.drawCircle(stage.stageWidth/2,stage.stageHeight/2,i);
  20. }
  21. }

0 件のコメント: