| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // Single peak. The parabola fit assumes that an extra point is | 110 // Single peak. The parabola fit assumes that an extra point is |
| 111 // available; worst case it gets a zero on the high end of the signal. | 111 // available; worst case it gets a zero on the high end of the signal. |
| 112 // TODO(hlundin): This can potentially get much worse. It breaks the | 112 // TODO(hlundin): This can potentially get much worse. It breaks the |
| 113 // API contract, that the length of |data| is |data_length|. | 113 // API contract, that the length of |data| is |data_length|. |
| 114 data_length++; | 114 data_length++; |
| 115 } | 115 } |
| 116 | 116 |
| 117 peak_index[i] = WebRtcSpl_MaxIndexW16(data, data_length - 1); | 117 peak_index[i] = WebRtcSpl_MaxIndexW16(data, data_length - 1); |
| 118 | 118 |
| 119 if (i != num_peaks - 1) { | 119 if (i != num_peaks - 1) { |
| 120 min_index = std::max(0, peak_index[i] - 2); | 120 min_index = (peak_index[i] > 2) ? (peak_index[i] - 2) : 0; |
| 121 max_index = std::min(data_length - 1, peak_index[i] + 2); | 121 max_index = std::min(data_length - 1, peak_index[i] + 2); |
| 122 } | 122 } |
| 123 | 123 |
| 124 if ((peak_index[i] != 0) && (peak_index[i] != (data_length - 2))) { | 124 if ((peak_index[i] != 0) && (peak_index[i] != (data_length - 2))) { |
| 125 ParabolicFit(&data[peak_index[i] - 1], fs_mult, &peak_index[i], | 125 ParabolicFit(&data[peak_index[i] - 1], fs_mult, &peak_index[i], |
| 126 &peak_value[i]); | 126 &peak_value[i]); |
| 127 } else { | 127 } else { |
| 128 if (peak_index[i] == data_length - 2) { | 128 if (peak_index[i] == data_length - 2) { |
| 129 if (data[peak_index[i]] > data[peak_index[i] + 1]) { | 129 if (data[peak_index[i]] > data[peak_index[i] + 1]) { |
| 130 ParabolicFit(&data[peak_index[i] - 1], fs_mult, &peak_index[i], | 130 ParabolicFit(&data[peak_index[i] - 1], fs_mult, &peak_index[i], |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 231 } |
| 232 } else { | 232 } else { |
| 233 *peak_value = signal_points[1]; | 233 *peak_value = signal_points[1]; |
| 234 *peak_index = *peak_index * 2 * fs_mult; | 234 *peak_index = *peak_index * 2 * fs_mult; |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 int DspHelper::MinDistortion(const int16_t* signal, int min_lag, | 238 int DspHelper::MinDistortion(const int16_t* signal, int min_lag, |
| 239 int max_lag, int length, | 239 int max_lag, int length, |
| 240 int32_t* distortion_value) { | 240 int32_t* distortion_value) { |
| 241 int best_index = -1; | 241 int best_index = 0; |
| 242 int32_t min_distortion = WEBRTC_SPL_WORD32_MAX; | 242 int32_t min_distortion = WEBRTC_SPL_WORD32_MAX; |
| 243 for (int i = min_lag; i <= max_lag; i++) { | 243 for (int i = min_lag; i <= max_lag; i++) { |
| 244 int32_t sum_diff = 0; | 244 int32_t sum_diff = 0; |
| 245 const int16_t* data1 = signal; | 245 const int16_t* data1 = signal; |
| 246 const int16_t* data2 = signal - i; | 246 const int16_t* data2 = signal - i; |
| 247 for (int j = 0; j < length; j++) { | 247 for (int j = 0; j < length; j++) { |
| 248 sum_diff += WEBRTC_SPL_ABS_W32(data1[j] - data2[j]); | 248 sum_diff += WEBRTC_SPL_ABS_W32(data1[j] - data2[j]); |
| 249 } | 249 } |
| 250 // Compare with previous minimum. | 250 // Compare with previous minimum. |
| 251 if (sum_diff < min_distortion) { | 251 if (sum_diff < min_distortion) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 } | 344 } |
| 345 | 345 |
| 346 // Returns -1 if input signal is too short; 0 otherwise. | 346 // Returns -1 if input signal is too short; 0 otherwise. |
| 347 return WebRtcSpl_DownsampleFast( | 347 return WebRtcSpl_DownsampleFast( |
| 348 &input[filter_length - 1], static_cast<int>(input_length) - | 348 &input[filter_length - 1], static_cast<int>(input_length) - |
| 349 (filter_length - 1), output, output_length, filter_coefficients, | 349 (filter_length - 1), output, output_length, filter_coefficients, |
| 350 filter_length, factor, filter_delay); | 350 filter_length, factor, filter_delay); |
| 351 } | 351 } |
| 352 | 352 |
| 353 } // namespace webrtc | 353 } // namespace webrtc |
| OLD | NEW |