private AudioRecord startMicRecording(int sampleRate, int channel, int encoding) {
   appendLogTextView(mHandler, "start recording...\n");
   int recordBufSize = AudioRecord.getMinBufferSize(sampleRate, channel, encoding);
   AudioRecord record =
       new AudioRecord(
           MediaRecorder.AudioSource.MIC, sampleRate, channel, encoding, recordBufSize);
   appendLogTextView(mHandler, " -> sample rate: " + sampleRate + "\n");
   appendLogTextView(mHandler, " -> buffer size:" + recordBufSize + "\n");
   int sid = record.getAudioSessionId();
   if (false) {
     appendLogTextView(mHandler, " -> do not use AEC.\n");
   } else {
     AcousticEchoCanceler aec = AcousticEchoCanceler.create(sid);
     if (aec == null) {
       appendLogTextView(mHandler, " -> create AEC error.\n");
     } else {
       appendLogTextView(mHandler, " > create AEC ok.\n");
     }
   }
   record.startRecording();
   appendLogTextView(mHandler, "start recording ok.\n");
   return record;
 }
    /** Configures echo cancellation and noise suppression effects. */
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    private void configureEffects() {
      if (!AndroidUtils.hasAPI(16)) return;

      AudioSystem audioSystem =
          AudioSystem.getAudioSystem(AudioSystem.LOCATOR_PROTOCOL_AUDIORECORD);

      // Creates echo canceler if available
      if (AcousticEchoCanceler.isAvailable()) {
        AcousticEchoCanceler echoCanceller =
            AcousticEchoCanceler.create(audioRecord.getAudioSessionId());
        if (echoCanceller != null) {
          echoCanceller.setEnableStatusListener(this);
          echoCanceller.setEnabled(audioSystem.isEchoCancel());
          logger.info("Echo cancellation: " + echoCanceller.getEnabled());
        }
      }

      // Automatic gain control
      if (AutomaticGainControl.isAvailable()) {
        AutomaticGainControl agc = AutomaticGainControl.create(audioRecord.getAudioSessionId());
        if (agc != null) {
          agc.setEnableStatusListener(this);
          agc.setEnabled(audioSystem.isAutomaticGainControl());
          logger.info("Auto gain control: " + agc.getEnabled());
        }
      }

      // Creates noise suppressor if available
      if (NoiseSuppressor.isAvailable()) {
        NoiseSuppressor noiseSuppressor = NoiseSuppressor.create(audioRecord.getAudioSessionId());
        if (noiseSuppressor != null) {
          noiseSuppressor.setEnableStatusListener(this);
          noiseSuppressor.setEnabled(audioSystem.isDenoise());
          logger.info("Noise suppressor: " + noiseSuppressor.getEnabled());
        }
      }
    }
 private boolean isAcousticEchoCancelerSupported() {
   return AcousticEchoCanceler.isAvailable();
 }