I have been working on a tuner app for Android, but I am having a hard time getting the fundamental frequency. 

There are two possible problems:
1) I am not computing the fundamental frequency correctly.
2) I am not passing this value on correctly so that it can be displayed on the UI.

Thanks to Craigy, I have successfully implemented the AsyncTask because I was able to pass through some sort of data continuously. Now, I just need to get the correct value to show up.

Here is the AsyncTask:

```
protected class Tune extends AsyncTask<Double, Double, Double>
{
    protected void onPreExecute()
    {
        super.onPreExecute();
        btnTune.setText("Stop Tuning");
    }

    protected Double doInBackground(Double... params)
    {

        while(tuning)
        {
            try{

                acquire();
                hello = computeFFT();
                publishProgress(hello);
                //Thread.sleep(1);
            } catch(Exception e) {

            }

        }

        return 100.0;
    }

    protected void onProgressUpdate(Double...values)
    {
        super.onProgressUpdate(values);

                //DecimalFormat d = new DecimalFormat("#3.65");
                freq.setText(values + " Hz");;

    }

    protected double onPostExecute(Double...hello)
    {
        tuning = false;
        freq.setText("STOP!");
        return 75.0;
    }
}

```

I think that it is set up correctly, but for some reason I cannot get anything to show up anymore on publishProgress and onProgressUpdate. What is wrong? How am I supposed to update the UI. I had it working for awhile, but not any more.

Here is my FFT:

```
public double computeFFT(){

    //Conversion from short to float
            float[] micBufferData = new float[buffer];//size may need to change
            final int bytesPerSample = 2; // As it is 16bit PCM
            final float amplification = 50; // choose a number as you like
            for (int index = 0, floatIndex = 0; index < buffer - bytesPerSample + 1; index += bytesPerSample, floatIndex++) {
                float sample = 0;
                for (int b = 0; b < bytesPerSample; b++) {
                    int v = audioData[index + b];
                    if (b < bytesPerSample - 1 || bytesPerSample == 1) {
                        v &= 0xFF;
                    }
                    sample += v << (b * 8);
                }
                float sample32 = amplification * (sample / 32768);
                micBufferData[floatIndex] = sample32;
            }
    sampleRate = sampleRateInHz;

    //Take FFT of float data
    fftgdx.forward(micBufferData);

    //Fill in imaginary and real arrays from FFT data
    tmpi = fftgdx.getImaginaryPart();
    tmpr = fftgdx.getRealPart();

    //Create array of magnitude = sqrt(real*real + imag*imag)
    for(int i=0;i<micBufferData.length;i++)
       {
           real[i] = (double) tmpr[i];
           imag[i] = (double) tmpi[i];
           mag[i] = Math.sqrt((real[i]*real[i]) + (imag[i]*imag[i]));
       }

   // find largest peak in power spectrum
     double max_magnitude = -1.0;
      int max_index = -1;
      for(int i = 0; i<(buffer/2.0-1); i++)
      { if(mag[i] > max_magnitude)
          max_magnitude = mag[i];
          max_index = i;
      }

      // convert index of largest peak to frequency
      frequency = (max_index*sampleRateInHz)/(buffer);

      return frequency;
}

```

From everything I have read and studied, this seems to be right. Look good to you? Am I passing the value back correctly?

Thanks for your help. It is much appreciated :)