Alessio Bazzica e82643fb9c Fix FFT output size to avoid incorrect band energy computation
The FFT output buffers sizes in SpectralFeaturesExtractor have been reduced
from N to N/2+1, where N is the audio frame size. This is required since
ComputeBandEnergies() currently calls ComputeBandCoefficients() indicating
a higher value for max_freq_bin_index, hence polluting the higher bands with
unwanted energy (coming from the symmetric conjugate copy of the Fourier
coefficients).

Bug: webrtc:10332
Change-Id: Ie080050c4f357fa95e256cf2a6bf572222e8ca44
Reviewed-on: https://webrtc-review.googlesource.com/c/123239
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Pablo Barrera González <barrerap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26761}
2019-02-20 09:08:49 +00:00

57 lines
2.2 KiB
C++

/*
* 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.
*/
#ifndef MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_FFT_UTIL_H_
#define MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_FFT_UTIL_H_
#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 {
public:
BandAnalysisFft();
BandAnalysisFft(const BandAnalysisFft&) = delete;
BandAnalysisFft& operator=(const BandAnalysisFft&) = delete;
~BandAnalysisFft();
// 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);
private:
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
#endif // MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_FFT_UTIL_H_