blob: d5db83ec59c642b18532acc52c6782ca3e78ebe4 [file] [log] [blame]
peah522d71b2017-02-23 05:16:26 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AEC3_AEC3_FFT_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_AEC3_FFT_H_
peah522d71b2017-02-23 05:16:26 -080013
14#include <array>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#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"
Yves Gerey988cc082018-10-23 12:03:01 +020020#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "rtc_base/constructor_magic.h"
peah522d71b2017-02-23 05:16:26 -080022
23namespace webrtc {
24
25// Wrapper class that provides 128 point real valued FFT functionality with the
26// FftData type.
27class Aec3Fft {
28 public:
Per Åhgren47d7fbd2018-04-24 12:44:29 +020029 enum class Window { kRectangular, kHanning, kSqrtHanning };
Per Åhgrend20639f2018-01-11 10:29:49 +010030
peah522d71b2017-02-23 05:16:26 -080031 Aec3Fft() = default;
32 // Computes the FFT. Note that both the input and output are modified.
33 void Fft(std::array<float, kFftLength>* x, FftData* X) const {
34 RTC_DCHECK(x);
35 RTC_DCHECK(X);
36 ooura_fft_.Fft(x->data());
37 X->CopyFromPackedArray(*x);
38 }
39 // Computes the inverse Fft.
40 void Ifft(const FftData& X, std::array<float, kFftLength>* x) const {
41 RTC_DCHECK(x);
42 X.CopyToPackedArray(x);
43 ooura_fft_.InverseFft(x->data());
44 }
45
Per Åhgrend20639f2018-01-11 10:29:49 +010046 // Windows the input using a Hanning window, and then adds padding of
47 // kFftLengthBy2 initial zeros before computing the Fft.
48 void ZeroPaddedFft(rtc::ArrayView<const float> x,
49 Window window,
50 FftData* X) const;
peah522d71b2017-02-23 05:16:26 -080051
52 // Concatenates the kFftLengthBy2 values long x and x_old before computing the
53 // Fft. After that, x is copied to x_old.
54 void PaddedFft(rtc::ArrayView<const float> x,
Per Åhgren658ad882018-04-27 14:22:37 +020055 rtc::ArrayView<const float> x_old,
Per Åhgren47d7fbd2018-04-24 12:44:29 +020056 FftData* X) const {
57 PaddedFft(x, x_old, Window::kRectangular, X);
58 }
59
60 // Padded Fft using a time-domain window.
61 void PaddedFft(rtc::ArrayView<const float> x,
Per Åhgren658ad882018-04-27 14:22:37 +020062 rtc::ArrayView<const float> x_old,
Per Åhgren47d7fbd2018-04-24 12:44:29 +020063 Window window,
peah522d71b2017-02-23 05:16:26 -080064 FftData* X) const;
65
66 private:
67 const OouraFft ooura_fft_;
68
69 RTC_DISALLOW_COPY_AND_ASSIGN(Aec3Fft);
70};
71
72} // namespace webrtc
73
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020074#endif // MODULES_AUDIO_PROCESSING_AEC3_AEC3_FFT_H_