tor-browser

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

ns_fft.cc (2139B)


      1 /*
      2 *  Copyright (c) 2019 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 #include "modules/audio_processing/ns/ns_fft.h"
     12 
     13 #include <array>
     14 #include <cstddef>
     15 
     16 #include "api/array_view.h"
     17 #include "common_audio/third_party/ooura/fft_size_256/fft4g.h"
     18 #include "modules/audio_processing/ns/ns_common.h"
     19 
     20 namespace webrtc {
     21 
     22 NrFft::NrFft() : bit_reversal_state_(kFftSize / 2), tables_(kFftSize / 2) {
     23  // Initialize WebRtc_rdt (setting (bit_reversal_state_[0] to 0 triggers
     24  // initialization)
     25  bit_reversal_state_[0] = 0.f;
     26  std::array<float, kFftSize> tmp_buffer;
     27  tmp_buffer.fill(0.f);
     28  WebRtc_rdft(kFftSize, 1, tmp_buffer.data(), bit_reversal_state_.data(),
     29              tables_.data());
     30 }
     31 
     32 void NrFft::Fft(ArrayView<float, kFftSize> time_data,
     33                ArrayView<float, kFftSize> real,
     34                ArrayView<float, kFftSize> imag) {
     35  WebRtc_rdft(kFftSize, 1, time_data.data(), bit_reversal_state_.data(),
     36              tables_.data());
     37 
     38  imag[0] = 0;
     39  real[0] = time_data[0];
     40 
     41  imag[kFftSizeBy2Plus1 - 1] = 0;
     42  real[kFftSizeBy2Plus1 - 1] = time_data[1];
     43 
     44  for (size_t i = 1; i < kFftSizeBy2Plus1 - 1; ++i) {
     45    real[i] = time_data[2 * i];
     46    imag[i] = time_data[2 * i + 1];
     47  }
     48 }
     49 
     50 void NrFft::Ifft(ArrayView<const float> real,
     51                 ArrayView<const float> imag,
     52                 ArrayView<float> time_data) {
     53  time_data[0] = real[0];
     54  time_data[1] = real[kFftSizeBy2Plus1 - 1];
     55  for (size_t i = 1; i < kFftSizeBy2Plus1 - 1; ++i) {
     56    time_data[2 * i] = real[i];
     57    time_data[2 * i + 1] = imag[i];
     58  }
     59  WebRtc_rdft(kFftSize, -1, time_data.data(), bit_reversal_state_.data(),
     60              tables_.data());
     61 
     62  // Scale the output
     63  constexpr float kScaling = 2.f / kFftSize;
     64  for (float& d : time_data) {
     65    d *= kScaling;
     66  }
     67 }
     68 
     69 }  // namespace webrtc