tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

aec3_fft.h (2347B)


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