Get microphone soundlevel in android
<p>Im trying to get the sound level by getting live-input from the microphone.</p>

<p>As apps such as ,Sound meter and deciBel. I found this sample code from the link: </p>

<p><a href="http://code.google.com/p/android-labs/source/browse/trunk/NoiseAlert/src/com/google/android/noisealert/SoundMeter.java" rel="nofollow">http://code.google.com/p/android-labs/source/browse/trunk/NoiseAlert/src/com/google/android/noisealert/SoundMeter.java</a></p>

<p>I'm also pasting it here.</p>

<pre><code>package com.google.android.noisealert;


import android.media.MediaRecorder;

public class SoundMeter {
    static final private double EMA_FILTER = 0.6;

    private MediaRecorder mRecorder = null;
    private double mEMA = 0.0;

    public void start() {
            if (mRecorder == null) {
                    mRecorder = new MediaRecorder();
                    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                mRecorder.setOutputFile("/dev/null"); 
                mRecorder.prepare();
                mRecorder.start();
                mEMA = 0.0;
            }
    }

    public void stop() {
            if (mRecorder != null) {
                    mRecorder.stop();       
                    mRecorder.release();
                    mRecorder = null;
            }
    }

    public double getAmplitude() {
            if (mRecorder != null)
                    return  (mRecorder.getMaxAmplitude()/2700.0);
            else
                    return 0;

    }

    public double getAmplitudeEMA() {
            double amp = getAmplitude();
            mEMA = EMA_FILTER * amp + (1.0 - EMA_FILTER) * mEMA;
            return mEMA;
    }
</code></pre>

<p>}</p>

<p>Does this code do what im trying to do?
Thanks!</p>
