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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 307 } |
308 } | 308 } |
309 | 309 |
310 int16_t Merge::CorrelateAndPeakSearch(int16_t expanded_max, int16_t input_max, | 310 int16_t Merge::CorrelateAndPeakSearch(int16_t expanded_max, int16_t input_max, |
311 int start_position, int input_length, | 311 int start_position, int input_length, |
312 int expand_period) const { | 312 int expand_period) const { |
313 // Calculate correlation without any normalization. | 313 // Calculate correlation without any normalization. |
314 const int max_corr_length = kMaxCorrelationLength; | 314 const int max_corr_length = kMaxCorrelationLength; |
315 int stop_position_downsamp = | 315 int stop_position_downsamp = |
316 std::min(max_corr_length, expand_->max_lag() / (fs_mult_ * 2) + 1); | 316 std::min(max_corr_length, expand_->max_lag() / (fs_mult_ * 2) + 1); |
317 int16_t correlation_shift = 0; | 317 int correlation_shift = 0; |
318 if (expanded_max * input_max > 26843546) { | 318 if (expanded_max * input_max > 26843546) { |
319 correlation_shift = 3; | 319 correlation_shift = 3; |
320 } | 320 } |
321 | 321 |
322 int32_t correlation[kMaxCorrelationLength]; | 322 int32_t correlation[kMaxCorrelationLength]; |
323 WebRtcSpl_CrossCorrelation(correlation, input_downsampled_, | 323 WebRtcSpl_CrossCorrelation(correlation, input_downsampled_, |
324 expanded_downsampled_, kInputDownsampLength, | 324 expanded_downsampled_, kInputDownsampLength, |
325 stop_position_downsamp, correlation_shift, 1); | 325 stop_position_downsamp, correlation_shift, 1); |
326 | 326 |
327 // Normalize correlation to 14 bits and copy to a 16-bit array. | 327 // Normalize correlation to 14 bits and copy to a 16-bit array. |
328 const int pad_length = static_cast<int>(expand_->overlap_length() - 1); | 328 const int pad_length = static_cast<int>(expand_->overlap_length() - 1); |
329 const int correlation_buffer_size = 2 * pad_length + kMaxCorrelationLength; | 329 const int correlation_buffer_size = 2 * pad_length + kMaxCorrelationLength; |
330 rtc::scoped_ptr<int16_t[]> correlation16( | 330 rtc::scoped_ptr<int16_t[]> correlation16( |
331 new int16_t[correlation_buffer_size]); | 331 new int16_t[correlation_buffer_size]); |
332 memset(correlation16.get(), 0, correlation_buffer_size * sizeof(int16_t)); | 332 memset(correlation16.get(), 0, correlation_buffer_size * sizeof(int16_t)); |
333 int16_t* correlation_ptr = &correlation16[pad_length]; | 333 int16_t* correlation_ptr = &correlation16[pad_length]; |
334 int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation, | 334 int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation, |
335 stop_position_downsamp); | 335 stop_position_downsamp); |
336 int16_t norm_shift = std::max(0, 17 - WebRtcSpl_NormW32(max_correlation)); | 336 int norm_shift = std::max(0, 17 - WebRtcSpl_NormW32(max_correlation)); |
337 WebRtcSpl_VectorBitShiftW32ToW16(correlation_ptr, stop_position_downsamp, | 337 WebRtcSpl_VectorBitShiftW32ToW16(correlation_ptr, stop_position_downsamp, |
338 correlation, norm_shift); | 338 correlation, norm_shift); |
339 | 339 |
340 // Calculate allowed starting point for peak finding. | 340 // Calculate allowed starting point for peak finding. |
341 // The peak location bestIndex must fulfill two criteria: | 341 // The peak location bestIndex must fulfill two criteria: |
342 // (1) w16_bestIndex + input_length < | 342 // (1) w16_bestIndex + input_length < |
343 // timestamps_per_call_ + expand_->overlap_length(); | 343 // timestamps_per_call_ + expand_->overlap_length(); |
344 // (2) w16_bestIndex + input_length < start_position. | 344 // (2) w16_bestIndex + input_length < start_position. |
345 int start_index = timestamps_per_call_ + | 345 int start_index = timestamps_per_call_ + |
346 static_cast<int>(expand_->overlap_length()); | 346 static_cast<int>(expand_->overlap_length()); |
(...skipping 28 matching lines...) Expand all Loading... |
375 } | 375 } |
376 return best_correlation_index; | 376 return best_correlation_index; |
377 } | 377 } |
378 | 378 |
379 int Merge::RequiredFutureSamples() { | 379 int Merge::RequiredFutureSamples() { |
380 return static_cast<int>(fs_hz_ / 100 * num_channels_); // 10 ms. | 380 return static_cast<int>(fs_hz_ / 100 * num_channels_); // 10 ms. |
381 } | 381 } |
382 | 382 |
383 | 383 |
384 } // namespace webrtc | 384 } // namespace webrtc |
OLD | NEW |