| 1 |
/* |
| 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 |
|
| 13 |
#include <stddef.h> |
| 14 |
|
| 15 |
#include <algorithm> |
| 16 |
#include <functional> |
| 17 |
|
| 18 |
#include "api/array_view.h" |
| 19 |
|
| 20 |
namespace webrtc { |
| 21 |
|
| 22 |
ReverbModel::ReverbModel() { |
| 23 |
Reset(); |
| 24 |
} |
| 25 |
|
| 26 |
ReverbModel::~ReverbModel() = default; |
| 27 |
|
| 28 |
void ReverbModel::Reset() { |
| 29 |
reverb_.fill(0.); |
| 30 |
} |
| 31 |
|
| 32 |
void ReverbModel::UpdateReverbNoFreqShaping( |
| 33 |
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 |
|
| 45 |
void ReverbModel::UpdateReverb( |
| 46 |
rtc::ArrayView<const float> power_spectrum, |
| 47 |
rtc::ArrayView<const float> power_spectrum_scaling, |
| 48 |
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 |
|
| 59 |
} // namespace webrtc |