blob: c744ff6c645a6bc1ae1e22b1692311755c1d1989 [file] [log] [blame]
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
#include <array>
#include <complex>
#include "api/array_view.h"
#include "modules/audio_processing/agc2/rnn_vad/common.h"
#include "third_party/rnnoise/src/kiss_fft.h"
namespace webrtc {
namespace rnn_vad {
// TODO(alessiob): Switch to PFFFT using its own wrapper.
// TODO(alessiob): Delete this class when switching to PFFFT.
// FFT implementation wrapper for the band-wise analysis step in which 20 ms
// frames at 24 kHz are analyzed in the frequency domain. The goal of this class
// are (i) making easy to switch to another FFT implementation, (ii) own the
// input buffer for the FFT and (iii) apply a windowing function before
// computing the FFT.
class BandAnalysisFft {
BandAnalysisFft(const BandAnalysisFft&) = delete;
BandAnalysisFft& operator=(const BandAnalysisFft&) = delete;
// Applies a windowing function to |samples|, computes the real forward FFT
// and writes the result in |dst|.
// The size of |samples| must be 480 (20 ms at 24 kHz).
// The size of |dst| must be 241 since the complex conjugate is not written.
void ForwardFft(rtc::ArrayView<const float> samples,
rtc::ArrayView<std::complex<float>> dst);
static_assert((kFrameSize20ms24kHz & 1) == 0,
"kFrameSize20ms24kHz must be even.");
const std::array<float, kFrameSize20ms24kHz / 2> half_window_;
std::array<std::complex<float>, kFrameSize20ms24kHz> input_buf_{};
std::array<std::complex<float>, kFrameSize20ms24kHz> output_buf_{};
rnnoise::KissFft fft_;
} // namespace rnn_vad
} // namespace webrtc