title: Converting mono to stereo sound
body: <p>I am trying to convert a 16bit mono sound to stereo. The sound is stored as a byte array, so to my understanding that means I duplicate two bytes at a time. </p>
  
  <p><img src="https://i.stack.imgur.com/YjEmP.jpg" alt="enter image description here"></p>
  
  <p>Am I doing this right? The code I produced changes the frequency.</p>
  
  <p>EDIT: </p>
  
  <p>I am successfully generating a mono tone and storing it in <code>byte [] generatedSnd</code></p>
  
  <p>Playing the mono sound (working): </p>
  
  <pre><code>    AudioTrack audioTrack = null;                                   // Get audio track
      try {
          audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                  sampleRate, AudioFormat.CHANNEL_OUT_MONO,
                  AudioFormat.ENCODING_PCM_16BIT, (int)numSamples*2,
                  AudioTrack.MODE_STATIC);
          audioTrack.setStereoVolume(0f, 1f);
          audioTrack.write(generatedSnd, 0, generatedSnd.length);     // Load the track
          audioTrack.play();                                          // Play the track
      }
      catch (Exception e){ }
  </code></pre>
  
  <p>Converting to stereo sound: </p>
  
  <pre><code>    int monoByteArrayLength = generatedSnd.length;
      byte [] stereoGeneratedSnd = new byte[monoByteArrayLength * 2];
  
      stereoGeneratedSnd[0] = generatedSnd[0];
      stereoGeneratedSnd[2] = generatedSnd[0];
  
      for (int x=1; x&lt;monoByteArrayLength; x+=2) {
  
          stereoGeneratedSnd[x*2-1] = generatedSnd[x];
          stereoGeneratedSnd[x*2+1] = generatedSnd[x];
  
          if (x+1 &lt; monoByteArrayLength) {
              stereoGeneratedSnd[x*2] = generatedSnd[x+1];
              stereoGeneratedSnd[x*2+2] = generatedSnd[x+1];
          }
      }
  
      AudioTrack audioTrack = null;                                   // Get audio track
      try {
          audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                  sampleRate, AudioFormat.CHANNEL_OUT_STEREO,
                  AudioFormat.ENCODING_PCM_16BIT, (int)numSamples*2,
                  AudioTrack.MODE_STATIC);
          audioTrack.setStereoVolume(0f, 1f);
          audioTrack.write(stereoGeneratedSnd, 0, stereoGeneratedSnd.length);     // Load the track
          audioTrack.play();                                          // Play the track
      }
      catch (Exception e){ }
  </code></pre>
  
  <p>What I am trying to do is play the sound out of only one channel</p>