title: Playing a wav file in Android using AudioTrack: noisy sound
body: <p>To produce sound on Android, I am using <code>AudioTrack</code>.</p>
  
  <p>I have been able to produce sine waves, sawtooth waves, square waves but it would be nice to have a more realistic sound.</p>
  
  <p>I found that <code>.wav</code> files were the easiest to play on <code>AudioTrack</code> because they are basically just a sequence of bytes with a header.</p>
  
  <p>So I have got my wav file in the <code>res/raw</code> folder and I tried playing it with this code :</p>
  
  <pre><code>public void writeWav(){
    byte[] byteData = null;
    InputStream is = getResources().openRawResource(R.raw.high);
    byteData = new byte[mBufferSize];
    try {
      is.read(byteData);
      is.close();
    }
    catch (FileNotFoundException e) {}
    catch (IOException e) {}
  
    mAudioTrack.write(byteData, 0, byteData.length);
  }
  </code></pre>
  
  <p>But all I get is noise. I realize there are lots of questions about <code>AudioTrack</code> and wav files, but I couldn't find an answer to my noise problem.</p>