| 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 |
| 11 #include "webrtc/modules/audio_coding/neteq/merge.h" | 11 #include "webrtc/modules/audio_coding/neteq/merge.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 #include <string.h> // memmove, memcpy, memset, size_t | 14 #include <string.h> // memmove, memcpy, memset, size_t |
| 15 | 15 |
| 16 #include <algorithm> // min, max | 16 #include <algorithm> // min, max |
| 17 #include <memory> | 17 #include <memory> |
| 18 | 18 |
| 19 #include "webrtc/base/safe_conversions.h" |
| 20 #include "webrtc/base/safe_minmax.h" |
| 19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 21 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
| 20 #include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h" | 22 #include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h" |
| 21 #include "webrtc/modules/audio_coding/neteq/cross_correlation.h" | 23 #include "webrtc/modules/audio_coding/neteq/cross_correlation.h" |
| 22 #include "webrtc/modules/audio_coding/neteq/dsp_helper.h" | 24 #include "webrtc/modules/audio_coding/neteq/dsp_helper.h" |
| 23 #include "webrtc/modules/audio_coding/neteq/expand.h" | 25 #include "webrtc/modules/audio_coding/neteq/expand.h" |
| 24 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" | 26 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" |
| 25 | 27 |
| 26 namespace webrtc { | 28 namespace webrtc { |
| 27 | 29 |
| 28 Merge::Merge(int fs_hz, | 30 Merge::Merge(int fs_hz, |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // Trim the length to exactly |required_length|. | 204 // Trim the length to exactly |required_length|. |
| 203 expanded_.PopBack(expanded_.Size() - required_length); | 205 expanded_.PopBack(expanded_.Size() - required_length); |
| 204 } | 206 } |
| 205 assert(expanded_.Size() >= required_length); | 207 assert(expanded_.Size() >= required_length); |
| 206 return required_length; | 208 return required_length; |
| 207 } | 209 } |
| 208 | 210 |
| 209 int16_t Merge::SignalScaling(const int16_t* input, size_t input_length, | 211 int16_t Merge::SignalScaling(const int16_t* input, size_t input_length, |
| 210 const int16_t* expanded_signal) const { | 212 const int16_t* expanded_signal) const { |
| 211 // Adjust muting factor if new vector is more or less of the BGN energy. | 213 // Adjust muting factor if new vector is more or less of the BGN energy. |
| 212 const size_t mod_input_length = | 214 const auto mod_input_length = rtc::SafeMin<size_t>( |
| 213 std::min(static_cast<size_t>(64 * fs_mult_), input_length); | 215 64 * rtc::dchecked_cast<size_t>(fs_mult_), input_length); |
| 214 const int16_t expanded_max = | 216 const int16_t expanded_max = |
| 215 WebRtcSpl_MaxAbsValueW16(expanded_signal, mod_input_length); | 217 WebRtcSpl_MaxAbsValueW16(expanded_signal, mod_input_length); |
| 216 int32_t factor = (expanded_max * expanded_max) / | 218 int32_t factor = (expanded_max * expanded_max) / |
| 217 (std::numeric_limits<int32_t>::max() / | 219 (std::numeric_limits<int32_t>::max() / |
| 218 static_cast<int32_t>(mod_input_length)); | 220 static_cast<int32_t>(mod_input_length)); |
| 219 const int expanded_shift = factor == 0 ? 0 : 31 - WebRtcSpl_NormW32(factor); | 221 const int expanded_shift = factor == 0 ? 0 : 31 - WebRtcSpl_NormW32(factor); |
| 220 int32_t energy_expanded = WebRtcSpl_DotProductWithScale(expanded_signal, | 222 int32_t energy_expanded = WebRtcSpl_DotProductWithScale(expanded_signal, |
| 221 expanded_signal, | 223 expanded_signal, |
| 222 mod_input_length, | 224 mod_input_length, |
| 223 expanded_shift); | 225 expanded_shift); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 371 } |
| 370 return best_correlation_index; | 372 return best_correlation_index; |
| 371 } | 373 } |
| 372 | 374 |
| 373 size_t Merge::RequiredFutureSamples() { | 375 size_t Merge::RequiredFutureSamples() { |
| 374 return fs_hz_ / 100 * num_channels_; // 10 ms. | 376 return fs_hz_ / 100 * num_channels_; // 10 ms. |
| 375 } | 377 } |
| 376 | 378 |
| 377 | 379 |
| 378 } // namespace webrtc | 380 } // namespace webrtc |
| OLD | NEW |