Why won't my sawtooth test tone play?
<p>Should I not make it in a for loop that cycle's the sample length? I don't understand why it plays the sine wave formula but not the saw wave... This is modified from a beep class that is stuctured quite similarly, perhaps it is the for loop in the middle that generate too mamy rounds to get the sawtooth shape. What do you think? Here is my code:</p>

<pre><code>class MakeSaw
{

  static void makeSaw(double f, int t) throws Exception
  {

    int nChannel = 1;         // number of channel : 1 or 2

    // samples per second
    float sampleRate = 16000;  // valid:8000,11025,16000,22050,44100
    int nBit = 16;             // 8 bit or 16 bit sample

    int bytesPerSample = nChannel*nBit/8;


    int bufferSize = (int) (nChannel*sampleRate*t*bytesPerSample);
    byte[] audioData = new byte[bufferSize];

    // "type cast" to ShortBuffer
    java.nio.ByteBuffer byteBuffer = java.nio.ByteBuffer.wrap(audioData);
    java.nio.ShortBuffer shortBuffer = byteBuffer.asShortBuffer();


    int sampleLength = audioData.length/bytesPerSample;

    // generate the wave
    double volume = 8192;   // 0-32767
    double PI = Math.PI;
    double sawWave=0;


        //make saw wave
        for(int i = 0; i &lt; sampleLength; i++)
        {
            double time = i/sampleRate;
            sawWave = sawWave + Math.sin(2*PI*f*(i*t)/i);    //passing amplitude frequency and time
            short amplitude = (short) (volume*sawWave);

            for (int c=0;c&lt;1;c++) //repeat once because audio playing on one channel
            {
                shortBuffer.put(amplitude);
            }
        }

    //end wave making//end generating sound wave sample


    boolean isSigned=true;
    boolean isBigEndian=true;

    // Define audio format
    javax.sound.sampled.AudioFormat audioFormat =
      new javax.sound.sampled.AudioFormat(sampleRate, nBit, nChannel, isSigned,isBigEndian);


    javax.sound.sampled.DataLine.Info dataLineInfo =
      new javax.sound.sampled.DataLine.Info(
         javax.sound.sampled.SourceDataLine.class, audioFormat);

    // get the SourceDataLine object
    javax.sound.sampled.SourceDataLine sourceDataLine = 
      (javax.sound.sampled.SourceDataLine)
      javax.sound.sampled.AudioSystem.getLine(dataLineInfo);

    sourceDataLine.open(audioFormat);
    sourceDataLine.start();

    // actually play the sound
    sourceDataLine.write(audioData,0,audioData.length);

    // "flush",  wait until the sound is completed
    sourceDataLine.drain();

  }


  public static void main(String[] args) throws Exception
  {

    makeSaw(400,2);
  }
}
</code></pre>
