Skip navigation
Currently Being Moderated

Transform sound problem

May 24, 2012 8:09 PM

I am trying to play recorded sound on my app. I recorded it by timing the time between player clicks on the instruments and the title of the sound. I am playing it with timers thet are set to the time between clicks that was recorded(to mach player clicking time).

 

When I play the sound not through a channel and sound transform it works fine.

 

I added a volume slider and a channel, and I am playing all sounds through that channel.  The volume changes fine when i drag the slider but there is a ticking sound every time a sound is played, like it started at 100% volume and transformed to the actual volume after the first frame is played.

 

the code:

 

var guitarArray:Array = new Array;

 

var guitarChannel:SoundChannel = new SoundChannel();

 

var string1_mixer:Sound = new Sound();

string1_mixer.load(new URLRequest("sounds/string1.mp3"));

var string2_mixer:Sound = new Sound();

string2_mixer.load(new URLRequest("sounds/string2.mp3"));

var string3_mixer:Sound = new Sound();

string3_mixer.load(new URLRequest("sounds/string3.mp3"));

var string4_mixer:Sound = new Sound();

string4_mixer.load(new URLRequest("sounds/string4.mp3"));

var string5_mixer:Sound = new Sound();

string5_mixer.load(new URLRequest("sounds/string5.mp3"));

var string6_mixer:Sound = new Sound();

string6_mixer.load(new URLRequest("sounds/string6.mp3"));

 

 

 

// function gets recorded array if even contains time if odd comtains sound name (string)

function addArrays(guitar_array:Array):void{

     guitarArray = guitar_array;

}

 

 

mixerPlay_btn.addEventListener(MouseEvent.CLICK, playAllArrays);

 

// play was clicked

function playAllArrays(e:MouseEvent):void{

     playGuitar_mixer();

}

 

 

 

 

////////////////////////   Volume    //////////////////////////////////////

 

drag_guitar_btn.addEventListener(MouseEvent.MOUSE_DOWN, changeGuitarVol);

drag_guitar_btn.addEventListener(MouseEvent.MOUSE_UP, stop_changeGuitarVol);

 

var guitar_slider_length:Number = slider_guitar.width;

 

var guitar_boundingBox:Rectangle=new Rectangle(slider_guitar.x,slider_guitar.y,guitar_slider_length,0);

 

var guitar_dragging:Boolean=false;

 

drag_guitar_btn.buttonMode = true;

 

 

function changeGuitarVol(e:MouseEvent):void{

     drag_guitar_btn.startDrag(false, guitar_boundingBox);

    guitar_dragging=true;

    drag_guitar_btn.addEventListener(Event.ENTER_FRAME, adjustVolume_guitar);

}

 

 

function stop_changeGuitarVol(e:MouseEvent):void{

    if (guitar_dragging) {

        drag_guitar_btn.stopDrag();

        guitar_dragging=false;

    }  

}

 

 

function adjustVolume_guitar(myEvent:Event):void {

    var guitar_Volume:Number=(drag_guitar_btn.x-964.6)/guitar_slider_length;

    var guitarTransform:SoundTransform=new SoundTransform(guitar_Volume);

    if (guitarChannel!=null) {

        guitarChannel.soundTransform=guitarTransform;

    }

}

 

//////////////////////   Guitar   /////////////////////////////////////////

function playGuitar_mixer():void{

      if(guitarArray!=null){

          var counter_guitar:Number = 0;

          soundaddGuitar();

 

          //function add timer if counter_guiter%2 = 0, else it plays sound acording to content(string), execute as long as counter_guitar<guitarArray length, recursive

          function soundaddGuitar():void{

               if(counter_guitar<guitarArray.length){

                        if(counter_guitar%2 == 0){

                              if(guitarArray[counter_guitar]!=null){                                 

                                   var timerloopGuitar2:Timer = new Timer(guitarArray[counter_guitar]*10,1);

                                   timerloopGuitar2.start();

                                   trace(guitarArray[counter_guitar]);

                                   trace(counter_guitar);

                                   trace(timerloopGuitar2.currentCount);

                                   timerloopGuitar2.addEventListener(TimerEvent.TIMER_COMPLETE, playSound);

                              }

 

 

                         }

                    }

               }

               else{

                    trace('END OF LOOP');

                    trace('array length ' + guitarArray.length);

                    trace('i = ' + counter_guitar);

               }

          }

 

     }

     //plays sound if guitar_counter is odd

     function playSound(t:TimerEvent):void{

            if(guitarArray[counter_guitar+1] != null){

               if(guitarArray[counter_guitar+1] == 'string1_sound'){

                    guitarChannel = string1_mixer.play();

                  }

               if(guitarArray[counter_guitar+1] == 'string2_sound'){

                    guitarChannel = string2_mixer.play();

                  }

               if(guitarArray[counter_guitar+1] == 'string3_sound'){

                    guitarChannel = string3_mixer.play();

                  }

               if(guitarArray[counter_guitar+1] == 'string4_sound'){

                    guitarChannel = string4_mixer.play();

                  }

               if(guitarArray[counter_guitar+1] == 'string5_sound'){

                    guitarChannel = string5_mixer.play();

                  }

               if(guitarArray[counter_guitar+1] == 'string6_sound'){

                    guitarChannel = string6_mixer.play();

                  }

          }

          counter_guitar= counter_guitar+2;

          soundaddGuitar();

     }

}

 

 

 

 

sorry if its long, can't specify a place in the code.

any help would be appreciated.

 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points