title: How create .wav file with a custom frequency tone / wave?
body: <p>I have a problem with my wave generator. I'm trying to create a .wav file with sound of given frequency. The code I use:</p>
  
  <pre><code>$freqOfTone = 21000;
  $sampleRate = 44100;
  $samplesCount = 80000;
  
  $amplitude = 0.25 * 32768;
  $w = 2 * pi() * $freqOfTone / $sampleRate;
  
  for ($n = 0; $n &lt; $samplesCount; $n++)
  {
      $data-&gt;samples[1][] = 32768 + (int)($amplitude *  sin($n * $w));
  }
  </code></pre>
  
  <p>Unfortunately, the output wave is incorrect, I get few frequencies instead of one: <a href="http://i49.tinypic.com/ab1nx0.png" rel="nofollow">http://i49.tinypic.com/ab1nx0.png</a></p>
  
  <p>It should look like this:
  <a href="http://i50.tinypic.com/33zbslk.png" rel="nofollow">http://i50.tinypic.com/33zbslk.png</a></p>
  
  <p>Where am I doing something wrong? :(</p>