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

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: Resync 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
« no previous file with comments | « webrtc/modules/audio_coding/neteq/expand.h ('k') | webrtc/modules/audio_coding/neteq/merge.cc » ('j') | 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 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 128, 662 128,
663 unvoiced_prescale); 663 unvoiced_prescale);
664 664
665 // Normalize |unvoiced_energy| to 28 or 29 bits to preserve sqrt() accuracy. 665 // Normalize |unvoiced_energy| to 28 or 29 bits to preserve sqrt() accuracy.
666 int16_t unvoiced_scale = WebRtcSpl_NormW32(unvoiced_energy) - 3; 666 int16_t unvoiced_scale = WebRtcSpl_NormW32(unvoiced_energy) - 3;
667 // Make sure we do an odd number of shifts since we already have 7 shifts 667 // Make sure we do an odd number of shifts since we already have 7 shifts
668 // from dividing with 128 earlier. This will make the total scale factor 668 // from dividing with 128 earlier. This will make the total scale factor
669 // even, which is suitable for the sqrt. 669 // even, which is suitable for the sqrt.
670 unvoiced_scale += ((unvoiced_scale & 0x1) ^ 0x1); 670 unvoiced_scale += ((unvoiced_scale & 0x1) ^ 0x1);
671 unvoiced_energy = WEBRTC_SPL_SHIFT_W32(unvoiced_energy, unvoiced_scale); 671 unvoiced_energy = WEBRTC_SPL_SHIFT_W32(unvoiced_energy, unvoiced_scale);
672 int32_t unvoiced_gain = WebRtcSpl_SqrtFloor(unvoiced_energy); 672 int16_t unvoiced_gain =
673 static_cast<int16_t>(WebRtcSpl_SqrtFloor(unvoiced_energy));
673 parameters.ar_gain_scale = 13 674 parameters.ar_gain_scale = 13
674 + (unvoiced_scale + 7 - unvoiced_prescale) / 2; 675 + (unvoiced_scale + 7 - unvoiced_prescale) / 2;
675 parameters.ar_gain = unvoiced_gain; 676 parameters.ar_gain = unvoiced_gain;
676 677
677 // Calculate voice_mix_factor from corr_coefficient. 678 // Calculate voice_mix_factor from corr_coefficient.
678 // Let x = corr_coefficient. Then, we compute: 679 // Let x = corr_coefficient. Then, we compute:
679 // if (x > 0.48) 680 // if (x > 0.48)
680 // voice_mix_factor = (-5179 + 19931x - 16422x^2 + 5776x^3) / 4096; 681 // voice_mix_factor = (-5179 + 19931x - 16422x^2 + 5776x^3) / 4096;
681 // else 682 // else
682 // voice_mix_factor = 0; 683 // voice_mix_factor = 0;
(...skipping 19 matching lines...) Expand all
702 // |expand_vector0| and |expand_vector1|. 703 // |expand_vector0| and |expand_vector1|.
703 int16_t slope = amplitude_ratio; 704 int16_t slope = amplitude_ratio;
704 if (slope > 12288) { 705 if (slope > 12288) {
705 // slope > 1.5. 706 // slope > 1.5.
706 // Calculate (1 - (1 / slope)) / distortion_lag = 707 // Calculate (1 - (1 / slope)) / distortion_lag =
707 // (slope - 1) / (distortion_lag * slope). 708 // (slope - 1) / (distortion_lag * slope).
708 // |slope| is in Q13, so 1 corresponds to 8192. Shift up to Q25 before 709 // |slope| is in Q13, so 1 corresponds to 8192. Shift up to Q25 before
709 // the division. 710 // the division.
710 // Shift the denominator from Q13 to Q5 before the division. The result of 711 // Shift the denominator from Q13 to Q5 before the division. The result of
711 // the division will then be in Q20. 712 // the division will then be in Q20.
712 int16_t temp_ratio = WebRtcSpl_DivW32W16((slope - 8192) << 12, 713 int16_t temp_ratio = WebRtcSpl_DivW32W16(
713 (distortion_lag * slope) >> 8); 714 (slope - 8192) << 12,
715 static_cast<int16_t>((distortion_lag * slope) >> 8));
714 if (slope > 14746) { 716 if (slope > 14746) {
715 // slope > 1.8. 717 // slope > 1.8.
716 // Divide by 2, with proper rounding. 718 // Divide by 2, with proper rounding.
717 parameters.mute_slope = (temp_ratio + 1) / 2; 719 parameters.mute_slope = (temp_ratio + 1) / 2;
718 } else { 720 } else {
719 // Divide by 8, with proper rounding. 721 // Divide by 8, with proper rounding.
720 parameters.mute_slope = (temp_ratio + 4) / 8; 722 parameters.mute_slope = (temp_ratio + 4) / 8;
721 } 723 }
722 parameters.onset = true; 724 parameters.onset = true;
723 } else { 725 } else {
724 // Calculate (1 - slope) / distortion_lag. 726 // Calculate (1 - slope) / distortion_lag.
725 // Shift |slope| by 7 to Q20 before the division. The result is in Q20. 727 // Shift |slope| by 7 to Q20 before the division. The result is in Q20.
726 parameters.mute_slope = WebRtcSpl_DivW32W16((8192 - slope) << 7, 728 parameters.mute_slope = WebRtcSpl_DivW32W16(
727 distortion_lag); 729 (8192 - slope) << 7, static_cast<int16_t>(distortion_lag));
728 if (parameters.voice_mix_factor <= 13107) { 730 if (parameters.voice_mix_factor <= 13107) {
729 // Make sure the mute factor decreases from 1.0 to 0.9 in no more than 731 // Make sure the mute factor decreases from 1.0 to 0.9 in no more than
730 // 6.25 ms. 732 // 6.25 ms.
731 // mute_slope >= 0.005 / fs_mult in Q20. 733 // mute_slope >= 0.005 / fs_mult in Q20.
732 parameters.mute_slope = std::max(static_cast<int16_t>(5243 / fs_mult), 734 parameters.mute_slope = std::max(static_cast<int16_t>(5243 / fs_mult),
733 parameters.mute_slope); 735 parameters.mute_slope);
734 } else if (slope > 8028) { 736 } else if (slope > 8028) {
735 parameters.mute_slope = 0; 737 parameters.mute_slope = 0;
736 } 738 }
737 parameters.onset = false; 739 parameters.onset = false;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 WebRtcSpl_CrossCorrelation( 805 WebRtcSpl_CrossCorrelation(
804 correlation, 806 correlation,
805 &downsampled_input[kDownsampledLength - kCorrelationLength], 807 &downsampled_input[kDownsampledLength - kCorrelationLength],
806 &downsampled_input[kDownsampledLength - kCorrelationLength 808 &downsampled_input[kDownsampledLength - kCorrelationLength
807 - kCorrelationStartLag], 809 - kCorrelationStartLag],
808 kCorrelationLength, kNumCorrelationLags, kCorrelationShift, -1); 810 kCorrelationLength, kNumCorrelationLags, kCorrelationShift, -1);
809 811
810 // Normalize and move data from 32-bit to 16-bit vector. 812 // Normalize and move data from 32-bit to 16-bit vector.
811 int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation, 813 int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation,
812 kNumCorrelationLags); 814 kNumCorrelationLags);
813 int16_t norm_shift2 = std::max(18 - WebRtcSpl_NormW32(max_correlation), 0); 815 int16_t norm_shift2 = static_cast<int16_t>(
816 std::max(18 - WebRtcSpl_NormW32(max_correlation), 0));
814 WebRtcSpl_VectorBitShiftW32ToW16(output, kNumCorrelationLags, correlation, 817 WebRtcSpl_VectorBitShiftW32ToW16(output, kNumCorrelationLags, correlation,
815 norm_shift2); 818 norm_shift2);
816 // Total scale factor (right shifts) of correlation value. 819 // Total scale factor (right shifts) of correlation value.
817 *output_scale = 2 * norm_shift + kCorrelationShift + norm_shift2; 820 *output_scale = 2 * norm_shift + kCorrelationShift + norm_shift2;
818 return kNumCorrelationLags; 821 return kNumCorrelationLags;
819 } 822 }
820 823
821 void Expand::UpdateLagIndex() { 824 void Expand::UpdateLagIndex() {
822 current_lag_index_ = current_lag_index_ + lag_index_direction_; 825 current_lag_index_ = current_lag_index_ + lag_index_direction_;
823 // Change direction if needed. 826 // Change direction if needed.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 } 924 }
922 } 925 }
923 // Update mute_factor in BackgroundNoise class. 926 // Update mute_factor in BackgroundNoise class.
924 background_noise_->SetMuteFactor(channel, bgn_mute_factor); 927 background_noise_->SetMuteFactor(channel, bgn_mute_factor);
925 } else { 928 } else {
926 // BGN parameters have not been initialized; use zero noise. 929 // BGN parameters have not been initialized; use zero noise.
927 memset(noise_samples, 0, sizeof(int16_t) * num_noise_samples); 930 memset(noise_samples, 0, sizeof(int16_t) * num_noise_samples);
928 } 931 }
929 } 932 }
930 933
931 void Expand::GenerateRandomVector(int seed_increment, 934 void Expand::GenerateRandomVector(int16_t seed_increment,
932 size_t length, 935 size_t length,
933 int16_t* random_vector) { 936 int16_t* random_vector) {
934 // TODO(turajs): According to hlundin The loop should not be needed. Should be 937 // TODO(turajs): According to hlundin The loop should not be needed. Should be
935 // just as good to generate all of the vector in one call. 938 // just as good to generate all of the vector in one call.
936 size_t samples_generated = 0; 939 size_t samples_generated = 0;
937 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; 940 const size_t kMaxRandSamples = RandomVector::kRandomTableSize;
938 while (samples_generated < length) { 941 while (samples_generated < length) {
939 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); 942 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples);
940 random_vector_->IncreaseSeedIncrement(seed_increment); 943 random_vector_->IncreaseSeedIncrement(seed_increment);
941 random_vector_->Generate(rand_length, &random_vector[samples_generated]); 944 random_vector_->Generate(rand_length, &random_vector[samples_generated]);
942 samples_generated += rand_length; 945 samples_generated += rand_length;
943 } 946 }
944 } 947 }
945 948
946 } // namespace webrtc 949 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/expand.h ('k') | webrtc/modules/audio_coding/neteq/merge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698