OLD | NEW |
(Empty) | |
| 1 /* |
| 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 |
| 11 #include "webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.h" |
| 12 |
| 13 #include <algorithm> |
| 14 #include <functional> |
| 15 |
| 16 #include "webrtc/base/checks.h" |
| 17 |
| 18 namespace webrtc { |
| 19 |
| 20 void ShadowFilterUpdateGain::Compute( |
| 21 const FftBuffer& X_buffer, |
| 22 const RenderSignalAnalyzer& render_signal_analyzer, |
| 23 const FftData& E_shadow, |
| 24 size_t size_partitions, |
| 25 bool saturated_capture_signal, |
| 26 FftData* G) { |
| 27 RTC_DCHECK(G); |
| 28 ++call_counter_; |
| 29 |
| 30 if (render_signal_analyzer.PoorSignalExcitation()) { |
| 31 poor_signal_excitation_counter_ = 0; |
| 32 } |
| 33 |
| 34 // Do not update the filter if the render is not sufficiently excited. |
| 35 if (++poor_signal_excitation_counter_ < size_partitions || |
| 36 saturated_capture_signal || call_counter_ <= size_partitions) { |
| 37 G->re.fill(0.f); |
| 38 G->im.fill(0.f); |
| 39 return; |
| 40 } |
| 41 |
| 42 // Compute mu. |
| 43 constexpr float kX2Min = 44015068.0f; |
| 44 constexpr float kMuFixed = .5f; |
| 45 std::array<float, kFftLengthBy2Plus1> mu; |
| 46 const auto& X2 = X_buffer.SpectralSum(size_partitions); |
| 47 std::transform(X2.begin(), X2.end(), mu.begin(), |
| 48 [&](float a) { return a > kX2Min ? kMuFixed / a : 0.f; }); |
| 49 |
| 50 // Avoid updating the filter close to narrow bands in the render signals. |
| 51 render_signal_analyzer.MaskRegionsAroundNarrowBands(&mu); |
| 52 |
| 53 // G = mu * E * X2. |
| 54 std::transform(mu.begin(), mu.end(), E_shadow.re.begin(), G->re.begin(), |
| 55 std::multiplies<float>()); |
| 56 std::transform(mu.begin(), mu.end(), E_shadow.im.begin(), G->im.begin(), |
| 57 std::multiplies<float>()); |
| 58 } |
| 59 |
| 60 } // namespace webrtc |
OLD | NEW |