PHP罪恶功能上升

I am generating a wav wobble tone in php with this function:

$samples = array();
$amplitude = 8192;
$sampleRate = 8000;
$samplesCount = 300000;


for ($n = 0; $n < $samplesCount; $n++) {


    $freqOfTone= 4*sin($n*0.00628)+440;

    $w = 2 * pi() * $freqOfTone / $sampleRate;
    $samples[$n] = (int)($amplitude *  sin($n * $w));



}

But the generated sound is not a constant wobble but goes up... (As you can hear there: Sound Link

Does anyone know why ?

Thank you

Doesn't quite solve the problem the same way, but I spent some time playing with the weird math corners of the internet to help get the trig rust off. This helped put it into perspective for me.

At anyrate, here's what I was playing around with (both amp and fm mod, I could screw with this for hours):

<?php   

$bps = 16; // bits/s
$Bps = $bps / 8; // byte/s
$duration = 30; // Seconds
$frequency = 440; // Hz
$amplitude = 8192;  

$samples = array();
$sampleRate = 44100;
$samplesCount = $sampleRate * $duration;    

for ($n = 0; $n <= $samplesCount; $n++)
{
    // Time
    $t = $n / $sampleRate;  

    // Freq Mod
    $mod = 0.1 * sin(2 * M_PI * $frequency * $t * 0.00628); 

    // Wave
    $w = $amplitude * sin(2 * M_PI * $frequency * ($t + $mod)); 

    // Amplitude Mod
    ($n / ($sampleRate / 10) % 2 == 0) ? $amplitude-- : $amplitude++;   

    $samples[] = (int)$w;
}   

$str = call_user_func_array("pack",
    array_merge(array("VVVVVvvVVvvVVv*"),
        array(// header
            0x46464952, // RIFF
            ($samplesCount * 2) + 44 - 8, // Filesize
            0x45564157, // WAVE
            0x20746d66, // "fmt " (chunk)
            16, // chunk size
            1, // compression (2 byte iteger)
            1, // nchannels
            $sampleRate, // sample rate
            $sampleRate * $Bps, //bytes/second
            $Bps, //block align
            $bps, //bits/sample
            0x61746164, //"data"
            $samplesCount * 2 // samples * compressed int
        ),
        $samples //data
    )
);  

// echo print_r($samples) . PHP_EOL;
$myfile = fopen("/tmp/sine.wav", "wb") or die("Unable to open file!");
fwrite($myfile, $str);
fclose($myfile);