1

I am a beginner to Android.I want to find the frequency density or volume amplitude in Android or using Android Media Player for an mp3 file.I tried many different ways but I didn't got succeeded.Can you please help me with this

I have found this code but it is giving the getMaxAmplitude() value in audio recorder time but not getting the at the time of playing mp3 file. Following is the link: What does Android's getMaxAmplitude() function for the MediaRecorder actually give me?

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>0)
    {
        return db;
    }
    else
    {
        return 0;
    }
}

I also refer of ringdroid link :https://code.google.com/p/ringdroid/

I also checked FFT but it is at the recording time.I need to detect the frequency / Amplitude while playing the Audio File (mp3 file).

Community
  • 1
  • 1
dhruvvarde
  • 179
  • 1
  • 10

1 Answers1

0

mRecorder.getMaxAmplitude() Returns the maximum absolute amplitude measured since the last call, or 0 when called for the first time

It is equivalent to do:

max(abs(signal));

You need check your Reference variable use 1.0 to floating point data representation or 32767 to short int!

To convert the maximum absolute amplitude to dB you need do 20 * log10(x/Reference)

An equivalent code in matlab show the concept:

% create a audio signal in float point at 90dB
signal = 10^(90/20)*sin(2*pi*f/Fs*t)';
%equivalent of mRecorder.getMaxAmplitude()
x = max(abs(signal));
%find dB (Reference for this example is 1.0 data in float point)
decibel = 20 * log10(x/1.0)

Result is 89.9955

To show decibel while playing mp3 file you need call getNoiseLevel() to every processed frame!

ederwander
  • 3,410
  • 1
  • 18
  • 23