• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_
12 #define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_
13 
14 #include <stdint.h>
15 
16 // For ComplexFFT(), the maximum fft order is 10;
17 // WebRTC APM uses orders of only 7 and 8.
18 enum { kMaxFFTOrder = 10 };
19 
20 struct RealFFT;
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 struct RealFFT* WebRtcSpl_CreateRealFFT(int order);
27 void WebRtcSpl_FreeRealFFT(struct RealFFT* self);
28 
29 // Compute an FFT for a real-valued signal of length of 2^order,
30 // where 1 < order <= MAX_FFT_ORDER. Transform length is determined by the
31 // specification structure, which must be initialized prior to calling the FFT
32 // function with WebRtcSpl_CreateRealFFT().
33 // The relationship between the input and output sequences can
34 // be expressed in terms of the DFT, i.e.:
35 //     x[n] = (2^(-scalefactor)/N)  . SUM[k=0,...,N-1] X[k].e^(jnk.2.pi/N)
36 //     n=0,1,2,...N-1
37 //     N=2^order.
38 // The conjugate-symmetric output sequence is represented using a CCS vector,
39 // which is of length N+2, and is organized as follows:
40 //     Index:      0  1  2  3  4  5   . . .   N-2       N-1       N       N+1
41 //     Component:  R0 0  R1 I1 R2 I2  . . .   R[N/2-1]  I[N/2-1]  R[N/2]  0
42 // where R[n] and I[n], respectively, denote the real and imaginary components
43 // for FFT bin 'n'. Bins  are numbered from 0 to N/2, where N is the FFT length.
44 // Bin index 0 corresponds to the DC component, and bin index N/2 corresponds to
45 // the foldover frequency.
46 //
47 // Input Arguments:
48 //   self - pointer to preallocated and initialized FFT specification structure.
49 //   real_data_in - the input signal. For an ARM Neon platform, it must be
50 //                  aligned on a 32-byte boundary.
51 //
52 // Output Arguments:
53 //   complex_data_out - the output complex signal with (2^order + 2) 16-bit
54 //                      elements. For an ARM Neon platform, it must be different
55 //                      from real_data_in, and aligned on a 32-byte boundary.
56 //
57 // Return Value:
58 //   0  - FFT calculation is successful.
59 //   -1 - Error with bad arguments (null pointers).
60 int WebRtcSpl_RealForwardFFT(struct RealFFT* self,
61                              const int16_t* real_data_in,
62                              int16_t* complex_data_out);
63 
64 // Compute the inverse FFT for a conjugate-symmetric input sequence of length of
65 // 2^order, where 1 < order <= MAX_FFT_ORDER. Transform length is determined by
66 // the specification structure, which must be initialized prior to calling the
67 // FFT function with WebRtcSpl_CreateRealFFT().
68 // For a transform of length M, the input sequence is represented using a packed
69 // CCS vector of length M+2, which is explained in the comments for
70 // WebRtcSpl_RealForwardFFTC above.
71 //
72 // Input Arguments:
73 //   self - pointer to preallocated and initialized FFT specification structure.
74 //   complex_data_in - the input complex signal with (2^order + 2) 16-bit
75 //                     elements. For an ARM Neon platform, it must be aligned on
76 //                     a 32-byte boundary.
77 //
78 // Output Arguments:
79 //   real_data_out - the output real signal. For an ARM Neon platform, it must
80 //                   be different to complex_data_in, and aligned on a 32-byte
81 //                   boundary.
82 //
83 // Return Value:
84 //   0 or a positive number - a value that the elements in the `real_data_out`
85 //                            should be shifted left with in order to get
86 //                            correct physical values.
87 //   -1 - Error with bad arguments (null pointers).
88 int WebRtcSpl_RealInverseFFT(struct RealFFT* self,
89                              const int16_t* complex_data_in,
90                              int16_t* real_data_out);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif  // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_
97