# Control volume of the player - crackling noise

**URL:** <https://forum.kirupa.com/t/control-volume-of-the-player-crackling-noise/327604>\
**Category:** Uncategorized\
**Created:** [March 13, 2012, 9:31pm UTC](https://forum.kirupa.com/t/control-volume-of-the-player-crackling-noise/327604 "2012-03-13T21:31:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![drpelz](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@drpelz](https://forum.kirupa.com/u/drpelz)\
**Post date:** [March 13, 2012, 9:31pm UTC](https://forum.kirupa.com/t/control-volume-of-the-player-crackling-noise/327604/1 "2012-03-13T21:31:58Z")

</div>

Hi there,

I want that my spaceship gets louder when my mouse moves away from it (and vice versa). Problem is that my function produces an annoying crackling sound I can’t get rid of when I move my mouse away from it (and vice versa). The sound file is ok so far. Can someone help me out with this problem, please?

```auto

shipSpeed = (abs(player.x - playerPrevPt.x) + abs(player.y - playerPrevPt.y)) / 2;//the ship's speed gets calculated
                
    //this is used to determine whether the ship's volume of its sound shall be increased or decreased
    if (shipSpeedPrev < shipSpeed) {
        sndManager.increaseSound(Main.SOUND_BACKGROUND, false, .01);
        } else if (shipSpeedPrev > shipSpeed) {
        sndManager.decreaseSound(Main.SOUND_BACKGROUND, false, .01);
        } else if (shipSpeedPrev == shipSpeed) {
        
        } else {
        
    }
                
    shipSpeedPrev = (abs(player.x - playerPrevPt.x) + abs(player.y - playerPrevPt.y)) / 2;//this is another ship speed so I can compare them

```

//the decreseSound-function is almost the same

```auto

public function increaseSound(soundName:String, isSoundTrack:Boolean = false, steps:Number = .1, targetVol:Number = 1):void {
            if (isSoundTrack) {
                if (soundTrackChannel != null) {
                    musicVolumeAdj.volume += steps;
                    if (musicVolumeAdj.volume >= targetVol) {
                        musicVolumeAdj.volume = targetVol;
                    }
                    soundTrackChannel.soundTransform = musicVolumeAdj;
                }
            } else {
                soundVolumeAdj = new SoundTransform(incrSndVal, 0);
                incrSndVal += steps;
                soundVolumeAdj.volume += incrSndVal;
                if (soundVolumeAdj.volume >= 1) {
                    soundVolumeAdj.volume = 1;
                }
                soundChannels[soundName].soundTransform = soundVolumeAdj;
                //trace("soundVolumeAdj.volume " + soundVolumeIncrAdj.volume);
            }
        }

```
