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

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

Issue 2500953003: Avoid left-shifting negative values in a number of places (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « webrtc/common_audio/signal_processing/vector_scaling_operations.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 // voice_mix_factor = (-5179 + 19931x - 16422x^2 + 5776x^3) / 4096; 705 // voice_mix_factor = (-5179 + 19931x - 16422x^2 + 5776x^3) / 4096;
706 // else 706 // else
707 // voice_mix_factor = 0; 707 // voice_mix_factor = 0;
708 if (corr_coefficient > 7875) { 708 if (corr_coefficient > 7875) {
709 int16_t x1, x2, x3; 709 int16_t x1, x2, x3;
710 // |corr_coefficient| is in Q14. 710 // |corr_coefficient| is in Q14.
711 x1 = static_cast<int16_t>(corr_coefficient); 711 x1 = static_cast<int16_t>(corr_coefficient);
712 x2 = (x1 * x1) >> 14; // Shift 14 to keep result in Q14. 712 x2 = (x1 * x1) >> 14; // Shift 14 to keep result in Q14.
713 x3 = (x1 * x2) >> 14; 713 x3 = (x1 * x2) >> 14;
714 static const int kCoefficients[4] = { -5179, 19931, -16422, 5776 }; 714 static const int kCoefficients[4] = { -5179, 19931, -16422, 5776 };
715 int32_t temp_sum = kCoefficients[0] << 14; 715 int32_t temp_sum = kCoefficients[0] * 16384;
716 temp_sum += kCoefficients[1] * x1; 716 temp_sum += kCoefficients[1] * x1;
717 temp_sum += kCoefficients[2] * x2; 717 temp_sum += kCoefficients[2] * x2;
718 temp_sum += kCoefficients[3] * x3; 718 temp_sum += kCoefficients[3] * x3;
719 parameters.voice_mix_factor = 719 parameters.voice_mix_factor =
720 static_cast<int16_t>(std::min(temp_sum / 4096, 16384)); 720 static_cast<int16_t>(std::min(temp_sum / 4096, 16384));
721 parameters.voice_mix_factor = std::max(parameters.voice_mix_factor, 721 parameters.voice_mix_factor = std::max(parameters.voice_mix_factor,
722 static_cast<int16_t>(0)); 722 static_cast<int16_t>(0));
723 } else { 723 } else {
724 parameters.voice_mix_factor = 0; 724 parameters.voice_mix_factor = 0;
725 } 725 }
(...skipping 18 matching lines...) Expand all
744 parameters.mute_slope = (temp_ratio + 1) / 2; 744 parameters.mute_slope = (temp_ratio + 1) / 2;
745 } else { 745 } else {
746 // Divide by 8, with proper rounding. 746 // Divide by 8, with proper rounding.
747 parameters.mute_slope = (temp_ratio + 4) / 8; 747 parameters.mute_slope = (temp_ratio + 4) / 8;
748 } 748 }
749 parameters.onset = true; 749 parameters.onset = true;
750 } else { 750 } else {
751 // Calculate (1 - slope) / distortion_lag. 751 // Calculate (1 - slope) / distortion_lag.
752 // Shift |slope| by 7 to Q20 before the division. The result is in Q20. 752 // Shift |slope| by 7 to Q20 before the division. The result is in Q20.
753 parameters.mute_slope = WebRtcSpl_DivW32W16( 753 parameters.mute_slope = WebRtcSpl_DivW32W16(
754 (8192 - slope) << 7, static_cast<int16_t>(distortion_lag)); 754 (8192 - slope) * 128, static_cast<int16_t>(distortion_lag));
755 if (parameters.voice_mix_factor <= 13107) { 755 if (parameters.voice_mix_factor <= 13107) {
756 // Make sure the mute factor decreases from 1.0 to 0.9 in no more than 756 // Make sure the mute factor decreases from 1.0 to 0.9 in no more than
757 // 6.25 ms. 757 // 6.25 ms.
758 // mute_slope >= 0.005 / fs_mult in Q20. 758 // mute_slope >= 0.005 / fs_mult in Q20.
759 parameters.mute_slope = std::max(5243 / fs_mult, parameters.mute_slope); 759 parameters.mute_slope = std::max(5243 / fs_mult, parameters.mute_slope);
760 } else if (slope > 8028) { 760 } else if (slope > 8028) {
761 parameters.mute_slope = 0; 761 parameters.mute_slope = 0;
762 } 762 }
763 parameters.onset = false; 763 parameters.onset = false;
764 } 764 }
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; 961 const size_t kMaxRandSamples = RandomVector::kRandomTableSize;
962 while (samples_generated < length) { 962 while (samples_generated < length) {
963 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); 963 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples);
964 random_vector_->IncreaseSeedIncrement(seed_increment); 964 random_vector_->IncreaseSeedIncrement(seed_increment);
965 random_vector_->Generate(rand_length, &random_vector[samples_generated]); 965 random_vector_->Generate(rand_length, &random_vector[samples_generated]);
966 samples_generated += rand_length; 966 samples_generated += rand_length;
967 } 967 }
968 } 968 }
969 969
970 } // namespace webrtc 970 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_audio/signal_processing/vector_scaling_operations.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698