title: PCM Wave file - stereo to mono
body: <p>I have an audio file which is stereo. Is converting it to mono just a case of skipping every other byte (after the header)? It's encoded in 16bit signed PCM format. I've got <code>javax.sound.sampled</code> available.</p>
  
  <p>Here's code I tried that didn't work:</p>
  
  <pre><code>WaveFileWriter wfw = new WaveFileWriter();
  AudioFormat format = new AudioFormat(Encoding.PCM_SIGNED, 44100, 16, 2, 2, 44100, false);
  AudioFormat monoFormat = new AudioFormat(Encoding.PCM_SIGNED, 44100, 16, 1, 2, 44100, false);
  
  byte[] audioData = dataout.toByteArray();
  int length = audioData.length;
  ByteArrayInputStream bais = new ByteArrayInputStream(audioData);
  
  AudioInputStream stereoStream = new AudioInputStream(bais,format,length);
  AudioInputStream monoStream = new AudioInputStream(stereoStream,format,length/2);
  
  wfw.write(monoStream, Type.WAVE, new File(Environment.
                   getExternalStorageDirectory().getAbsolutePath()+"/stegDroid/un-ogged.wav"));
  </code></pre>
  
  <p>This code is used after reading a <code>.ogg</code> file using Jorbis to convert it to PCM data. The only problem is the result is stereo and I need it to be mono, so if there's another solution I'm happy to hear it!</p>