title: AudioRecord and AudioTrack echo
body: <p>I'm streaming the mic audio between two devices, everything is working but i have a bad echo.</p>
  
  <p>Here what i'm doing</p>
  
  <p>Reading thread</p>
  
  <pre><code>int sampleFreq = 22050; 
          int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_MONO;
          int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
          int minBuffer = 2*AudioTrack.getMinBufferSize(sampleFreq, channelConfig, audioFormat);
  
          AudioTrack atrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                          sampleFreq,
                          channelConfig,
                          audioFormat,
                          minBuffer,
                          AudioTrack.MODE_STREAM);
          atrack.play();
  
          byte[] buffer = new byte[minBuffer];
          while (true) {
              try {                
                  // Read from the InputStream                
                  bytes = mmInStream.read(buffer);                    
                  atrack.write(buffer, 0, buffer.length);
                  atrack.flush();                         
              } catch (IOException e) {
                  Log.e(TAG, "disconnected", e);
                  break;
              }
          }
  </code></pre>
  
  <p>Here the recording thread</p>
  
  <pre><code>int sampleRate = 22050; 
      int channelMode = AudioFormat.CHANNEL_CONFIGURATION_MONO;
      int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
      int buffersize = 2*AudioTrack.getMinBufferSize(sampleRate, channelMode, audioFormat);
  
      AudioRecord arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
              sampleRate, channelMode,
              AudioFormat.ENCODING_PCM_16BIT, buffersize);
  
      buffer = new byte[buffersize];
      arec.startRecording();
  
      while (true) {  
          arec.read(buffer, 0, buffersize);
          new Thread( new Runnable(){
              @Override
              public void run() {
                  try {               
                      mOutputStream.write(buffer);
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }                   
              }               
          }).start();
      }
  </code></pre>
  
  <p>Am I doing something wrong?</p>