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

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

Issue 1168753002: Match existing type usage better. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Attempted test fix Created 5 years, 6 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 DspHelper::CrossFade(voiced_vector, unvoiced_vector, temp_lenght, 220 DspHelper::CrossFade(voiced_vector, unvoiced_vector, temp_lenght,
221 &parameters.current_voice_mix_factor, 221 &parameters.current_voice_mix_factor,
222 mix_factor_increment, temp_data); 222 mix_factor_increment, temp_data);
223 223
224 // End of cross-fading period was reached before end of expanded signal 224 // End of cross-fading period was reached before end of expanded signal
225 // path. Mix the rest with a fixed mixing factor. 225 // path. Mix the rest with a fixed mixing factor.
226 if (temp_lenght < current_lag) { 226 if (temp_lenght < current_lag) {
227 if (mix_factor_increment != 0) { 227 if (mix_factor_increment != 0) {
228 parameters.current_voice_mix_factor = parameters.voice_mix_factor; 228 parameters.current_voice_mix_factor = parameters.voice_mix_factor;
229 } 229 }
230 int temp_scale = 16384 - parameters.current_voice_mix_factor; 230 int16_t temp_scale = 16384 - parameters.current_voice_mix_factor;
231 WebRtcSpl_ScaleAndAddVectorsWithRound( 231 WebRtcSpl_ScaleAndAddVectorsWithRound(
232 voiced_vector + temp_lenght, parameters.current_voice_mix_factor, 232 voiced_vector + temp_lenght, parameters.current_voice_mix_factor,
233 unvoiced_vector + temp_lenght, temp_scale, 14, 233 unvoiced_vector + temp_lenght, temp_scale, 14,
234 temp_data + temp_lenght, static_cast<int>(current_lag - temp_lenght)); 234 temp_data + temp_lenght, static_cast<int>(current_lag - temp_lenght));
235 } 235 }
236 236
237 // Select muting slope depending on how many consecutive expands we have 237 // Select muting slope depending on how many consecutive expands we have
238 // done. 238 // done.
239 if (consecutive_expands_ == 3) { 239 if (consecutive_expands_ == 3) {
240 // Let the mute factor decrease from 1.0 to 0.95 in 6.25 ms. 240 // Let the mute factor decrease from 1.0 to 0.95 in 6.25 ms.
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 128, 664 128,
665 unvoiced_prescale); 665 unvoiced_prescale);
666 666
667 // Normalize |unvoiced_energy| to 28 or 29 bits to preserve sqrt() accuracy. 667 // Normalize |unvoiced_energy| to 28 or 29 bits to preserve sqrt() accuracy.
668 int16_t unvoiced_scale = WebRtcSpl_NormW32(unvoiced_energy) - 3; 668 int16_t unvoiced_scale = WebRtcSpl_NormW32(unvoiced_energy) - 3;
669 // Make sure we do an odd number of shifts since we already have 7 shifts 669 // Make sure we do an odd number of shifts since we already have 7 shifts
670 // from dividing with 128 earlier. This will make the total scale factor 670 // from dividing with 128 earlier. This will make the total scale factor
671 // even, which is suitable for the sqrt. 671 // even, which is suitable for the sqrt.
672 unvoiced_scale += ((unvoiced_scale & 0x1) ^ 0x1); 672 unvoiced_scale += ((unvoiced_scale & 0x1) ^ 0x1);
673 unvoiced_energy = WEBRTC_SPL_SHIFT_W32(unvoiced_energy, unvoiced_scale); 673 unvoiced_energy = WEBRTC_SPL_SHIFT_W32(unvoiced_energy, unvoiced_scale);
674 int32_t unvoiced_gain = WebRtcSpl_SqrtFloor(unvoiced_energy); 674 int16_t unvoiced_gain =
675 static_cast<int16_t>(WebRtcSpl_SqrtFloor(unvoiced_energy));
675 parameters.ar_gain_scale = 13 676 parameters.ar_gain_scale = 13
676 + (unvoiced_scale + 7 - unvoiced_prescale) / 2; 677 + (unvoiced_scale + 7 - unvoiced_prescale) / 2;
677 parameters.ar_gain = unvoiced_gain; 678 parameters.ar_gain = unvoiced_gain;
678 679
679 // Calculate voice_mix_factor from corr_coefficient. 680 // Calculate voice_mix_factor from corr_coefficient.
680 // Let x = corr_coefficient. Then, we compute: 681 // Let x = corr_coefficient. Then, we compute:
681 // if (x > 0.48) 682 // if (x > 0.48)
682 // voice_mix_factor = (-5179 + 19931x - 16422x^2 + 5776x^3) / 4096; 683 // voice_mix_factor = (-5179 + 19931x - 16422x^2 + 5776x^3) / 4096;
683 // else 684 // else
684 // voice_mix_factor = 0; 685 // voice_mix_factor = 0;
(...skipping 20 matching lines...) Expand all
705 // |expand_vector0| and |expand_vector1|. 706 // |expand_vector0| and |expand_vector1|.
706 int16_t slope = amplitude_ratio; 707 int16_t slope = amplitude_ratio;
707 if (slope > 12288) { 708 if (slope > 12288) {
708 // slope > 1.5. 709 // slope > 1.5.
709 // Calculate (1 - (1 / slope)) / distortion_lag = 710 // Calculate (1 - (1 / slope)) / distortion_lag =
710 // (slope - 1) / (distortion_lag * slope). 711 // (slope - 1) / (distortion_lag * slope).
711 // |slope| is in Q13, so 1 corresponds to 8192. Shift up to Q25 before 712 // |slope| is in Q13, so 1 corresponds to 8192. Shift up to Q25 before
712 // the division. 713 // the division.
713 // Shift the denominator from Q13 to Q5 before the division. The result of 714 // Shift the denominator from Q13 to Q5 before the division. The result of
714 // the division will then be in Q20. 715 // the division will then be in Q20.
715 int16_t temp_ratio = WebRtcSpl_DivW32W16((slope - 8192) << 12, 716 int16_t temp_ratio = WebRtcSpl_DivW32W16(
716 (distortion_lag * slope) >> 8); 717 (slope - 8192) << 12,
718 static_cast<int16_t>((distortion_lag * slope) >> 8));
717 if (slope > 14746) { 719 if (slope > 14746) {
718 // slope > 1.8. 720 // slope > 1.8.
719 // Divide by 2, with proper rounding. 721 // Divide by 2, with proper rounding.
720 parameters.mute_slope = (temp_ratio + 1) / 2; 722 parameters.mute_slope = (temp_ratio + 1) / 2;
721 } else { 723 } else {
722 // Divide by 8, with proper rounding. 724 // Divide by 8, with proper rounding.
723 parameters.mute_slope = (temp_ratio + 4) / 8; 725 parameters.mute_slope = (temp_ratio + 4) / 8;
724 } 726 }
725 parameters.onset = true; 727 parameters.onset = true;
726 } else { 728 } else {
727 // Calculate (1 - slope) / distortion_lag. 729 // Calculate (1 - slope) / distortion_lag.
728 // Shift |slope| by 7 to Q20 before the division. The result is in Q20. 730 // Shift |slope| by 7 to Q20 before the division. The result is in Q20.
729 parameters.mute_slope = WebRtcSpl_DivW32W16((8192 - slope) << 7, 731 parameters.mute_slope = WebRtcSpl_DivW32W16(
730 distortion_lag); 732 (8192 - slope) << 7, static_cast<int16_t>(distortion_lag));
731 if (parameters.voice_mix_factor <= 13107) { 733 if (parameters.voice_mix_factor <= 13107) {
732 // Make sure the mute factor decreases from 1.0 to 0.9 in no more than 734 // Make sure the mute factor decreases from 1.0 to 0.9 in no more than
733 // 6.25 ms. 735 // 6.25 ms.
734 // mute_slope >= 0.005 / fs_mult in Q20. 736 // mute_slope >= 0.005 / fs_mult in Q20.
735 parameters.mute_slope = std::max(static_cast<int16_t>(5243 / fs_mult), 737 parameters.mute_slope = std::max(static_cast<int16_t>(5243 / fs_mult),
736 parameters.mute_slope); 738 parameters.mute_slope);
737 } else if (slope > 8028) { 739 } else if (slope > 8028) {
738 parameters.mute_slope = 0; 740 parameters.mute_slope = 0;
739 } 741 }
740 parameters.onset = false; 742 parameters.onset = false;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 WebRtcSpl_CrossCorrelation( 808 WebRtcSpl_CrossCorrelation(
807 correlation, 809 correlation,
808 &downsampled_input[kDownsampledLength - kCorrelationLength], 810 &downsampled_input[kDownsampledLength - kCorrelationLength],
809 &downsampled_input[kDownsampledLength - kCorrelationLength 811 &downsampled_input[kDownsampledLength - kCorrelationLength
810 - kCorrelationStartLag], 812 - kCorrelationStartLag],
811 kCorrelationLength, kNumCorrelationLags, kCorrelationShift, -1); 813 kCorrelationLength, kNumCorrelationLags, kCorrelationShift, -1);
812 814
813 // Normalize and move data from 32-bit to 16-bit vector. 815 // Normalize and move data from 32-bit to 16-bit vector.
814 int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation, 816 int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation,
815 kNumCorrelationLags); 817 kNumCorrelationLags);
816 int16_t norm_shift2 = std::max(18 - WebRtcSpl_NormW32(max_correlation), 0); 818 int16_t norm_shift2 = static_cast<int16_t>(
819 std::max(18 - WebRtcSpl_NormW32(max_correlation), 0));
817 WebRtcSpl_VectorBitShiftW32ToW16(output, kNumCorrelationLags, correlation, 820 WebRtcSpl_VectorBitShiftW32ToW16(output, kNumCorrelationLags, correlation,
818 norm_shift2); 821 norm_shift2);
819 // Total scale factor (right shifts) of correlation value. 822 // Total scale factor (right shifts) of correlation value.
820 *output_scale = 2 * norm_shift + kCorrelationShift + norm_shift2; 823 *output_scale = 2 * norm_shift + kCorrelationShift + norm_shift2;
821 return kNumCorrelationLags; 824 return kNumCorrelationLags;
822 } 825 }
823 826
824 void Expand::UpdateLagIndex() { 827 void Expand::UpdateLagIndex() {
825 current_lag_index_ = current_lag_index_ + lag_index_direction_; 828 current_lag_index_ = current_lag_index_ + lag_index_direction_;
826 // Change direction if needed. 829 // Change direction if needed.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 } 927 }
925 } 928 }
926 // Update mute_factor in BackgroundNoise class. 929 // Update mute_factor in BackgroundNoise class.
927 background_noise_->SetMuteFactor(channel, bgn_mute_factor); 930 background_noise_->SetMuteFactor(channel, bgn_mute_factor);
928 } else { 931 } else {
929 // BGN parameters have not been initialized; use zero noise. 932 // BGN parameters have not been initialized; use zero noise.
930 memset(noise_samples, 0, sizeof(int16_t) * num_noise_samples); 933 memset(noise_samples, 0, sizeof(int16_t) * num_noise_samples);
931 } 934 }
932 } 935 }
933 936
934 void Expand::GenerateRandomVector(int seed_increment, 937 void Expand::GenerateRandomVector(int16_t seed_increment,
935 size_t length, 938 size_t length,
936 int16_t* random_vector) { 939 int16_t* random_vector) {
937 // TODO(turajs): According to hlundin The loop should not be needed. Should be 940 // TODO(turajs): According to hlundin The loop should not be needed. Should be
938 // just as good to generate all of the vector in one call. 941 // just as good to generate all of the vector in one call.
939 size_t samples_generated = 0; 942 size_t samples_generated = 0;
940 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; 943 const size_t kMaxRandSamples = RandomVector::kRandomTableSize;
941 while (samples_generated < length) { 944 while (samples_generated < length) {
942 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); 945 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples);
943 random_vector_->IncreaseSeedIncrement(seed_increment); 946 random_vector_->IncreaseSeedIncrement(seed_increment);
944 random_vector_->Generate(rand_length, &random_vector[samples_generated]); 947 random_vector_->Generate(rand_length, &random_vector[samples_generated]);
945 samples_generated += rand_length; 948 samples_generated += rand_length;
946 } 949 }
947 } 950 }
948 951
949 } // namespace webrtc 952 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698