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 WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_ 12 #define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_ 13 14 #include "webrtc/typedefs.h" 15 16 // For ComplexFFT(), the maximum fft order is 10; 17 // for OpenMax FFT in ARM, it is 12; 18 // WebRTC APM uses orders of only 7 and 8. 19 enum {kMaxFFTOrder = 10}; 20 21 struct RealFFT; 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 typedef struct RealFFT* (*CreateRealFFT)(int order); 28 typedef void (*FreeRealFFT)(struct RealFFT* self); 29 typedef int (*RealForwardFFT)(struct RealFFT* self, 30 const int16_t* real_data_in, 31 int16_t* complex_data_out); 32 typedef int (*RealInverseFFT)(struct RealFFT* self, 33 const int16_t* complex_data_in, 34 int16_t* real_data_out); 35 36 extern CreateRealFFT WebRtcSpl_CreateRealFFT; 37 extern FreeRealFFT WebRtcSpl_FreeRealFFT; 38 extern RealForwardFFT WebRtcSpl_RealForwardFFT; 39 extern RealInverseFFT WebRtcSpl_RealInverseFFT; 40 41 struct RealFFT* WebRtcSpl_CreateRealFFTC(int order); 42 void WebRtcSpl_FreeRealFFTC(struct RealFFT* self); 43 44 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON) 45 struct RealFFT* WebRtcSpl_CreateRealFFTNeon(int order); 46 void WebRtcSpl_FreeRealFFTNeon(struct RealFFT* self); 47 #endif 48 49 // Compute an FFT for a real-valued signal of length of 2^order, 50 // where 1 < order <= MAX_FFT_ORDER. Transform length is determined by the 51 // specification structure, which must be initialized prior to calling the FFT 52 // function with WebRtcSpl_CreateRealFFT(). 53 // The relationship between the input and output sequences can 54 // be expressed in terms of the DFT, i.e.: 55 // x[n] = (2^(-scalefactor)/N) . SUM[k=0,...,N-1] X[k].e^(jnk.2.pi/N) 56 // n=0,1,2,...N-1 57 // N=2^order. 58 // The conjugate-symmetric output sequence is represented using a CCS vector, 59 // which is of length N+2, and is organized as follows: 60 // Index: 0 1 2 3 4 5 . . . N-2 N-1 N N+1 61 // Component: R0 0 R1 I1 R2 I2 . . . R[N/2-1] I[N/2-1] R[N/2] 0 62 // where R[n] and I[n], respectively, denote the real and imaginary components 63 // for FFT bin 'n'. Bins are numbered from 0 to N/2, where N is the FFT length. 64 // Bin index 0 corresponds to the DC component, and bin index N/2 corresponds to 65 // the foldover frequency. 66 // 67 // Input Arguments: 68 // self - pointer to preallocated and initialized FFT specification structure. 69 // real_data_in - the input signal. For an ARM Neon platform, it must be 70 // aligned on a 32-byte boundary. 71 // 72 // Output Arguments: 73 // complex_data_out - the output complex signal with (2^order + 2) 16-bit 74 // elements. For an ARM Neon platform, it must be different 75 // from real_data_in, and aligned on a 32-byte boundary. 76 // 77 // Return Value: 78 // 0 - FFT calculation is successful. 79 // -1 - Error with bad arguments (NULL pointers). 80 int WebRtcSpl_RealForwardFFTC(struct RealFFT* self, 81 const int16_t* real_data_in, 82 int16_t* complex_data_out); 83 84 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON) 85 int WebRtcSpl_RealForwardFFTNeon(struct RealFFT* self, 86 const int16_t* real_data_in, 87 int16_t* complex_data_out); 88 #endif 89 90 // Compute the inverse FFT for a conjugate-symmetric input sequence of length of 91 // 2^order, where 1 < order <= MAX_FFT_ORDER. Transform length is determined by 92 // the specification structure, which must be initialized prior to calling the 93 // FFT function with WebRtcSpl_CreateRealFFT(). 94 // For a transform of length M, the input sequence is represented using a packed 95 // CCS vector of length M+2, which is explained in the comments for 96 // WebRtcSpl_RealForwardFFTC above. 97 // 98 // Input Arguments: 99 // self - pointer to preallocated and initialized FFT specification structure. 100 // complex_data_in - the input complex signal with (2^order + 2) 16-bit 101 // elements. For an ARM Neon platform, it must be aligned on 102 // a 32-byte boundary. 103 // 104 // Output Arguments: 105 // real_data_out - the output real signal. For an ARM Neon platform, it must 106 // be different to complex_data_in, and aligned on a 32-byte 107 // boundary. 108 // 109 // Return Value: 110 // 0 or a positive number - a value that the elements in the |real_data_out| 111 // should be shifted left with in order to get 112 // correct physical values. 113 // -1 - Error with bad arguments (NULL pointers). 114 int WebRtcSpl_RealInverseFFTC(struct RealFFT* self, 115 const int16_t* complex_data_in, 116 int16_t* real_data_out); 117 118 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON) 119 int WebRtcSpl_RealInverseFFTNeon(struct RealFFT* self, 120 const int16_t* complex_data_in, 121 int16_t* real_data_out); 122 #endif 123 124 #ifdef __cplusplus 125 } 126 #endif 127 128 #endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_ 129