Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Worked on this some more. Using some tests done with calibrated SPL-Meters and smart phones with diferent pure frequencies, white noise and pink noise I now know that mobile phone microphones are not usable for anything that should register anywhere above 90 to 100 dB(SPL) depending on the phone.</p> <p>Asuming that 90 dB(SPL) is the maximum one can calculate that this would correspond to a pressure of 0.6325 Pa at the mic. Now asuming that p0=0.0002 Pa is the reference minimum and asuming that this would register as 0 (which would never actually happen) from getMaxAmplitude() we can corelate the values from the getMaxAmplitude() function with maximum pressure at the mic. This means a result of 16375 from getMaxAmplitude() would correspond to 0.3165 Pa maximum pressure. This of course is not very scientific since the max and min values are pure conjesture, but it gives us a starting point. We can now calculate p with </p> <p>p=getMaxAmplitude()/51805.5336</p> <p>Knowing the pressure at the mic we can calculate the dB(SPL)-value with the well known formula </p> <p>X = 20 log_10 (p/p0)</p> <p>This still will give a value that is to high since only the maximum amplitude is used in the calculations. To solve this one must not use getMaxAmplitude() and while this is slighly outside the focus of this question, I will put the code in anyway in the hope, that it helps</p> <pre><code>public class NoiseRecorder { private final String TAG = SoundOfTheCityConstants.TAG; public static double REFERENCE = 0.00002; public double getNoiseLevel() throws NoValidNoiseLevelException { Logging.e(TAG, "start new recording process"); int bufferSize = AudioRecord.getMinBufferSize(44100,AudioFormat.CHANNEL_IN_DEFAULT,AudioFormat.ENCODING_PCM_16BIT); //making the buffer bigger.... bufferSize=bufferSize*4; AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, 44100, AudioFormat.CHANNEL_IN_DEFAULT, AudioFormat.ENCODING_PCM_16BIT, bufferSize); short data [] = new short[bufferSize]; double average = 0.0; recorder.startRecording(); //recording data; recorder.read(data, 0, bufferSize); recorder.stop(); Logging.e(TAG, "stop"); for (short s : data) { if(s&gt;0) { average += Math.abs(s); } else { bufferSize--; } } //x=max; double x = average/bufferSize; Logging.e(TAG, ""+x); recorder.release(); Logging.d(TAG, "getNoiseLevel() "); double db=0; if (x==0){ NoValidNoiseLevelException e = new NoValidNoiseLevelException(x); throw e; } // calculating the pascal pressure based on the idea that the max amplitude (between 0 and 32767) is // relative to the pressure double pressure = x/51805.5336; //the value 51805.5336 can be derived from asuming that x=32767=0.6325 Pa and x=1 = 0.00002 Pa (the reference value) Logging.d(TAG, "x="+pressure +" Pa"); db = (20 * Math.log10(pressure/REFERENCE)); Logging.d(TAG, "db="+db); if(db&gt;0) { return db; } NoValidNoiseLevelException e = new NoValidNoiseLevelException(x); throw e; } } </code></pre> <p>These values now are derived from the average of all amplitudes in an 4 seconds sample and thus more accurate. Afterwards the above decribed calculations are done. This will give a more realistic decibel value. Note that mobile phone mics still do suck and that this algorithm will not produce actual dB(SPL) but only a slighly better approximation then the one before.</p> <p>To get the performance of some apps out there some more would need to be done. Most of these apps use sliding windows, meaning the keep recording and slide a window of x seconds to contnuosly evaluate the sound level. Also I will perform some evaluation what db Value is best suited to be used as max, right now it's 90 dB(SPL)/0.6325 Pa which is just a reasonable guess, it will probably be slighly above that.</p> <p>As soon as I have more I'll update the info.</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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