title: Audio Streaming and getting the Amplitude to draw Waveform same time
body: <p>I am trying to stream and getting amplitude to draw waveform. When I stream and comment the code to get amplitude its works fine. I guess the problem is that audioRecord.read() which is called by streaming as well as amplitude method separately. Once it is called in  read() method and next in getAmplitude() method. I looking for a way in which both stream and amplitude work together. With existed  code there is a skipping in streaming. Below is the code:</p>
  
  <pre><code>public void start() {
    if (isCreated()) {
      init();
      new Thread(new Runnable() {
        @Override
        public void run() {
          while (running &amp;&amp; !Thread.interrupted()) {
            DataTaken dataTaken = read();
            if (dataTaken != null) {
              Log.e("amplitude ",getAmplitude()+"");
              amplitude = getAmplitude();
              getMicrophoneData.inputPCMData(dataTaken.getPcmBuffer(), dataTaken.getSize());
            } else {
              running = false;
            }
          }
        }
      }).start();
    } else {
      Log.e(TAG, "Microphone no created, MicrophoneManager not enabled");
    }
  } 
  
    private DataTaken read() {
      int size;
      if (muted) {
        size = audioRecord.read(pcmBufferMuted, 0, pcmBufferMuted.length);
      } else {
        size = audioRecord.read(pcmBuffer, 0, pcmBuffer.length);
      }
      if (size &lt;= 0) {
        return null;
      }
      return new DataTaken(pcmBuffer, size);
  }
  
  public double getAmplitude() {
    if(audioRecord != null) {
      short[] buffer = new short[getPcmBufferSize()];
      audioRecord.read(buffer, 0, getPcmBufferSize());
      int max = 0;
      for (short s : buffer) {
        if (Math.abs(s) &gt; max) {
          max = Math.abs(s);
        }
      }
      return max;
    }else{
      return 0;
    }
  }
  
  public class DataTaken {
  
    private byte[] pcmBuffer;
    private int size;
  
    public DataTaken(byte[] pcmBuffer, int size) {
      this.pcmBuffer = pcmBuffer;
      this.size = size;
    }
  
    public byte[] getPcmBuffer() {
      return pcmBuffer;
    }
  
    public void setPcmBuffer(byte[] pcmBuffer) {
      this.pcmBuffer = pcmBuffer;
    }
  
    public int getSize() {
      return size;
    }
  
    public void setSize(int size) {
      this.size = size;
    }
  }
  </code></pre>