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/render_signal_analyzer.h" | |
12 | |
13 #include <algorithm> | |
14 | |
15 #include "webrtc/base/array_view.h" | |
aleloi
2017/02/13 16:44:51
Not used here.
peah-webrtc
2017/02/20 07:37:18
Done.
| |
16 #include "webrtc/base/checks.h" | |
17 | |
18 namespace webrtc { | |
19 | |
20 namespace { | |
21 constexpr size_t kCounterThreshold = 5; | |
22 | |
23 } // namespace | |
24 | |
25 RenderSignalAnalyzer::RenderSignalAnalyzer() { | |
26 narrow_band_counters_.fill(0); | |
27 } | |
28 RenderSignalAnalyzer::~RenderSignalAnalyzer() = default; | |
29 | |
30 void RenderSignalAnalyzer::Update( | |
31 const FftBuffer& X_buffer, | |
32 const rtc::Optional<size_t>& delay_partitions) { | |
33 if (!delay_partitions) { | |
34 narrow_band_counters_.fill(0); | |
35 return; | |
36 } | |
37 | |
38 const std::array<float, kFftLengthBy2Plus1>& X2 = | |
39 X_buffer.Spectrum(*delay_partitions); | |
40 | |
41 // Detect narrow band signal regions. | |
42 for (size_t k = 1; k < (X2.size() - 1); ++k) { | |
43 narrow_band_counters_[k - 1] = X2[k] > 3 * std::max(X2[k - 1], X2[k + 1]) | |
44 ? narrow_band_counters_[k - 1] + 1 | |
45 : 0; | |
46 } | |
47 } | |
48 | |
49 void RenderSignalAnalyzer::MaskRegionsAroundNarrowBands( | |
50 std::array<float, kFftLengthBy2Plus1>* v) const { | |
51 RTC_DCHECK(v); | |
52 | |
53 // Set v to zero around narrow band signal regions. | |
54 if (narrow_band_counters_[0] > kCounterThreshold) { | |
55 (*v)[1] = (*v)[0] = 0.f; | |
56 } | |
57 for (size_t k = 2; k < kFftLengthBy2 - 1; ++k) { | |
58 if (narrow_band_counters_[k - 1] > kCounterThreshold) { | |
59 (*v)[k - 2] = (*v)[k - 1] = (*v)[k] = (*v)[k + 2] = (*v)[k + 1] = 0.f; | |
hlundin-webrtc
2017/02/13 21:37:01
Nit: For a more natural readability I would sugges
peah-webrtc
2017/02/20 07:37:18
Done.
peah-webrtc
2017/02/20 07:37:18
Done.
| |
60 } | |
61 } | |
62 if (narrow_band_counters_[kFftLengthBy2 - 2] > kCounterThreshold) { | |
63 (*v)[kFftLengthBy2] = (*v)[kFftLengthBy2 - 1] = 0.f; | |
64 } | |
65 } | |
66 | |
67 } // namespace webrtc | |
OLD | NEW |