4

I've searched similar topics but cannot find a clear and concise answer. I've been trying to figure out a way I could determine the decibel level output at a given point of time while the Android media player is being played. I cannot find a way to determine how loud the phone is at a given point in time when a song is being played. I've been looking over the media player API but I cannot figure out how I can get a reading at a given time during a song being played.

Any ideas or help appreciated.

T.Rob
  • 31,522
  • 9
  • 59
  • 103
YoungGuy
  • 303
  • 2
  • 8
  • 15

2 Answers2

5

I think you have to record audio to 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 Db value :

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

It is common to choose the maximum signal magnitude as the reference amplitude. That is, we normalize the signal so that the maximum amplitude is defined as 1, or 0 dB

Reno
  • 33,594
  • 11
  • 89
  • 102
  • I don't think this is what you need, because I think you are wanting a dB (SPL) measurement, rather than a dB power ratio -- see http://stackoverflow.com/a/9598848/188414 – the_mandrill Mar 07 '12 at 09:34
  • Hi, what do you mean by maximum signal magnitude? maximum amplitude?? if so, is it still relative?. if not how can I get maximum signal magnitude? Best Regards – smoothumut May 19 '15 at 08:56
  • 1
    i come here for finding a player decibel, not recorder. – Jiang YD May 26 '15 at 01:25
2

The author is long gone here, but I'll chime in anyway, for posterity. I think the key to understanding what you want to do here is working out what you mean by decibel, and what you understand to be the output of the android system. it sounds like you are trying to measure the output of the headphones, in this instance, which is impossible without an external headphone calibration system, so that you know what dB of output is corresponding to as dB SPL out of the headphone.

If this is the goal and you understand this, the visualizer class that android provides might be handy. It also gives 8-bit FFT frequency data, as well as magnitude.