Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何显示该算法的FFT结果?_Android_Algorithm_Fft_Live_Android Mediarecorder - Fatal编程技术网

Android 如何显示该算法的FFT结果?

Android 如何显示该算法的FFT结果?,android,algorithm,fft,live,android-mediarecorder,Android,Algorithm,Fft,Live,Android Mediarecorder,我在stackoverflow上搜索了最快的FFT算法,发现如下: public class FFT { int n, m; // Lookup tables. Only need to recompute when size of FFT changes. double[] cos; double[] sin; public FFT(int n) { this.n = n; this.m

我在stackoverflow上搜索了最快的FFT算法,发现如下:

public class FFT {

      int n, m;

      // Lookup tables. Only need to recompute when size of FFT changes.
      double[] cos;
      double[] sin;

      public FFT(int n) {
          this.n = n;
          this.m = (int) (Math.log(n) / Math.log(2));

          // Make sure n is a power of 2
          if (n != (1 << m))
              throw new RuntimeException("FFT length must be power of 2");

          // precompute tables
          cos = new double[n / 2];
          sin = new double[n / 2];

          for (int i = 0; i < n / 2; i++) {
              cos[i] = Math.cos(-2 * Math.PI * i / n);
              sin[i] = Math.sin(-2 * Math.PI * i / n);
          }

      }

      public void fft(double[] x, double[] y) {
          int i, j, k, n1, n2, a;
          double c, s, t1, t2;

          // Bit-reverse
          j = 0;
          n2 = n / 2;
          for (i = 1; i < n - 1; i++) {
              n1 = n2;
              while (j >= n1) {
                  j = j - n1;
                  n1 = n1 / 2;
              }
              j = j + n1;

              if (i < j) {
                  t1 = x[i];
                  x[i] = x[j];
                  x[j] = t1;
                  t1 = y[i];
                  y[i] = y[j];
                  y[j] = t1;
              }
          }

          // FFT
          n1 = 0;
          n2 = 1;

          for (i = 0; i < m; i++) {
              n1 = n2;
              n2 = n2 + n2;
              a = 0;

              for (j = 0; j < n1; j++) {
                  c = cos[a];
                  s = sin[a];
                  a += 1 << (m - i - 1);

                  for (k = j; k < n; k = k + n2) {
                      t1 = c * x[k + n1] - s * y[k + n1];
                      t2 = s * x[k + n1] + c * y[k + n1];
                      x[k + n1] = x[k] - t1;
                      y[k + n1] = y[k] - t2;
                      x[k] = x[k] + t1;
                      y[k] = y[k] + t2;
                  }
              }
          }
      }
    }

现在我想在我捕获的音频上使用这个FFT算法,并在均衡器或其他东西上显示结果。我该怎么做?

MediaRecorder不允许您直接访问音频缓冲区,但如果您使用AudioRecord,您可以。如果必须使用MediaRecorder,则可以将其保存到文件中,然后重新读取该文件


有人在这里制作了一个示例

谢谢,我将尝试这种方法。
if (mRecorder == null) {
            mRecorder = new MediaRecorder();
            mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

            mRecorder.setOutputFile("/dev/null");

            try {
                mRecorder.prepare();
            } catch (IllegalStateException e) {
                Log.e("error", "IllegalStateException");
            } catch (IOException e) {
                Log.e("error", "IOException");
                ;
            }

            mRecorder.start();
        }