tor-browser

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

spectral_features.h (3254B)


      1 /*
      2 *  Copyright (c) 2018 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_AGC2_RNN_VAD_SPECTRAL_FEATURES_H_
     12 #define MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_SPECTRAL_FEATURES_H_
     13 
     14 #include <array>
     15 #include <cstddef>
     16 #include <memory>
     17 
     18 #include "api/array_view.h"
     19 #include "modules/audio_processing/agc2/rnn_vad/common.h"
     20 #include "modules/audio_processing/agc2/rnn_vad/ring_buffer.h"
     21 #include "modules/audio_processing/agc2/rnn_vad/spectral_features_internal.h"
     22 #include "modules/audio_processing/agc2/rnn_vad/symmetric_matrix_buffer.h"
     23 #include "modules/audio_processing/utility/pffft_wrapper.h"
     24 
     25 namespace webrtc {
     26 namespace rnn_vad {
     27 
     28 // Class to compute spectral features.
     29 class SpectralFeaturesExtractor {
     30 public:
     31  SpectralFeaturesExtractor();
     32  SpectralFeaturesExtractor(const SpectralFeaturesExtractor&) = delete;
     33  SpectralFeaturesExtractor& operator=(const SpectralFeaturesExtractor&) =
     34      delete;
     35  ~SpectralFeaturesExtractor();
     36  // Resets the internal state of the feature extractor.
     37  void Reset();
     38  // Analyzes a pair of reference and lagged frames from the pitch buffer,
     39  // detects silence and computes features. If silence is detected, the output
     40  // is neither computed nor written.
     41  bool CheckSilenceComputeFeatures(
     42      ArrayView<const float, kFrameSize20ms24kHz> reference_frame,
     43      ArrayView<const float, kFrameSize20ms24kHz> lagged_frame,
     44      ArrayView<float, kNumBands - kNumLowerBands> higher_bands_cepstrum,
     45      ArrayView<float, kNumLowerBands> average,
     46      ArrayView<float, kNumLowerBands> first_derivative,
     47      ArrayView<float, kNumLowerBands> second_derivative,
     48      ArrayView<float, kNumLowerBands> bands_cross_corr,
     49      float* variability);
     50 
     51 private:
     52  void ComputeAvgAndDerivatives(
     53      ArrayView<float, kNumLowerBands> average,
     54      ArrayView<float, kNumLowerBands> first_derivative,
     55      ArrayView<float, kNumLowerBands> second_derivative) const;
     56  void ComputeNormalizedCepstralCorrelation(
     57      ArrayView<float, kNumLowerBands> bands_cross_corr);
     58  float ComputeVariability() const;
     59 
     60  const std::array<float, kFrameSize20ms24kHz / 2> half_window_;
     61  Pffft fft_;
     62  std::unique_ptr<Pffft::FloatBuffer> fft_buffer_;
     63  std::unique_ptr<Pffft::FloatBuffer> reference_frame_fft_;
     64  std::unique_ptr<Pffft::FloatBuffer> lagged_frame_fft_;
     65  SpectralCorrelator spectral_correlator_;
     66  std::array<float, kOpusBands24kHz> reference_frame_bands_energy_;
     67  std::array<float, kOpusBands24kHz> lagged_frame_bands_energy_;
     68  std::array<float, kOpusBands24kHz> bands_cross_corr_;
     69  const std::array<float, kNumBands * kNumBands> dct_table_;
     70  RingBuffer<float, kNumBands, kCepstralCoeffsHistorySize>
     71      cepstral_coeffs_ring_buf_;
     72  SymmetricMatrixBuffer<float, kCepstralCoeffsHistorySize> cepstral_diffs_buf_;
     73 };
     74 
     75 }  // namespace rnn_vad
     76 }  // namespace webrtc
     77 
     78 #endif  // MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_SPECTRAL_FEATURES_H_