# I need help with visualizer (SoundMixer.computeSpectrum)

**URL:** <https://forum.kirupa.com/t/i-need-help-with-visualizer-soundmixer-computespectrum/297115>\
**Category:** flash\
**Created:** [September 25, 2009, 8:41pm UTC](https://forum.kirupa.com/t/i-need-help-with-visualizer-soundmixer-computespectrum/297115 "2009-09-25T20:41:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wonsong82](https://avatars.discourse-cdn.com/v4/letter/w/22d042/32.png) [@wonsong82](https://forum.kirupa.com/u/wonsong82)\
**Post date:** [September 25, 2009, 8:41pm UTC](https://forum.kirupa.com/t/i-need-help-with-visualizer-soundmixer-computespectrum/297115/1 "2009-09-25T20:41:46Z")

</div>

[http://www.karaokeboho.com/index2.html](http://www.karaokeboho.com/index2.html)

this is the site im currenlty developing and the visualizer runs as a background

sometimes gets an error and wouldnt continue playing!!

here is the code for the visualizer.

```auto

//Visualizer.as

package 
{
    import flash.display.*;
    import flash.media.*; // need for sound, soundmixer
    import flash.net.*; // need for urlrequest
    import flash.events.*;
    import flash.utils.*; // need for bytearray
    import flash.filters.*;
    
    public class Visualizer extends Sprite
    {        
        private var ba:ByteArray = new ByteArray();
        
        private var lineThickness:Number;
        private var lineColor:Number;
        private var circleSize:Number;
        private var timer:Timer;
        private var type:String;
        
        private var scaleOnBeat:Number = 1.2;
        private var reactToBeat:Number = 50;    
        
        private var added:Boolean;
        
        function Visualizer(param:Object) // param : color, size, thinkness, blur
        {            
            lineColor = param.color;
            lineThickness = param.thickness;
            circleSize = param.size;
                        
            if (param.blur != null){
                this.filters = [new BlurFilter(param.blur,param.blur, BitmapFilterQuality.HIGH)];
            }
            
            this.addEventListener(Event.ADDED_TO_STAGE, init);
            this.addEventListener(Event.REMOVED_FROM_STAGE, removed);
        }
        
        private function init(e:Event):void
        {
            added = true;
        }
        
        private function removed(e:Event):void
        {
            this.removeEventListener(Event.ADDED_TO_STAGE, init);
            this.removeEventListener(Event.REMOVED_FROM_STAGE, removed);
            timer.removeEventListener(TimerEvent.TIMER, processBar);
            timer.removeEventListener(TimerEvent.TIMER, processCircle);
        }
        
        private function processCircle(e:Event):void
        {
            if (added){
                
                SoundMixer.computeSpectrum(ba, false, 0);            
                
                this.graphics.clear();
                this.graphics.moveTo(0, -circleSize);
                this.graphics.lineStyle(lineThickness,lineColor);
                var vol:Number = 0;
                for (var i:uint = 0; i <512; i += 1){                
                    var lev:Number = ba.readFloat();
                    vol += lev;
                    var a:uint = i;
                    if (i < 256) a += 256;
                    if (i == 256) graphics.moveTo(0, -circleSize);
                    graphics.lineTo(-Math.sin(i/256*Math.PI) * circleSize * (lev+1),
                                    Math.cos(a/256*Math.PI) * circleSize * (lev+1));                
                }
                if (vol>reactToBeat){
                    this.scaleX = this.scaleY = scaleOnBeat;
                } else {
                    this.scaleX = this.scaleY = 1;
                }
            
            }
        }
        
        private function processBar(e:Event):void
        {
            if (added){
            
                SoundMixer.computeSpectrum(ba, false, 0);
                
                this.graphics.clear();            
                this.graphics.lineStyle(lineThickness, lineColor);
                this.graphics.moveTo(0,0);
                var vol:Number = 0;
                for (var i:uint=0; i <512; i+=1){
                    var lev:Number = ba.readFloat();
                    vol += lev;
                    var n:Number = (lev * 100);
                    graphics.lineTo(i*1.5, n);
                }
                if (vol>reactToBeat){
                    this.scaleY = scaleOnBeat;
                } else {
                    this.scaleY = 1;
                }
            
            }
        }
        
        public function changeColor(color:Number):void
        {
            lineColor = color;
        }
        
        public function playBar():void
        {                
            type = "bar";
            try {timer.reset();} catch(e:Error){}
            timer = null;
            timer = new Timer(50);
            timer.addEventListener(TimerEvent.TIMER, processBar);
            timer.start();
            
        }
        
        public function playCircle():void
        {
            type = "circle";
            try {timer.reset();} catch(e:Error){}
            timer = null;
            timer = new Timer(50);
            timer.addEventListener(TimerEvent.TIMER, processCircle);
            timer.start();
            
        }
        
        public function getName():String
        {
            return type;
        }
        
        public function hide():void
        {            
            try {timer.removeEventListener(TimerEvent.TIMER, processBar);} catch(e:Error){}
            try {timer.removeEventListener(TimerEvent.TIMER, processCircle);} catch(e:Error){}
            this.graphics.clear();
        }
    
    }    
}

```

**2030** End of file was encountered.

this was the error i got last time i checked it.
