Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat does Android's getMaxAmplitude() function for the MediaRecorder actually give me?
    primarykey
    data
    text
    <p>The Android MediaRecorder has a function <pre>.getMaxAmplitude();</pre> which, as the <a href="http://developer.android.com/reference/android/media/MediaRecorder.html#getMaxAmplitude%28%29" rel="noreferrer">API</a> tells me, <i>"Returns the maximum absolute amplitude that was sampled since the last call to this method."</i> but I can't find what amplitude this is? Is it in pascal or watts?</p> <p>I have found on several pages on the web that you can calculate a value closely corelated to decibels using (as suggested <a href="https://stackoverflow.com/questions/7189275/how-to-calculate-microphone-audio-input-power-in-decibell-unit">here</a>). </p> <pre><code>double db = (20 * Math.log10(amplitude / REFERENCE)); </code></pre> <p>which would let me assume that the returned value is in some linear scale (probably something like milipascal...) </p> <p>REFERENCE=0.1 (I am aware that this should be something like 2*10^(-5) Pascal ((20 uPascal)), but that returns strange values... 0.1 strangely works better.)</p> <p>Right now I measure the MaxAmplitude() using the <pre>getMaxAmplitude()</pre> and put this into the variable <i>amplitude</i>.</p> <p>This is the method:</p> <pre><code>public double getNoiseLevel() { //Log.d("SPLService", "getNoiseLevel() "); int x = mRecorder.getMaxAmplitude(); double x2 = x; Log.d("SPLService", "x="+x); double db = (20 * Math.log10(x2 / REFERENCE)); //Log.d("SPLService", "db="+db); if(db&gt;0) { return db; } else { return 0; } } </code></pre> <p>This is done 5 times in half a second, which gets kind of an average</p> <pre><code>for(int i=0; i&lt;5; i++) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); return 0; } level = level+getNoiseLevel(); if(level&gt;0) { counter++; } } level=level/counter; Log.d(LOG_TAG, "level="+level); </code></pre> <p>I get something that kinda looks like decibel but I'm not sure its actualy decibel at all...</p> <p>So, could anyone help me on this? It seems very odd that the API does not specefy at all what is returned...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload