OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_utils.
h" | 11 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_utils.
h" |
12 | 12 |
13 #include <math.h> | 13 #include <math.h> |
14 #include <stdlib.h> | 14 #include <stdlib.h> |
15 #include <string.h> | 15 #include <string.h> |
16 #include <algorithm> | 16 #include <algorithm> |
17 #include <limits> | 17 #include <limits> |
18 | 18 |
| 19 #include "webrtc/base/safe_minmax.h" |
| 20 |
19 namespace webrtc { | 21 namespace webrtc { |
20 | 22 |
21 namespace intelligibility { | 23 namespace intelligibility { |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 const float kMinFactor = 0.01f; | 27 const float kMinFactor = 0.01f; |
26 const float kMaxFactor = 100.f; | 28 const float kMaxFactor = 100.f; |
27 | 29 |
28 // Return |current| changed towards |target|, with the relative change being at | 30 // Return |current| changed towards |target|, with the relative change being at |
29 // most |limit|. | 31 // most |limit|. |
30 float UpdateFactor(float target, float current, float limit) { | 32 float UpdateFactor(float target, float current, float limit) { |
31 float gain = target / (current + std::numeric_limits<float>::epsilon()); | 33 const float gain = target / (current + std::numeric_limits<float>::epsilon()); |
32 gain = std::min(std::max(gain, 1.f - limit), 1.f + limit); | 34 const float clamped_gain = rtc::SafeClamp(gain, 1 - limit, 1 + limit); |
33 return std::min(std::max(current * gain, kMinFactor), kMaxFactor);; | 35 return rtc::SafeClamp(current * clamped_gain, kMinFactor, kMaxFactor); |
34 } | 36 } |
35 | 37 |
36 } // namespace | 38 } // namespace |
37 | 39 |
38 template<typename T> | 40 template<typename T> |
39 PowerEstimator<T>::PowerEstimator(size_t num_freqs, float decay) | 41 PowerEstimator<T>::PowerEstimator(size_t num_freqs, float decay) |
40 : power_(num_freqs, 0.f), decay_(decay) {} | 42 : power_(num_freqs, 0.f), decay_(decay) {} |
41 | 43 |
42 template<typename T> | 44 template<typename T> |
43 void PowerEstimator<T>::Step(const T* data) { | 45 void PowerEstimator<T>::Step(const T* data) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 sample_index = 0u; | 85 sample_index = 0u; |
84 } | 86 } |
85 } | 87 } |
86 } | 88 } |
87 read_index_ = sample_index; | 89 read_index_ = sample_index; |
88 } | 90 } |
89 | 91 |
90 } // namespace intelligibility | 92 } // namespace intelligibility |
91 | 93 |
92 } // namespace webrtc | 94 } // namespace webrtc |
OLD | NEW |