# Problems with Sound clicking

**URL:** https://forum.kirupa.com/t/problems-with-sound-clicking/286855
**Category:** flash
**Created:** [April 22, 2009, 12:20am UTC](https://forum.kirupa.com/t/problems-with-sound-clicking/286855 "2009-04-22T00:20:12Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![lazarusomega200](https://avatars.discourse-cdn.com/v4/letter/l/d6d6ee/32.png) [@lazarusomega200](https://forum.kirupa.com/u/lazarusomega200)
#### Post date: [April 22, 2009, 12:20am UTC](https://forum.kirupa.com/t/problems-with-sound-clicking/286855/1 "2009-04-22T00:20:12Z")

</div>

[SIZE=5][COLOR=Black]I am having issues with the following code. The audio keeps clicking with each change in the frequency. Can anyone give me a way to stop the clicking?[/COLOR][/SIZE]

* * *

//variables for sound section follows

import flash.events.TimerEvent;  
import flash.utils.Timer;

var AMP\_MULTIPLIER:Number = .25; //amplitude  
var leftfreq:Number = 110; //main frequency

var SAMPLING\_RATE:int = 44100;  
var TWO\_PI:Number = 2\*Math.PI;  
var TWO\_PI\_OVER\_SR:Number = TWO\_PI/SAMPLING\_RATE;  
var leftsound:Sound = new Sound();  
var rightsound:Sound = new Sound();  
var isitleft:Boolean = true;

var trans1:SoundTransform = new SoundTransform(.6,-1);  
var trans2:SoundTransform = new SoundTransform(.6,1);

//variables for light flash follow

var StartingHTZ:Number = 14; //starting frequency in HTZ  
var rightfreq:Number = leftfreq - StartingHTZ;  
var EndingHTZ:Number = 5.5; //ending frequency in HTZ  
var TotalTime:Number = 300 //total time in seconds of sequence displaying flash  
var subflashrate:Number = 50; //number of flashes between eyes  
var increment:Number = (((1000/EndingHTZ/2) - (1000/StartingHTZ/2))/TotalTime);  
var milliseconds:Number = (1000/StartingHTZ/2);  
var curcnt:Number = 300;  
var counter:int = 0;  
var counter2:int = 0;  
var seconds:Number = 0;

var soundchange:Number = (((leftfreq - rightfreq) - EndingHTZ)/TotalTime); //left freq always needs to be higher than right freq for this to work

var duration:Timer = new Timer(1000,TotalTime);  
var flash1:Timer = new Timer(milliseconds,1);  
var maintimer:Timer = new Timer(1000);

//flashing light section

function adjustflashrate(event:TimerEvent):void  
{  
if (isitleft == true)  
{  
leftfreq = leftfreq - soundchange;  
isitleft = false;  
}  
else  
{  
rightfreq = rightfreq + soundchange;  
isitleft = true;  
trace((leftfreq - rightfreq) + " is the HTZ, " + soundchange + " is the change");  
}  
milliseconds = milliseconds + increment;  
flash1.delay = milliseconds;  
}

function flasher(event:TimerEvent):void  
{  
counter2 = counter2 + 1;  
if (counter == 0)  
{  
this.light.alpha = 100;  
counter = counter + 1;  
}  
else  
{  
this.light.alpha = 0;  
counter = 0;  
}  
flash1.start();  
}

//sound section

function sineWave1(event:SampleDataEvent):void {  
var sample:Number  
for (var i:int=0; i\<8192; i++) {  
sample = Math.sin((i+event.position) \* TWO\_PI\_OVER\_SR \* leftfreq);  
event.data.writeFloat(sample \* AMP\_MULTIPLIER);  
event.data.writeFloat(sample \* AMP\_MULTIPLIER);  
}  
}

function sineWave2(event:SampleDataEvent):void {  
var sample:Number  
for (var i:int=0; i\<8192; i++) {  
sample = Math.sin((i+event.position) \* TWO\_PI\_OVER\_SR \* rightfreq);  
event.data.writeFloat(sample \* AMP\_MULTIPLIER);  
event.data.writeFloat(sample \* AMP\_MULTIPLIER);  
}  
}

leftsound.addEventListener(SampleDataEvent.SAMPLE\_DATA, sineWave1);  
rightsound.addEventListener(SampleDataEvent.SAMPLE\_DATA, sineWave2);  
flash1.addEventListener(TimerEvent.TIMER\_COMPLETE, flasher);  
duration.addEventListener(TimerEvent.TIMER,adjustflashrate);

flash1.start();  
leftsound.play(0, 1, trans1);  
rightsound.play(0,1,trans2);

* * *
