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/echo_detector/moving_max.h" | |
12 | |
13 #include "webrtc/base/checks.h" | |
14 | |
15 namespace webrtc { | |
16 namespace { | |
17 | |
18 // Parameter for controlling how fast the estimated maximum decays after the | |
19 // previous maximum is no longer valid. With a value of 0.95, the maximum will | |
20 // decay to 1% of its former value after 90 updates. | |
hlundin-webrtc
2017/01/13 15:27:47
This might be too fast, but I'm not sure.
ivoc
2017/01/13 15:48:52
Changed this back to 0.99 per offline discussion.
| |
21 constexpr float kDecayFactor = 0.95f; | |
22 | |
23 } // namespace | |
24 | |
25 MovingMax::MovingMax(size_t window_size) : window_size_(window_size) { | |
26 RTC_DCHECK_GT(window_size, 0); | |
27 } | |
28 | |
29 MovingMax::~MovingMax() {} | |
30 | |
31 void MovingMax::Update(float value) { | |
32 if (value > max_value_) { | |
33 max_value_ = value; | |
34 counter_ = 0; | |
the sun
2017/01/13 15:16:02
return;
otherwise you're effectively resetting co
ivoc
2017/01/13 15:48:52
I shuffled things around so a return is not needed
the sun
2017/01/13 21:23:25
Much nicer, but I'm not sure I agree with the (win
| |
35 } | |
36 if (counter_ >= window_size_) { | |
37 max_value_ *= kDecayFactor; | |
38 } else { | |
39 ++counter_; | |
40 } | |
41 } | |
42 | |
43 float MovingMax::max() const { | |
44 return max_value_; | |
45 } | |
46 | |
47 void MovingMax::Clear() { | |
48 max_value_ = 0.f; | |
49 counter_ = 0; | |
50 } | |
51 | |
52 } // namespace webrtc | |
OLD | NEW |