My goal is to obtain the rpm of powerballs by analysing sound generated during ball rotation. In google play, several application available to calculate rpm and frequency by sound but each and every app failed to find out rpm of power balls. I searched on google and found that "To calculate frequency from sound, we have to use FFT Algo".
what is power ball? Powerball rotate and generate sound. "Powerball® generates resistance which is directly in proportion to the effort expended by the user".
class RecorderThread1 extends Thread {
 private static final String TAG = RecorderThread1.class.getSimpleName();
 public boolean recording; // variable to start or stop recording
 public int frequency; // the public variable that contains the frequency
 private PlaceholderFragment placeHolder;
 private Handler handler;
 private long avgFrequency;
 private int avg = 0;
 private int sampelRateHz = 8000;
 // value "heard", it is updated continually while
 // the thread is running.
 public RecorderThread1(PlaceholderFragment placeHolder) {
  this.placeHolder = placeHolder;
 }
 @Override
 public void run() {
  AudioRecord recorder;
  int numCrossing, p;
  short audioData[];
  int bufferSize;
  bufferSize = AudioRecord.getMinBufferSize(8000,
    AudioFormat.CHANNEL_CONFIGURATION_MONO,
    AudioFormat.ENCODING_PCM_16BIT) * 3; // get the buffer size to
              // use with this audio
              // record
  recorder = new AudioRecord(AudioSource.MIC, 8000,
    AudioFormat.CHANNEL_CONFIGURATION_MONO,
    AudioFormat.ENCODING_PCM_16BIT, bufferSize); // instantiate the
                // AudioRecorder
  recording = true; // variable to use start or stop recording
  audioData = new short[bufferSize]; // short array that pcm data is put
           // into.
  while (recording) { // loop while recording is needed
   if (recorder.getState() == android.media.AudioRecord.STATE_INITIALIZED) // check
                     // to
                     // see
                     // if
                     // the
                     // recorder
                     // has
                     // initialized
                     // yet.
    if (recorder.getRecordingState() == android.media.AudioRecord.RECORDSTATE_STOPPED)
     recorder.startRecording(); // check to see if the Recorder
            // has stopped or is not
            // recording, and make it
            // record.
    else {
     recorder.read(audioData, 0, bufferSize); // read the PCM
                // audio data
                // into the
                // audioData
                // array
     // Now we need to decode the PCM data using the Zero
     // Crossings Method
     numCrossing = 0; // initialize your number of zero crossings
          // to 0
     for (p = 0; p  0 && audioData[p + 1] = 0)
       numCrossing++;
      if (audioData[p + 1] > 0 && audioData[p + 2] = 0)
       numCrossing++;
      if (audioData[p + 2] > 0 && audioData[p + 3] = 0)
       numCrossing++;
      if (audioData[p + 3] > 0 && audioData[p + 4] = 0)
       numCrossing++;
     }// for p
     for (p = (bufferSize / 4) * 4; p  0 && audioData[p + 1] = 0)
       numCrossing++;
     }
     frequency = (8000 / bufferSize) * (numCrossing / 2); // Set
     // the audio Frequency to half the number of zero crossings, times the number of samples our buffersize is per second.
     avgFrequency = avgFrequency + frequency;
     avg++;
     Log.d(TAG, " frequency is " + frequency);
     if (handler == null) {
      handler = new Handler(Looper.getMainLooper());
      handler.postDelayed(runnable, 2000);
     }
     // placeHolder.printFrequency((frequency * 60));
    }// else recorder started
  } // while recording