title: Creating a stereo WAV file using C
body: <p>I am looking at creating a <code>WAV file</code> in C and have seen an example <a href="http://karplus4arduino.wordpress.com/2011/10/08/making-wav-files-from-c-programs/" rel="noreferrer">here</a>.</p>
  
  <p>This looks good, but I'm interested in adding two buffers to make the audio stereo <strong>(the possibility to have different sound in each ear)</strong>. If I set the number of channels to two, the audio plays out of the left channel only (which apparently is right, as the left channel is the first channel). I have read I must interleave it with the right channel.</p>
  
  <p>Unfortunately I haven't found much online to help create a stereo WAV. </p>
  
  <pre><code>write_little_endian((unsigned int)(data[i]),bytes_per_sample, wav_file); 
  </code></pre>
  
  <p>I've tried to create a second buffer, with half the amplitude to see if I could interleave. </p>
  
  <pre><code>for (j=0; i&lt;BUF_SIZE; i++) {
      phase +=freq_radians_per_sample;
      buffertwo[i] = (int)((amplitude/2) * sin(phase));;
      }
  
  write_wav("test.wav", BUF_SIZE, buffer, buffertwo, S_RATE);
  </code></pre>
  
  <p>(changing the function to take two short integer buffers)</p>
  
  <p>And just doing</p>
  
  <pre><code>    write_little_endian((unsigned int)(data[i]),bytes_per_sample, wav_file);
      write_little_endian((unsigned int)(datatwo[i]),bytes_per_sample, wav_file);
  </code></pre>
  
  <p>But that does not work. That should in theory be interleaved.</p>