getMaxAmplitude() returns wrong values in different cases
<p>App is running, <code>MediaRecoder</code> object is created and <code>getMaxAmplitude()</code> called every second. It returns value range 300-1000. It's seems to be normal. BUT! After incoming call is received or I call to somebody and after ending call I see that <code>getMaxAmplitude()</code> returns 8-10 value. Why it happens?</p>

<p>I always recreate <code>MediaRecorder</code> object before/after calling, create before start recording and destroy <code>MediaRecorder</code> object after stop recording. May be problem in it?</p>

<p>On Genymotion emulator it doesn't happen only on a real device with Android 4.2.2</p>

<p>public class Recorder {</p>

<pre><code>private MediaRecorder mRecorder = null;
private boolean isRecording = false;

public Recorder() {}

private boolean initRecorder()
{
    try {
        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        mRecorder.setOutputFile("/dev/null");
        return true;
    }
    catch (RuntimeException e)
    {
        return false;
    }
}

public boolean isRecording()
{
    return isRecording;
}

private boolean prepareAndStartRecord()
{
    try {
        mRecorder.prepare();
    } catch (IOException e) {
        return false;
    } catch (IllegalStateException e) {
        return false;
    }

    try {
        mRecorder.start();
        isRecording = true;
        return true;
    } catch (IllegalStateException e) {
        return false;
    }
}

public boolean startRecording()
{
    if (mRecorder == null)
    {
        if(initRecorder())
        {
            return prepareAndStartRecord();
        }
        return false;
    }
    else
    {
        if(prepareAndStartRecord())
            return true;
    }
    return false;
}

public boolean stopRecording()
{
    if (mRecorder != null)
    {
        try {
            mRecorder.stop();
            isRecording = false;
        } catch(RuntimeException e) {
            return false;
        } finally {
            mRecorder.reset();
            mRecorder.release();
            mRecorder = null;
        }
        return true;
    }
    return true;
}

public int getSPL()
{
    int spl = 0;
    if(mRecorder != null) {
        int amp = mRecorder.getMaxAmplitude();
        System.out.println("mRecorder.getMaxAmplitude = "+amp);
        spl = ((Double) Math.ceil(20 * Math.log10((amp / 51805.5336f) / 0.00002f))).intValue();
        //spl = ((Double) Math.ceil(20 * Math.log10((double)Math.abs(amp)))).intValue();
    }
    return spl &gt; 0 ? spl : 0;
}
</code></pre>

<p>}</p>

<p>For example, In service I do this: <code>Recorder recorder = new Recorder();</code> and then calling <code>if(!recorder.startRecording()) {... stopSelf(); ...}</code> and in <code>onDestroy()</code> something like this: <code>recorder.stopRecording();</code></p>