andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_ |
| 12 | #define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_ |
andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 14 | #include "typedefs.h" // NOLINT(build/include) |
andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 15 | |
kma@webrtc.org | fc8aaf0 | 2013-07-24 17:38:23 +0000 | [diff] [blame] | 16 | // For ComplexFFT(), the maximum fft order is 10; |
kma@webrtc.org | fc8aaf0 | 2013-07-24 17:38:23 +0000 | [diff] [blame] | 17 | // WebRTC APM uses orders of only 7 and 8. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 18 | enum { kMaxFFTOrder = 10 }; |
kma@webrtc.org | fc8aaf0 | 2013-07-24 17:38:23 +0000 | [diff] [blame] | 19 | |
andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 20 | struct RealFFT; |
| 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
bjornv@webrtc.org | ee43263 | 2014-12-08 16:36:22 +0000 | [diff] [blame] | 26 | struct RealFFT* WebRtcSpl_CreateRealFFT(int order); |
| 27 | void WebRtcSpl_FreeRealFFT(struct RealFFT* self); |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 28 | |
kma@webrtc.org | fc8aaf0 | 2013-07-24 17:38:23 +0000 | [diff] [blame] | 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 | // |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 47 | // Input Arguments: |
| 48 | // self - pointer to preallocated and initialized FFT specification structure. |
kma@webrtc.org | fc8aaf0 | 2013-07-24 17:38:23 +0000 | [diff] [blame] | 49 | // real_data_in - the input signal. For an ARM Neon platform, it must be |
| 50 | // aligned on a 32-byte boundary. |
andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 51 | // |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 52 | // Output Arguments: |
kma@webrtc.org | fc8aaf0 | 2013-07-24 17:38:23 +0000 | [diff] [blame] | 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. |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 56 | // |
| 57 | // Return Value: |
| 58 | // 0 - FFT calculation is successful. |
deadbeef | 922246a | 2017-02-26 04:18:12 -0800 | [diff] [blame] | 59 | // -1 - Error with bad arguments (null pointers). |
bjornv@webrtc.org | ee43263 | 2014-12-08 16:36:22 +0000 | [diff] [blame] | 60 | int WebRtcSpl_RealForwardFFT(struct RealFFT* self, |
| 61 | const int16_t* real_data_in, |
| 62 | int16_t* complex_data_out); |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 63 | |
kma@webrtc.org | fc8aaf0 | 2013-07-24 17:38:23 +0000 | [diff] [blame] | 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 | // |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 72 | // Input Arguments: |
| 73 | // self - pointer to preallocated and initialized FFT specification structure. |
kma@webrtc.org | fc8aaf0 | 2013-07-24 17:38:23 +0000 | [diff] [blame] | 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. |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 77 | // |
| 78 | // Output Arguments: |
kma@webrtc.org | fc8aaf0 | 2013-07-24 17:38:23 +0000 | [diff] [blame] | 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. |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 82 | // |
| 83 | // Return Value: |
kma@webrtc.org | fc8aaf0 | 2013-07-24 17:38:23 +0000 | [diff] [blame] | 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. |
deadbeef | 922246a | 2017-02-26 04:18:12 -0800 | [diff] [blame] | 87 | // -1 - Error with bad arguments (null pointers). |
bjornv@webrtc.org | ee43263 | 2014-12-08 16:36:22 +0000 | [diff] [blame] | 88 | int WebRtcSpl_RealInverseFFT(struct RealFFT* self, |
| 89 | const int16_t* complex_data_in, |
| 90 | int16_t* real_data_out); |
andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 91 | |
| 92 | #ifdef __cplusplus |
| 93 | } |
| 94 | #endif |
| 95 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 96 | #endif // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_ |