Decibel Reading for Android Media Player

I have searched for similar topics, but cannot find a clear and concise answer. I was trying to determine the way in which I could determine the decibel level output at a given point in time while the Android multimedia player is playing. I can’t find a way to determine how loud the phone is at a given time when the song is playing. I was looking through the API of the media player, but I can’t understand how I can get reading at a specific time while playing a song.

Any ideas or help appreciated.

+4
source share
2 answers

I think you need to record audio using MediaRecorder :

 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(); 

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

To calculate the Db value:

  powerDb = 20 * log10(getAmplitude() / referenceAmp); 

Typically, a maximum signal value is selected as a reference amplitude. That is, we normalize the signal, so that the maximum amplitude is defined as 1 or 0 dB

+4
source

The author has long gone here, but I’ll call you back anyway, for posterity. I think that the key to understanding what you want to do here is to develop what you mean by decibel and what you understand as the result of the Android system. it looks like you are trying to measure the headphone output, in this case, which is impossible without an external headphone calibration system so that you know which dB of output corresponds to the dB SPL of the headphone.

If this is the goal, and you understand it, the visualizer class that android will provide may be convenient. It also gives 8-bit FFT frequency data as well as magnitude.

0
source

Source: https://habr.com/ru/post/1382830/


All Articles