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> |
hlundin-webrtc
2016/04/28 06:57:14
Is this still needed?
turaj
2016/04/28 17:00:21
for std::numeric_limits<float>::epsilon(), I guess
aluebs-webrtc
2016/04/28 18:10:45
Exactly!
hlundin-webrtc
2016/04/28 18:54:00
Acknowledged. My bad.
| |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
21 namespace intelligibility { | 21 namespace intelligibility { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 const float kMinFactor = 0.01f; | |
26 const float kMaxFactor = 1000.f; | |
peah-webrtc
2016/04/28 18:43:24
It is a bit weird to have a limit on the max and m
aluebs-webrtc
2016/04/28 20:05:23
I don't see why they should be symmetric.
| |
27 | |
25 // Return |current| changed towards |target|, with the relative change being at | 28 // Return |current| changed towards |target|, with the relative change being at |
26 // most |limit|. | 29 // most |limit|. |
27 float UpdateFactor(float target, float current, float limit) { | 30 float UpdateFactor(float target, float current, float limit) { |
28 float gain = target / (current + std::numeric_limits<float>::epsilon()); | 31 float gain = target / (current + std::numeric_limits<float>::epsilon()); |
29 if (gain < 1.f - limit) { | 32 gain = std::min(std::max(gain, 1.f - limit), 1.f + limit); |
30 gain = 1.f - limit; | 33 return std::min(std::max(current * gain, kMinFactor), kMaxFactor);; |
31 } else if (gain > 1.f + limit) { | |
32 gain = 1.f + limit; | |
33 } | |
34 return current * gain + std::numeric_limits<float>::epsilon(); | |
35 } | 34 } |
36 | 35 |
37 } // namespace | 36 } // namespace |
38 | 37 |
39 template<typename T> | 38 template<typename T> |
40 PowerEstimator<T>::PowerEstimator(size_t num_freqs, float decay) | 39 PowerEstimator<T>::PowerEstimator(size_t num_freqs, float decay) |
41 : power_(num_freqs, 0.f), decay_(decay) {} | 40 : power_(num_freqs, 0.f), decay_(decay) {} |
42 | 41 |
43 template<typename T> | 42 template<typename T> |
44 void PowerEstimator<T>::Step(const T* data) { | 43 void PowerEstimator<T>::Step(const T* data) { |
(...skipping 16 matching lines...) Expand all Loading... | |
61 std::complex<float>* out_block) { | 60 std::complex<float>* out_block) { |
62 for (size_t i = 0; i < num_freqs_; ++i) { | 61 for (size_t i = 0; i < num_freqs_; ++i) { |
63 current_[i] = UpdateFactor(target_[i], current_[i], relative_change_limit_); | 62 current_[i] = UpdateFactor(target_[i], current_[i], relative_change_limit_); |
64 out_block[i] = sqrtf(fabsf(current_[i])) * in_block[i]; | 63 out_block[i] = sqrtf(fabsf(current_[i])) * in_block[i]; |
65 } | 64 } |
66 } | 65 } |
67 | 66 |
68 } // namespace intelligibility | 67 } // namespace intelligibility |
69 | 68 |
70 } // namespace webrtc | 69 } // namespace webrtc |
OLD | NEW |