| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // the previous results, so the high results have a width equals to | 139 // the previous results, so the high results have a width equals to |
| 140 // |transient_length|. | 140 // |transient_length|. |
| 141 return *std::max_element(previous_results_.begin(), previous_results_.end()); | 141 return *std::max_element(previous_results_.begin(), previous_results_.end()); |
| 142 } | 142 } |
| 143 | 143 |
| 144 // Looks for the highest slope and compares it with the previous ones. | 144 // Looks for the highest slope and compares it with the previous ones. |
| 145 // An exponential transformation takes this to the [0, 1] range. This value is | 145 // An exponential transformation takes this to the [0, 1] range. This value is |
| 146 // multiplied by the detection result to avoid false positives. | 146 // multiplied by the detection result to avoid false positives. |
| 147 float TransientDetector::ReferenceDetectionValue(const float* data, | 147 float TransientDetector::ReferenceDetectionValue(const float* data, |
| 148 size_t length) { | 148 size_t length) { |
| 149 if (data == NULL) { | 149 if (data == nullptr) { |
| 150 using_reference_ = false; | 150 using_reference_ = false; |
| 151 return 1.f; | 151 return 1.f; |
| 152 } | 152 } |
| 153 static const float kEnergyRatioThreshold = 0.2f; | 153 static const float kEnergyRatioThreshold = 0.2f; |
| 154 static const float kReferenceNonLinearity = 20.f; | 154 static const float kReferenceNonLinearity = 20.f; |
| 155 static const float kMemory = 0.99f; | 155 static const float kMemory = 0.99f; |
| 156 float reference_energy = 0.f; | 156 float reference_energy = 0.f; |
| 157 for (size_t i = 1; i < length; ++i) { | 157 for (size_t i = 1; i < length; ++i) { |
| 158 reference_energy += data[i] * data[i]; | 158 reference_energy += data[i] * data[i]; |
| 159 } | 159 } |
| 160 if (reference_energy == 0.f) { | 160 if (reference_energy == 0.f) { |
| 161 using_reference_ = false; | 161 using_reference_ = false; |
| 162 return 1.f; | 162 return 1.f; |
| 163 } | 163 } |
| 164 RTC_DCHECK_NE(0, reference_energy_); | 164 RTC_DCHECK_NE(0, reference_energy_); |
| 165 float result = 1.f / (1.f + exp(kReferenceNonLinearity * | 165 float result = 1.f / (1.f + exp(kReferenceNonLinearity * |
| 166 (kEnergyRatioThreshold - | 166 (kEnergyRatioThreshold - |
| 167 reference_energy / reference_energy_))); | 167 reference_energy / reference_energy_))); |
| 168 reference_energy_ = | 168 reference_energy_ = |
| 169 kMemory * reference_energy_ + (1.f - kMemory) * reference_energy; | 169 kMemory * reference_energy_ + (1.f - kMemory) * reference_energy; |
| 170 | 170 |
| 171 using_reference_ = true; | 171 using_reference_ = true; |
| 172 | 172 |
| 173 return result; | 173 return result; |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace webrtc | 176 } // namespace webrtc |
| OLD | NEW |