2013-09-26 3 views
0

가 나는 가장 빠른 FFT 알고리즘의 유래에 검색 한, 내가 찾은 다음어떻게 그 알고리즘의 FFT 결과를 보여줄 수 있습니까?

내 질문에 다음과 같이 내가 오디오 캡처하는 MediaRecorder 개체를 가지고있다
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; 
        } 
       } 
      } 
     } 
    } 

:

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(); 
     } 

을 지금 캡처 한 오디오에이 FFT 알고리즘을 사용하고 이퀄라이저 또는 다른 결과에 결과를 표시하려고합니다. 내가 어떻게 할 수 있니?

답변

2

MediaRecorder는 오디오 버퍼에 직접 액세스하지 못하지만 AudioRecord를 사용하면 가능합니다. MediaRecorder를 사용해야하는 경우 파일에 저장 한 다음 다시 파일을 다시 읽으십시오.

누군가가 예를 들어 여기에 Capturing Sound for Analysis and Visualizing Frequencies in Android

+0

감사 일했다, 나는이 방법을 시도 할 것이다. – MAOL

관련 문제