peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 MODULES_AUDIO_PROCESSING_AEC3_AEC3_FFT_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_AEC3_FFT_H_ |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 13 | |
| 14 | #include <array> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "api/array_view.h" |
| 17 | #include "modules/audio_processing/aec3/aec3_common.h" |
| 18 | #include "modules/audio_processing/aec3/fft_data.h" |
| 19 | #include "modules/audio_processing/utility/ooura_fft.h" |
| 20 | #include "rtc_base/constructormagic.h" |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | // Wrapper class that provides 128 point real valued FFT functionality with the |
| 25 | // FftData type. |
| 26 | class Aec3Fft { |
| 27 | public: |
Per Åhgren | 47d7fbd | 2018-04-24 12:44:29 +0200 | [diff] [blame] | 28 | enum class Window { kRectangular, kHanning, kSqrtHanning }; |
Per Åhgren | d20639f | 2018-01-11 10:29:49 +0100 | [diff] [blame] | 29 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 30 | Aec3Fft() = default; |
| 31 | // Computes the FFT. Note that both the input and output are modified. |
| 32 | void Fft(std::array<float, kFftLength>* x, FftData* X) const { |
| 33 | RTC_DCHECK(x); |
| 34 | RTC_DCHECK(X); |
| 35 | ooura_fft_.Fft(x->data()); |
| 36 | X->CopyFromPackedArray(*x); |
| 37 | } |
| 38 | // Computes the inverse Fft. |
| 39 | void Ifft(const FftData& X, std::array<float, kFftLength>* x) const { |
| 40 | RTC_DCHECK(x); |
| 41 | X.CopyToPackedArray(x); |
| 42 | ooura_fft_.InverseFft(x->data()); |
| 43 | } |
| 44 | |
Per Åhgren | d20639f | 2018-01-11 10:29:49 +0100 | [diff] [blame] | 45 | // Windows the input using a Hanning window, and then adds padding of |
| 46 | // kFftLengthBy2 initial zeros before computing the Fft. |
| 47 | void ZeroPaddedFft(rtc::ArrayView<const float> x, |
| 48 | Window window, |
| 49 | FftData* X) const; |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 50 | |
| 51 | // Concatenates the kFftLengthBy2 values long x and x_old before computing the |
| 52 | // Fft. After that, x is copied to x_old. |
| 53 | void PaddedFft(rtc::ArrayView<const float> x, |
Per Åhgren | 658ad88 | 2018-04-27 14:22:37 +0200 | [diff] [blame] | 54 | rtc::ArrayView<const float> x_old, |
Per Åhgren | 47d7fbd | 2018-04-24 12:44:29 +0200 | [diff] [blame] | 55 | FftData* X) const { |
| 56 | PaddedFft(x, x_old, Window::kRectangular, X); |
| 57 | } |
| 58 | |
| 59 | // Padded Fft using a time-domain window. |
| 60 | void PaddedFft(rtc::ArrayView<const float> x, |
Per Åhgren | 658ad88 | 2018-04-27 14:22:37 +0200 | [diff] [blame] | 61 | rtc::ArrayView<const float> x_old, |
Per Åhgren | 47d7fbd | 2018-04-24 12:44:29 +0200 | [diff] [blame] | 62 | Window window, |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 63 | FftData* X) const; |
| 64 | |
| 65 | private: |
| 66 | const OouraFft ooura_fft_; |
| 67 | |
| 68 | RTC_DISALLOW_COPY_AND_ASSIGN(Aec3Fft); |
| 69 | }; |
| 70 | |
| 71 | } // namespace webrtc |
| 72 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 73 | #endif // MODULES_AUDIO_PROCESSING_AEC3_AEC3_FFT_H_ |