Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: webrtc/modules/audio_coding/neteq/expand.cc

Issue 2714063002: Introduce dchecked_cast, and start using it (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 // Combine voiced and unvoiced contributions. 216 // Combine voiced and unvoiced contributions.
217 217
218 // Set a suitable cross-fading slope. 218 // Set a suitable cross-fading slope.
219 // For lag = 219 // For lag =
220 // <= 31 * fs_mult => go from 1 to 0 in about 8 ms; 220 // <= 31 * fs_mult => go from 1 to 0 in about 8 ms;
221 // (>= 31 .. <= 63) * fs_mult => go from 1 to 0 in about 16 ms; 221 // (>= 31 .. <= 63) * fs_mult => go from 1 to 0 in about 16 ms;
222 // >= 64 * fs_mult => go from 1 to 0 in about 32 ms. 222 // >= 64 * fs_mult => go from 1 to 0 in about 32 ms.
223 // temp_shift = getbits(max_lag_) - 5. 223 // temp_shift = getbits(max_lag_) - 5.
224 int temp_shift = 224 int temp_shift =
225 (31 - WebRtcSpl_NormW32(rtc::checked_cast<int32_t>(max_lag_))) - 5; 225 (31 - WebRtcSpl_NormW32(rtc::dchecked_cast<int32_t>(max_lag_))) - 5;
226 int16_t mix_factor_increment = 256 >> temp_shift; 226 int16_t mix_factor_increment = 256 >> temp_shift;
227 if (stop_muting_) { 227 if (stop_muting_) {
228 mix_factor_increment = 0; 228 mix_factor_increment = 0;
229 } 229 }
230 230
231 // Create combined signal by shifting in more and more of unvoiced part. 231 // Create combined signal by shifting in more and more of unvoiced part.
232 temp_shift = 8 - temp_shift; // = getbits(mix_factor_increment). 232 temp_shift = 8 - temp_shift; // = getbits(mix_factor_increment).
233 size_t temp_length = (parameters.current_voice_mix_factor - 233 size_t temp_length = (parameters.current_voice_mix_factor -
234 parameters.voice_mix_factor) >> temp_shift; 234 parameters.voice_mix_factor) >> temp_shift;
235 temp_length = std::min(temp_length, current_lag); 235 temp_length = std::min(temp_length, current_lag);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 assert(output->Size() == current_lag); 308 assert(output->Size() == current_lag);
309 } 309 }
310 (*output)[channel_ix].OverwriteAt(temp_data, current_lag, 0); 310 (*output)[channel_ix].OverwriteAt(temp_data, current_lag, 0);
311 } 311 }
312 312
313 // Increase call number and cap it. 313 // Increase call number and cap it.
314 consecutive_expands_ = consecutive_expands_ >= kMaxConsecutiveExpands ? 314 consecutive_expands_ = consecutive_expands_ >= kMaxConsecutiveExpands ?
315 kMaxConsecutiveExpands : consecutive_expands_ + 1; 315 kMaxConsecutiveExpands : consecutive_expands_ + 1;
316 expand_duration_samples_ += output->Size(); 316 expand_duration_samples_ += output->Size();
317 // Clamp the duration counter at 2 seconds. 317 // Clamp the duration counter at 2 seconds.
318 expand_duration_samples_ = 318 expand_duration_samples_ = std::min(expand_duration_samples_,
319 std::min(expand_duration_samples_, rtc::checked_cast<size_t>(fs_hz_ * 2)); 319 rtc::dchecked_cast<size_t>(fs_hz_ * 2));
320 return 0; 320 return 0;
321 } 321 }
322 322
323 void Expand::SetParametersForNormalAfterExpand() { 323 void Expand::SetParametersForNormalAfterExpand() {
324 current_lag_index_ = 0; 324 current_lag_index_ = 0;
325 lag_index_direction_ = 0; 325 lag_index_direction_ = 0;
326 stop_muting_ = true; // Do not mute signal any more. 326 stop_muting_ = true; // Do not mute signal any more.
327 statistics_->LogDelayedPacketOutageEvent( 327 statistics_->LogDelayedPacketOutageEvent(
328 rtc::checked_cast<int>(expand_duration_samples_) / (fs_hz_ / 1000)); 328 rtc::dchecked_cast<int>(expand_duration_samples_) / (fs_hz_ / 1000));
329 } 329 }
330 330
331 void Expand::SetParametersForMergeAfterExpand() { 331 void Expand::SetParametersForMergeAfterExpand() {
332 current_lag_index_ = -1; /* out of the 3 possible ones */ 332 current_lag_index_ = -1; /* out of the 3 possible ones */
333 lag_index_direction_ = 1; /* make sure we get the "optimal" lag */ 333 lag_index_direction_ = 1; /* make sure we get the "optimal" lag */
334 stop_muting_ = true; 334 stop_muting_ = true;
335 } 335 }
336 336
337 bool Expand::Muted() const { 337 bool Expand::Muted() const {
338 if (first_expand_ || stop_muting_) 338 if (first_expand_ || stop_muting_)
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; 969 const size_t kMaxRandSamples = RandomVector::kRandomTableSize;
970 while (samples_generated < length) { 970 while (samples_generated < length) {
971 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); 971 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples);
972 random_vector_->IncreaseSeedIncrement(seed_increment); 972 random_vector_->IncreaseSeedIncrement(seed_increment);
973 random_vector_->Generate(rand_length, &random_vector[samples_generated]); 973 random_vector_->Generate(rand_length, &random_vector[samples_generated]);
974 samples_generated += rand_length; 974 samples_generated += rand_length;
975 } 975 }
976 } 976 }
977 977
978 } // namespace webrtc 978 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698