blob: d6690360f864672281ff3ecc2e19c7888b9c6ad7 [file] [log] [blame]
peah522d71b2017-02-23 05:16:26 -08001/*
2 * Copyright (c) 2017 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/aec3/aec3_fft.h"
peah522d71b2017-02-23 05:16:26 -080012
13#include <algorithm>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/checks.h"
peah522d71b2017-02-23 05:16:26 -080016
17namespace webrtc {
18
Per Åhgrend20639f2018-01-11 10:29:49 +010019namespace {
20
21const float kHanning64[kFftLengthBy2] = {
22 0.f, 0.00248461f, 0.00991376f, 0.0222136f, 0.03926189f,
23 0.06088921f, 0.08688061f, 0.11697778f, 0.15088159f, 0.1882551f,
24 0.22872687f, 0.27189467f, 0.31732949f, 0.36457977f, 0.41317591f,
25 0.46263495f, 0.51246535f, 0.56217185f, 0.61126047f, 0.65924333f,
26 0.70564355f, 0.75f, 0.79187184f, 0.83084292f, 0.86652594f,
27 0.89856625f, 0.92664544f, 0.95048443f, 0.96984631f, 0.98453864f,
28 0.99441541f, 0.99937846f, 0.99937846f, 0.99441541f, 0.98453864f,
29 0.96984631f, 0.95048443f, 0.92664544f, 0.89856625f, 0.86652594f,
30 0.83084292f, 0.79187184f, 0.75f, 0.70564355f, 0.65924333f,
31 0.61126047f, 0.56217185f, 0.51246535f, 0.46263495f, 0.41317591f,
32 0.36457977f, 0.31732949f, 0.27189467f, 0.22872687f, 0.1882551f,
33 0.15088159f, 0.11697778f, 0.08688061f, 0.06088921f, 0.03926189f,
34 0.0222136f, 0.00991376f, 0.00248461f, 0.f};
35
36} // namespace
37
peah522d71b2017-02-23 05:16:26 -080038// TODO(peah): Change x to be std::array once the rest of the code allows this.
Per Åhgrend20639f2018-01-11 10:29:49 +010039void Aec3Fft::ZeroPaddedFft(rtc::ArrayView<const float> x,
40 Window window,
41 FftData* X) const {
peah522d71b2017-02-23 05:16:26 -080042 RTC_DCHECK(X);
43 RTC_DCHECK_EQ(kFftLengthBy2, x.size());
44 std::array<float, kFftLength> fft;
45 std::fill(fft.begin(), fft.begin() + kFftLengthBy2, 0.f);
Per Åhgrend20639f2018-01-11 10:29:49 +010046 switch (window) {
47 case Window::kRectangular:
48 std::copy(x.begin(), x.end(), fft.begin() + kFftLengthBy2);
49 break;
50 case Window::kHanning:
51 std::transform(x.begin(), x.end(), std::begin(kHanning64),
52 fft.begin() + kFftLengthBy2,
53 [](float a, float b) { return a * b; });
54 break;
55 default:
56 RTC_NOTREACHED();
57 }
58
peah522d71b2017-02-23 05:16:26 -080059 Fft(&fft, X);
60}
61
62void Aec3Fft::PaddedFft(rtc::ArrayView<const float> x,
63 rtc::ArrayView<float> x_old,
64 FftData* X) const {
65 RTC_DCHECK(X);
66 RTC_DCHECK_EQ(kFftLengthBy2, x.size());
67 RTC_DCHECK_EQ(kFftLengthBy2, x_old.size());
68 std::array<float, kFftLength> fft;
69 std::copy(x_old.begin(), x_old.end(), fft.begin());
70 std::copy(x.begin(), x.end(), fft.begin() + x_old.size());
71 std::copy(x.begin(), x.end(), x_old.begin());
72 Fft(&fft, X);
73}
74
75} // namespace webrtc