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

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

Issue 1172163004: Reformat existing code. There should be no functional effects. (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
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // >= 64 * fs_mult => go from 1 to 0 in about 32 ms. 207 // >= 64 * fs_mult => go from 1 to 0 in about 32 ms.
208 // temp_shift = getbits(max_lag_) - 5. 208 // temp_shift = getbits(max_lag_) - 5.
209 int temp_shift = (31 - WebRtcSpl_NormW32(max_lag_)) - 5; 209 int temp_shift = (31 - WebRtcSpl_NormW32(max_lag_)) - 5;
210 int16_t mix_factor_increment = 256 >> temp_shift; 210 int16_t mix_factor_increment = 256 >> temp_shift;
211 if (stop_muting_) { 211 if (stop_muting_) {
212 mix_factor_increment = 0; 212 mix_factor_increment = 0;
213 } 213 }
214 214
215 // Create combined signal by shifting in more and more of unvoiced part. 215 // Create combined signal by shifting in more and more of unvoiced part.
216 temp_shift = 8 - temp_shift; // = getbits(mix_factor_increment). 216 temp_shift = 8 - temp_shift; // = getbits(mix_factor_increment).
217 size_t temp_lenght = (parameters.current_voice_mix_factor - 217 size_t temp_length = (parameters.current_voice_mix_factor -
218 parameters.voice_mix_factor) >> temp_shift; 218 parameters.voice_mix_factor) >> temp_shift;
219 temp_lenght = std::min(temp_lenght, current_lag); 219 temp_length = std::min(temp_length, current_lag);
220 DspHelper::CrossFade(voiced_vector, unvoiced_vector, temp_lenght, 220 DspHelper::CrossFade(voiced_vector, unvoiced_vector, temp_length,
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_length < 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 int16_t 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_length, parameters.current_voice_mix_factor,
233 unvoiced_vector + temp_lenght, temp_scale, 14, 233 unvoiced_vector + temp_length, temp_scale, 14,
234 temp_data + temp_lenght, static_cast<int>(current_lag - temp_lenght)); 234 temp_data + temp_length, static_cast<int>(current_lag - temp_length));
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.
241 // mute_slope = 0.0010 / fs_mult in Q20. 241 // mute_slope = 0.0010 / fs_mult in Q20.
242 parameters.mute_slope = std::max(parameters.mute_slope, 242 parameters.mute_slope = std::max(parameters.mute_slope,
243 static_cast<int16_t>(1049 / fs_mult)); 243 static_cast<int16_t>(1049 / fs_mult));
244 } 244 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 best_ratio = ratio; 421 best_ratio = ratio;
422 } 422 }
423 } 423 }
424 424
425 int distortion_lag = best_distortion_index[best_index]; 425 int distortion_lag = best_distortion_index[best_index];
426 int correlation_lag = best_correlation_index[best_index]; 426 int correlation_lag = best_correlation_index[best_index];
427 max_lag_ = std::max(distortion_lag, correlation_lag); 427 max_lag_ = std::max(distortion_lag, correlation_lag);
428 428
429 // Calculate the exact best correlation in the range between 429 // Calculate the exact best correlation in the range between
430 // |correlation_lag| and |distortion_lag|. 430 // |correlation_lag| and |distortion_lag|.
431 correlation_length = distortion_lag + 10; 431 correlation_length =
432 correlation_length = std::min(correlation_length, fs_mult_120); 432 std::max(std::min(distortion_lag + 10, fs_mult_120), 60 * fs_mult);
433 correlation_length = std::max(correlation_length, 60 * fs_mult);
434 433
435 int start_index = std::min(distortion_lag, correlation_lag); 434 int start_index = std::min(distortion_lag, correlation_lag);
436 int correlation_lags = WEBRTC_SPL_ABS_W16((distortion_lag-correlation_lag)) 435 int correlation_lags =
437 + 1; 436 WEBRTC_SPL_ABS_W16((distortion_lag-correlation_lag)) + 1;
438 assert(correlation_lags <= 99 * fs_mult + 1); // Cannot be larger. 437 assert(correlation_lags <= 99 * fs_mult + 1); // Cannot be larger.
439 438
440 for (size_t channel_ix = 0; channel_ix < num_channels_; ++channel_ix) { 439 for (size_t channel_ix = 0; channel_ix < num_channels_; ++channel_ix) {
441 ChannelParameters& parameters = channel_parameters_[channel_ix]; 440 ChannelParameters& parameters = channel_parameters_[channel_ix];
442 // Calculate suitable scaling. 441 // Calculate suitable scaling.
443 int16_t signal_max = WebRtcSpl_MaxAbsValueW16( 442 int16_t signal_max = WebRtcSpl_MaxAbsValueW16(
444 &audio_history[signal_length - correlation_length - start_index 443 &audio_history[signal_length - correlation_length - start_index
445 - correlation_lags], 444 - correlation_lags],
446 correlation_length + start_index + correlation_lags - 1); 445 correlation_length + start_index + correlation_lags - 1);
447 correlation_scale = ((31 - WebRtcSpl_NormW32(signal_max * signal_max)) 446 correlation_scale = ((31 - WebRtcSpl_NormW32(signal_max * signal_max))
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 ar_gain(0), 745 ar_gain(0),
747 ar_gain_scale(0), 746 ar_gain_scale(0),
748 voice_mix_factor(0), 747 voice_mix_factor(0),
749 current_voice_mix_factor(0), 748 current_voice_mix_factor(0),
750 onset(false), 749 onset(false),
751 mute_slope(0) { 750 mute_slope(0) {
752 memset(ar_filter, 0, sizeof(ar_filter)); 751 memset(ar_filter, 0, sizeof(ar_filter));
753 memset(ar_filter_state, 0, sizeof(ar_filter_state)); 752 memset(ar_filter_state, 0, sizeof(ar_filter_state));
754 } 753 }
755 754
756 int16_t Expand::Correlation(const int16_t* input, size_t input_length, 755 void Expand::Correlation(const int16_t* input,
757 int16_t* output, int16_t* output_scale) const { 756 size_t input_length,
757 int16_t* output,
758 int16_t* output_scale) const {
758 // Set parameters depending on sample rate. 759 // Set parameters depending on sample rate.
759 const int16_t* filter_coefficients; 760 const int16_t* filter_coefficients;
760 int16_t num_coefficients; 761 int16_t num_coefficients;
761 int16_t downsampling_factor; 762 int16_t downsampling_factor;
762 if (fs_hz_ == 8000) { 763 if (fs_hz_ == 8000) {
763 num_coefficients = 3; 764 num_coefficients = 3;
764 downsampling_factor = 2; 765 downsampling_factor = 2;
765 filter_coefficients = DspHelper::kDownsample8kHzTbl; 766 filter_coefficients = DspHelper::kDownsample8kHzTbl;
766 } else if (fs_hz_ == 16000) { 767 } else if (fs_hz_ == 16000) {
767 num_coefficients = 5; 768 num_coefficients = 5;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 812
812 // Normalize and move data from 32-bit to 16-bit vector. 813 // Normalize and move data from 32-bit to 16-bit vector.
813 int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation, 814 int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation,
814 kNumCorrelationLags); 815 kNumCorrelationLags);
815 int16_t norm_shift2 = static_cast<int16_t>( 816 int16_t norm_shift2 = static_cast<int16_t>(
816 std::max(18 - WebRtcSpl_NormW32(max_correlation), 0)); 817 std::max(18 - WebRtcSpl_NormW32(max_correlation), 0));
817 WebRtcSpl_VectorBitShiftW32ToW16(output, kNumCorrelationLags, correlation, 818 WebRtcSpl_VectorBitShiftW32ToW16(output, kNumCorrelationLags, correlation,
818 norm_shift2); 819 norm_shift2);
819 // Total scale factor (right shifts) of correlation value. 820 // Total scale factor (right shifts) of correlation value.
820 *output_scale = 2 * norm_shift + kCorrelationShift + norm_shift2; 821 *output_scale = 2 * norm_shift + kCorrelationShift + norm_shift2;
821 return kNumCorrelationLags;
822 } 822 }
823 823
824 void Expand::UpdateLagIndex() { 824 void Expand::UpdateLagIndex() {
825 current_lag_index_ = current_lag_index_ + lag_index_direction_; 825 current_lag_index_ = current_lag_index_ + lag_index_direction_;
826 // Change direction if needed. 826 // Change direction if needed.
827 if (current_lag_index_ <= 0) { 827 if (current_lag_index_ <= 0) {
828 lag_index_direction_ = 1; 828 lag_index_direction_ = 1;
829 } 829 }
830 if (current_lag_index_ >= kNumLags - 1) { 830 if (current_lag_index_ >= kNumLags - 1) {
831 lag_index_direction_ = -1; 831 lag_index_direction_ = -1;
(...skipping 11 matching lines...) Expand all
843 843
844 // TODO(turajs): This can be moved to BackgroundNoise class. 844 // TODO(turajs): This can be moved to BackgroundNoise class.
845 void Expand::GenerateBackgroundNoise(int16_t* random_vector, 845 void Expand::GenerateBackgroundNoise(int16_t* random_vector,
846 size_t channel, 846 size_t channel,
847 int16_t mute_slope, 847 int16_t mute_slope,
848 bool too_many_expands, 848 bool too_many_expands,
849 size_t num_noise_samples, 849 size_t num_noise_samples,
850 int16_t* buffer) { 850 int16_t* buffer) {
851 static const int kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder; 851 static const int kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder;
852 int16_t scaled_random_vector[kMaxSampleRate / 8000 * 125]; 852 int16_t scaled_random_vector[kMaxSampleRate / 8000 * 125];
853 assert(static_cast<size_t>(kMaxSampleRate / 8000 * 125) >= num_noise_samples); 853 assert(num_noise_samples <= static_cast<size_t>(kMaxSampleRate / 8000 * 125));
854 int16_t* noise_samples = &buffer[kNoiseLpcOrder]; 854 int16_t* noise_samples = &buffer[kNoiseLpcOrder];
855 if (background_noise_->initialized()) { 855 if (background_noise_->initialized()) {
856 // Use background noise parameters. 856 // Use background noise parameters.
857 memcpy(noise_samples - kNoiseLpcOrder, 857 memcpy(noise_samples - kNoiseLpcOrder,
858 background_noise_->FilterState(channel), 858 background_noise_->FilterState(channel),
859 sizeof(int16_t) * kNoiseLpcOrder); 859 sizeof(int16_t) * kNoiseLpcOrder);
860 860
861 int dc_offset = 0; 861 int dc_offset = 0;
862 if (background_noise_->ScaleShift(channel) > 1) { 862 if (background_noise_->ScaleShift(channel) > 1) {
863 dc_offset = 1 << (background_noise_->ScaleShift(channel) - 1); 863 dc_offset = 1 << (background_noise_->ScaleShift(channel) - 1);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; 940 const size_t kMaxRandSamples = RandomVector::kRandomTableSize;
941 while (samples_generated < length) { 941 while (samples_generated < length) {
942 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); 942 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples);
943 random_vector_->IncreaseSeedIncrement(seed_increment); 943 random_vector_->IncreaseSeedIncrement(seed_increment);
944 random_vector_->Generate(rand_length, &random_vector[samples_generated]); 944 random_vector_->Generate(rand_length, &random_vector[samples_generated]);
945 samples_generated += rand_length; 945 samples_generated += rand_length;
946 } 946 }
947 } 947 }
948 948
949 } // namespace webrtc 949 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698