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 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; | 25 const float kMinFactor = 0.01f; |
26 const float kMaxFactor = 1000.f; | 26 const float kMaxFactor = 100.f; |
27 | 27 |
28 // Return |current| changed towards |target|, with the relative change being at | 28 // Return |current| changed towards |target|, with the relative change being at |
29 // most |limit|. | 29 // most |limit|. |
30 float UpdateFactor(float target, float current, float limit) { | 30 float UpdateFactor(float target, float current, float limit) { |
31 float gain = target / (current + std::numeric_limits<float>::epsilon()); | 31 float gain = target / (current + std::numeric_limits<float>::epsilon()); |
32 gain = std::min(std::max(gain, 1.f - limit), 1.f + limit); | 32 gain = std::min(std::max(gain, 1.f - limit), 1.f + limit); |
33 return std::min(std::max(current * gain, kMinFactor), kMaxFactor);; | 33 return std::min(std::max(current * gain, kMinFactor), kMaxFactor);; |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
(...skipping 23 matching lines...) Expand all Loading... |
60 std::complex<float>* out_block) { | 60 std::complex<float>* out_block) { |
61 for (size_t i = 0; i < num_freqs_; ++i) { | 61 for (size_t i = 0; i < num_freqs_; ++i) { |
62 current_[i] = UpdateFactor(target_[i], current_[i], relative_change_limit_); | 62 current_[i] = UpdateFactor(target_[i], current_[i], relative_change_limit_); |
63 out_block[i] = sqrtf(fabsf(current_[i])) * in_block[i]; | 63 out_block[i] = sqrtf(fabsf(current_[i])) * in_block[i]; |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 } // namespace intelligibility | 67 } // namespace intelligibility |
68 | 68 |
69 } // namespace webrtc | 69 } // namespace webrtc |
OLD | NEW |