title: getMaxAmplitude() always returns 0
body: <p>I'm trying to get the <code>Sound Level Pressure</code> expressed in <code>decibel</code> but I always get <code>0</code>. (The output of the <code>TextView</code> is <strong>-Infinity</strong> but because <em>log(0) = -infinity</em>.</p>
  
  <pre><code>public class SLP extends Activity{
  
  TextView sound;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.sound_activity);
  
      MediaRecorder recorder = new MediaRecorder();
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      Timer timer = new Timer();
      timer.scheduleAtFixedRate(new RecorderTask(recorder), 0, 500);
  
  
  }
  
  private class RecorderTask extends TimerTask {
      TextView sound = (TextView) findViewById(R.id.decibel);
      private MediaRecorder recorder;
  
      public RecorderTask(MediaRecorder recorder) {
          this.recorder = recorder;
      }
  
      public void run() {
          runOnUiThread(new Runnable() {
              @Override
              public void run() {
                  int amplitude = recorder.getMaxAmplitude();
                  double amplitudeDb = 20 * Math.log10((double)Math.abs(amplitude) / 32768);
                  sound.setText("" + amplitudeDb);
              }
          });
      }
  }
  </code></pre>
  
  <p>The permission in the <code>Manifest.xml</code>:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.RECORD_AUDIO" /&gt;
  </code></pre>
  
  <p>Could you help me please?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I tried with this too:</p>
  
  <pre><code>MediaRecorder recorder = new MediaRecorder();
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      recorder.setOutputFile("/dev/null");
      try {
          recorder.prepare();
      } catch (IOException e) {
          e.printStackTrace();
      }
      recorder.start();
      Timer timer = new Timer();
      timer.scheduleAtFixedRate(new RecorderTask(recorder), 0, 500);
      recorder.reset();
  }
  private class RecorderTask extends TimerTask {
      TextView risultato = (TextView) findViewById(R.id.decibel);
      private MediaRecorder recorder;
  
      public RecorderTask(MediaRecorder recorder) {
          this.recorder = recorder;
      }
  
      public double getAmplitude() {
          if (recorder != null)
              return  (recorder.getMaxAmplitude());
          else
              return 0;
  
      }
  
      public void run() {
          runOnUiThread(new Runnable() {
              @Override
              public void run() {
                  int amplitude = recorder.getMaxAmplitude();
                  double amplitudeDb = 20 * Math.log10(getAmplitude() / 32768);
                  //double db = 20 * Math.log(recorder.getMaxAmplitude() / 2700.0);
                  risultato.setText("" + amplitudeDb);
              }
          });
      }
  }
  </code></pre>
  
  <p>but nothing, still getting <strong>-Infinite</strong></p>
  
  <p>            </p>