aec3_fft.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef MODULES_AUDIO_PROCESSING_AEC3_AEC3_FFT_H_
  11. #define MODULES_AUDIO_PROCESSING_AEC3_AEC3_FFT_H_
  12. #include <array>
  13. #include "api/array_view.h"
  14. #include "common_audio/third_party/ooura/fft_size_128/ooura_fft.h"
  15. #include "modules/audio_processing/aec3/aec3_common.h"
  16. #include "modules/audio_processing/aec3/fft_data.h"
  17. #include "rtc_base/checks.h"
  18. #include "rtc_base/constructor_magic.h"
  19. namespace webrtc {
  20. // Wrapper class that provides 128 point real valued FFT functionality with the
  21. // FftData type.
  22. class Aec3Fft {
  23. public:
  24. enum class Window { kRectangular, kHanning, kSqrtHanning };
  25. Aec3Fft();
  26. // Computes the FFT. Note that both the input and output are modified.
  27. void Fft(std::array<float, kFftLength>* x, FftData* X) const {
  28. RTC_DCHECK(x);
  29. RTC_DCHECK(X);
  30. ooura_fft_.Fft(x->data());
  31. X->CopyFromPackedArray(*x);
  32. }
  33. // Computes the inverse Fft.
  34. void Ifft(const FftData& X, std::array<float, kFftLength>* x) const {
  35. RTC_DCHECK(x);
  36. X.CopyToPackedArray(x);
  37. ooura_fft_.InverseFft(x->data());
  38. }
  39. // Windows the input using a Hanning window, and then adds padding of
  40. // kFftLengthBy2 initial zeros before computing the Fft.
  41. void ZeroPaddedFft(rtc::ArrayView<const float> x,
  42. Window window,
  43. FftData* X) const;
  44. // Concatenates the kFftLengthBy2 values long x and x_old before computing the
  45. // Fft. After that, x is copied to x_old.
  46. void PaddedFft(rtc::ArrayView<const float> x,
  47. rtc::ArrayView<const float> x_old,
  48. FftData* X) const {
  49. PaddedFft(x, x_old, Window::kRectangular, X);
  50. }
  51. // Padded Fft using a time-domain window.
  52. void PaddedFft(rtc::ArrayView<const float> x,
  53. rtc::ArrayView<const float> x_old,
  54. Window window,
  55. FftData* X) const;
  56. private:
  57. const OouraFft ooura_fft_;
  58. RTC_DISALLOW_COPY_AND_ASSIGN(Aec3Fft);
  59. };
  60. } // namespace webrtc
  61. #endif // MODULES_AUDIO_PROCESSING_AEC3_AEC3_FFT_H_