title: android AudioRecord amplitude reading from MIC
body: <p>I am trying to record the sound from the MIC and draw a live graph. I am able to record and draw the graph. The problem is the values that are recorded using the code below are not accurate for example ... the image below is what i get when there is no sound at all present. I have seen examples using the fft but I am noot sure if that will be of any help in my case as I am trying to draw a time domain graph and I see no purpose to convert it to frequency domain (for now). Others are using average power, this might be helpful but I am not sure.</p>
  
  <p>Thanks for any help.</p>
  
  <p><img src="https://i.stack.imgur.com/DCxxw.png" alt="enter image description here"></p>
  
  <pre><code>bufferSize = AudioRecord.getMinBufferSize(RECORDER_SAMPLERATE,RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING);
  
      recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
              RECORDER_SAMPLERATE, RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING, bufferSize);
  
      short data [] = new short[bufferSize];
  
      while (!Thread.interrupted()) {
  
          recorder.startRecording();
  
          recorder.read(data, 0, bufferSize);
  
          recorder.stop();
  
          for (short s : data)
          {
              try {
                  Thread.sleep((long) 300.00);
              } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              postUI (Math.abs(s));
          }
      }
  
      recorder.release();
  </code></pre>