• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 #ifndef LEGACY_TALKIN_FFT_H
18 #define LEGACY_TALKIN_FFT_H
19 
20 class Fft {
21 public:
22     Fft(void);
23 
24     virtual ~Fft(void);
25 
26     // Prepare for radix-2 FFT's of size (1<<pow2)
27     void fftInit(int pow2);
28 
29     // Forward fft.  Real time-domain components in x, imaginary in y
30     void fft(float *x, float *y);
31 
32     // Inverse fft.  Real frequency-domain components in x, imaginary in y
33     void ifft(float *x, float *y);
34 
35     // Compute the dB-scaled log-magnitude spectrum from the real spectal
36     // amplitude values in 'x', and imaginary values in 'y'.  Return the
37     // magnitude spectrum in z.  Compute 'n' components.
38     int fftLogMag(float *x, float *y, float *z, int n);
39 
40     int fftGetSize();
41 
42     int fftGetPower2();
43 
44     // Return the power of 2 required to contain at least size samples.
fftPow2FromWindowSize(int size)45     static int fftPow2FromWindowSize(int size) {
46         int pow2 = 1;
47         while ((1 << pow2) < size)
48             pow2++;
49         return pow2;
50     }
51 
52 private:
53     // Free up memory and reset the static globals.
54     void fftCleanup();
55 
56     // Create the sine/cosine basis tables and return the size of the FFT
57     // corresponding to pow2.
58     int fftMakeTable(int pow2);
59 
60     float* mSine;
61     float* mCosine;
62     int mFftTableSize;
63     int mFftSize;
64     int mPower2;
65     int mBase;
66 };
67 
68 #endif // LEGACY_TALKIN_FFT_H
69