blob: e4f3507d31703f2ac11fb04dee13d182560958dd [file] [log] [blame]
Jesús de Vicente Peña075cb2b2018-06-13 15:13:55 +02001/*
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#include "modules/audio_processing/aec3/reverb_model.h"
12
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <stddef.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Jesús de Vicente Peña075cb2b2018-06-13 15:13:55 +020015#include <algorithm>
16#include <functional>
17
18#include "api/array_view.h"
Jesús de Vicente Peña075cb2b2018-06-13 15:13:55 +020019
20namespace webrtc {
21
22ReverbModel::ReverbModel() {
23 Reset();
24}
25
26ReverbModel::~ReverbModel() = default;
27
28void ReverbModel::Reset() {
29 reverb_.fill(0.);
30}
31
Per Åhgrenb4161d32019-10-08 12:35:47 +020032void ReverbModel::UpdateReverbNoFreqShaping(
Jesús de Vicente Peñae58bd8a2018-06-26 17:19:15 +020033 rtc::ArrayView<const float> power_spectrum,
34 float power_spectrum_scaling,
35 float reverb_decay) {
36 if (reverb_decay > 0) {
37 // Update the estimate of the reverberant power.
38 for (size_t k = 0; k < power_spectrum.size(); ++k) {
39 reverb_[k] = (reverb_[k] + power_spectrum[k] * power_spectrum_scaling) *
40 reverb_decay;
41 }
42 }
43}
44
Per Åhgrenb4161d32019-10-08 12:35:47 +020045void ReverbModel::UpdateReverb(
46 rtc::ArrayView<const float> power_spectrum,
47 rtc::ArrayView<const float> power_spectrum_scaling,
Jesús de Vicente Peñae58bd8a2018-06-26 17:19:15 +020048 float reverb_decay) {
49 if (reverb_decay > 0) {
50 // Update the estimate of the reverberant power.
51 for (size_t k = 0; k < power_spectrum.size(); ++k) {
52 reverb_[k] =
53 (reverb_[k] + power_spectrum[k] * power_spectrum_scaling[k]) *
54 reverb_decay;
55 }
56 }
57}
58
Jesús de Vicente Peña075cb2b2018-06-13 15:13:55 +020059} // namespace webrtc