Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate sound frequency in android?

I want to develop app to calculate Sound frequency in Android. Android Device will take Sound from microphone (i.e. out side sound) and I have one color background screen in app. on sound frequency changes i have to change background color of screen .

So my question is "How can i get sound frequency"?

is there any android API available?

Please help me out of this problem.

like image 573
Ashish Wadatkar Avatar asked Oct 04 '12 06:10

Ashish Wadatkar


People also ask

Is there an app to measure sound frequencies?

Sound Meter Pro: Sound Meter PRO works with Android phones to measure sound or decibel level. It can also measure sound pressure.

What is a sound frequency?

Frequency, sometimes referred to as pitch, is the number of times per second that a sound pressure wave repeats itself. A drum beat has a much lower frequency than a whistle, and a bullfrog call has a lower frequency than a cricket. The lower the frequency, the fewer the oscillations.


2 Answers

Your problem was solved here EDIT: archived here. Also you can analyze the frequency by using FFT.

EDIT: FFTBasedSpectrumAnalyzer (example code, the link from the comment)

like image 68
ymn Avatar answered Oct 18 '22 00:10

ymn


Thanks for Reply I have done this by using sample on
http://som-itsolutions.blogspot.in/2012/01/fft-based-simple-spectrum-analyzer.html

Just modify your code for to calculate sound frequency by using below method

 // sampleRate = 44100 

public static int calculate(int sampleRate, short [] audioData){

    int numSamples = audioData.length;
    int numCrossing = 0;
    for (int p = 0; p < numSamples-1; p++)
    {
        if ((audioData[p] > 0 && audioData[p + 1] <= 0) || 
            (audioData[p] < 0 && audioData[p + 1] >= 0))
        {
            numCrossing++;
        }
    }

    float numSecondsRecorded = (float)numSamples/(float)sampleRate;
    float numCycles = numCrossing/2;
    float frequency = numCycles/numSecondsRecorded;

    return (int)frequency;
}
like image 25
Ashish Wadatkar Avatar answered Oct 17 '22 23:10

Ashish Wadatkar