mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-16 07:10:38 +01:00

- Code clean: exploiting the recently added ArrayView ctor for std::array - Pitch search internal unit test: long const arrays moved to a resource file - Minor changes Bug: webrtc:9076 Change-Id: Iaf30753f2498b4568860d72e0b81f5351235692f TBR: aleloi@webrtc.org Reviewed-on: https://webrtc-review.googlesource.com/76920 Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23248}
58 lines
1.9 KiB
C++
58 lines
1.9 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.
|
|
*/
|
|
|
|
#include "modules/audio_processing/agc2/rnn_vad/fft_util.h"
|
|
|
|
#include <cmath>
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
namespace webrtc {
|
|
namespace rnn_vad {
|
|
namespace {
|
|
|
|
constexpr size_t kHalfFrameSize = kFrameSize20ms24kHz / 2;
|
|
|
|
// Computes the first half of the Vorbis window.
|
|
std::array<float, kHalfFrameSize> ComputeHalfVorbisWindow() {
|
|
std::array<float, kHalfFrameSize> half_window{};
|
|
for (size_t i = 0; i < kHalfFrameSize; ++i) {
|
|
half_window[i] =
|
|
std::sin(0.5 * kPi * std::sin(0.5 * kPi * (i + 0.5) / kHalfFrameSize) *
|
|
std::sin(0.5 * kPi * (i + 0.5) / kHalfFrameSize));
|
|
}
|
|
return half_window;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
BandAnalysisFft::BandAnalysisFft()
|
|
: half_window_(ComputeHalfVorbisWindow()),
|
|
fft_(static_cast<int>(input_buf_.size())) {}
|
|
|
|
BandAnalysisFft::~BandAnalysisFft() = default;
|
|
|
|
void BandAnalysisFft::ForwardFft(rtc::ArrayView<const float> samples,
|
|
rtc::ArrayView<std::complex<float>> dst) {
|
|
RTC_DCHECK_EQ(input_buf_.size(), samples.size());
|
|
RTC_DCHECK_EQ(samples.size(), dst.size());
|
|
// Apply windowing.
|
|
RTC_DCHECK_EQ(input_buf_.size(), 2 * half_window_.size());
|
|
for (size_t i = 0; i < input_buf_.size() / 2; ++i) {
|
|
input_buf_[i].real(samples[i] * half_window_[i]);
|
|
size_t j = kFrameSize20ms24kHz - i - 1;
|
|
input_buf_[j].real(samples[j] * half_window_[i]);
|
|
}
|
|
fft_.ForwardFft(kFrameSize20ms24kHz, input_buf_.data(), kFrameSize20ms24kHz,
|
|
dst.data());
|
|
}
|
|
|
|
} // namespace rnn_vad
|
|
} // namespace webrtc
|