title: Android AudioRecord with CHANNEL_IN_STEREO read raw Audio buffer resulted in mixed Left and Right audio
body: <p>I am trying to record an audio with CHANNEL_IN_STEREO configuration in which I am telling audio recorded to record audio in two channel. But after storing buffer array from recorder Audio left channel  and right channel is resulting as mix. I cannot separate Audio Left channel and Right channel.</p>
  <p>Below is code written for same :</p>
  <pre><code>import androidx.appcompat.app.AppCompatActivity;
  
  import android.media.AudioFormat;
  import android.media.AudioRecord;
  import android.media.MediaRecorder;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  
      import java.io.ByteArrayOutputStream;
      import java.io.DataOutputStream;
      import java.io.File;
      import java.io.FileNotFoundException;
      import java.io.FileOutputStream;
      import java.io.IOException;
      
      public class MainActivity extends AppCompatActivity {
          AudioRecord record;
          Boolean status = true;
          private int sampleRate = 44100;
          private int channelConfig = AudioFormat.CHANNEL_IN_STEREO;
          private int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
          int minBufSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
          byte buffer[] = new byte[8916];
          ByteArrayOutputStream leftbaos;
          ByteArrayOutputStream rightbaos;
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              Button start = findViewById(R.id.start);
              Button stop = findViewById(R.id.stop);
              leftbaos = new ByteArrayOutputStream();
              rightbaos = new ByteArrayOutputStream();
              start.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      startRecorder();
                  }
              });
      
              stop.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      stopRecorder();
      
                  }
              });
          }
      
          private void startRecorder() {
              status = true;
              record = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, channelConfig, audioFormat, minBufSize);
              Thread streamThread = new Thread(new Runnable() {
      
                  @Override
                  public void run() {
                      try {
      
      
                          record.startRecording();
                          while (status == true) {
      
                              int recorded_int  = record.read(buffer, 0, minBufSize);
                              byte leftChannelAudioData[] = new byte[buffer.length/2];
                              byte rightChannelAudioData[] = new byte[buffer.length/2];
                              for(int i = 0; i &lt; buffer.length/2; i = i + 1)
                              {
                                  leftChannelAudioData[i] = buffer[2*i];
                                  rightChannelAudioData[i] =  buffer[2*i+1];
      
                              }
                              leftbaos.write(leftChannelAudioData,0,recorded_int/2);
                              rightbaos.write(rightChannelAudioData,0,recorded_int/2);
      
      
                          }
      
                      } catch(Exception e) {
                      }
                  }
              });
              streamThread.start();
          }
          private void stopRecorder() {
              status = false;
              if(record!= null) {
                  //storing left channel audio
                  send(leftbaos,&quot;/mydirectory/left.pcm&quot;);
                  //storing right channel audio
                  send(rightbaos,&quot;/mydirectory/right.pcm&quot;);
                  record.stop();
                  record.release();
              }
          }
      
          private void send(ByteArrayOutputStream baos,String path) {
              File file = new File(path);
      
      
              try {
                  FileOutputStream out = new FileOutputStream(file);
                  baos.writeTo(out);
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      
      
      
      }
  </code></pre>
  <p>I have Used below mentioned permission</p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot; /&gt;
  </code></pre>
  <p>In above code I am storing <code>ByteArrayOutputStream</code> in PCM file once recording gets stopped.
  How can I separate Audio Left channel and Right channel from Audio Record.</p>