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

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: 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 int temp_scale = 16384 - parameters.current_voice_mix_factor; 230 int 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, 1049 / fs_mult); 242 parameters.mute_slope = std::max(parameters.mute_slope, 1049 / fs_mult);
243 } 243 }
244 if (consecutive_expands_ == 7) { 244 if (consecutive_expands_ == 7) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 best_ratio = ratio; 419 best_ratio = ratio;
420 } 420 }
421 } 421 }
422 422
423 int distortion_lag = best_distortion_index[best_index]; 423 int distortion_lag = best_distortion_index[best_index];
424 int correlation_lag = best_correlation_index[best_index]; 424 int correlation_lag = best_correlation_index[best_index];
425 max_lag_ = std::max(distortion_lag, correlation_lag); 425 max_lag_ = std::max(distortion_lag, correlation_lag);
426 426
427 // Calculate the exact best correlation in the range between 427 // Calculate the exact best correlation in the range between
428 // |correlation_lag| and |distortion_lag|. 428 // |correlation_lag| and |distortion_lag|.
429 correlation_length = distortion_lag + 10; 429 correlation_length =
430 correlation_length = std::min(correlation_length, fs_mult_120); 430 std::max(std::min(distortion_lag + 10, fs_mult_120), 60 * fs_mult);
431 correlation_length = std::max(correlation_length, 60 * fs_mult);
432 431
433 int start_index = std::min(distortion_lag, correlation_lag); 432 int start_index = std::min(distortion_lag, correlation_lag);
434 int correlation_lags = WEBRTC_SPL_ABS_W16((distortion_lag-correlation_lag)) 433 int correlation_lags =
435 + 1; 434 WEBRTC_SPL_ABS_W16((distortion_lag-correlation_lag)) + 1;
436 assert(correlation_lags <= 99 * fs_mult + 1); // Cannot be larger. 435 assert(correlation_lags <= 99 * fs_mult + 1); // Cannot be larger.
437 436
438 for (size_t channel_ix = 0; channel_ix < num_channels_; ++channel_ix) { 437 for (size_t channel_ix = 0; channel_ix < num_channels_; ++channel_ix) {
439 ChannelParameters& parameters = channel_parameters_[channel_ix]; 438 ChannelParameters& parameters = channel_parameters_[channel_ix];
440 // Calculate suitable scaling. 439 // Calculate suitable scaling.
441 int16_t signal_max = WebRtcSpl_MaxAbsValueW16( 440 int16_t signal_max = WebRtcSpl_MaxAbsValueW16(
442 &audio_history[signal_length - correlation_length - start_index 441 &audio_history[signal_length - correlation_length - start_index
443 - correlation_lags], 442 - correlation_lags],
444 correlation_length + start_index + correlation_lags - 1); 443 correlation_length + start_index + correlation_lags - 1);
445 correlation_scale = ((31 - WebRtcSpl_NormW32(signal_max * signal_max)) 444 correlation_scale = ((31 - WebRtcSpl_NormW32(signal_max * signal_max))
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 ar_gain(0), 744 ar_gain(0),
746 ar_gain_scale(0), 745 ar_gain_scale(0),
747 voice_mix_factor(0), 746 voice_mix_factor(0),
748 current_voice_mix_factor(0), 747 current_voice_mix_factor(0),
749 onset(false), 748 onset(false),
750 mute_slope(0) { 749 mute_slope(0) {
751 memset(ar_filter, 0, sizeof(ar_filter)); 750 memset(ar_filter, 0, sizeof(ar_filter));
752 memset(ar_filter_state, 0, sizeof(ar_filter_state)); 751 memset(ar_filter_state, 0, sizeof(ar_filter_state));
753 } 752 }
754 753
755 int16_t Expand::Correlation(const int16_t* input, size_t input_length, 754 void Expand::Correlation(const int16_t* input,
756 int16_t* output, int* output_scale) const { 755 size_t input_length,
756 int16_t* output,
757 int* output_scale) const {
757 // Set parameters depending on sample rate. 758 // Set parameters depending on sample rate.
758 const int16_t* filter_coefficients; 759 const int16_t* filter_coefficients;
759 int16_t num_coefficients; 760 int16_t num_coefficients;
760 int16_t downsampling_factor; 761 int16_t downsampling_factor;
761 if (fs_hz_ == 8000) { 762 if (fs_hz_ == 8000) {
762 num_coefficients = 3; 763 num_coefficients = 3;
763 downsampling_factor = 2; 764 downsampling_factor = 2;
764 filter_coefficients = DspHelper::kDownsample8kHzTbl; 765 filter_coefficients = DspHelper::kDownsample8kHzTbl;
765 } else if (fs_hz_ == 16000) { 766 } else if (fs_hz_ == 16000) {
766 num_coefficients = 5; 767 num_coefficients = 5;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 kCorrelationLength, kNumCorrelationLags, kCorrelationShift, -1); 810 kCorrelationLength, kNumCorrelationLags, kCorrelationShift, -1);
810 811
811 // Normalize and move data from 32-bit to 16-bit vector. 812 // Normalize and move data from 32-bit to 16-bit vector.
812 int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation, 813 int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation,
813 kNumCorrelationLags); 814 kNumCorrelationLags);
814 int16_t norm_shift2 = std::max(18 - WebRtcSpl_NormW32(max_correlation), 0); 815 int16_t norm_shift2 = std::max(18 - WebRtcSpl_NormW32(max_correlation), 0);
815 WebRtcSpl_VectorBitShiftW32ToW16(output, kNumCorrelationLags, correlation, 816 WebRtcSpl_VectorBitShiftW32ToW16(output, kNumCorrelationLags, correlation,
816 norm_shift2); 817 norm_shift2);
817 // Total scale factor (right shifts) of correlation value. 818 // Total scale factor (right shifts) of correlation value.
818 *output_scale = 2 * norm_shift + kCorrelationShift + norm_shift2; 819 *output_scale = 2 * norm_shift + kCorrelationShift + norm_shift2;
819 return kNumCorrelationLags;
820 } 820 }
821 821
822 void Expand::UpdateLagIndex() { 822 void Expand::UpdateLagIndex() {
823 current_lag_index_ = current_lag_index_ + lag_index_direction_; 823 current_lag_index_ = current_lag_index_ + lag_index_direction_;
824 // Change direction if needed. 824 // Change direction if needed.
825 if (current_lag_index_ <= 0) { 825 if (current_lag_index_ <= 0) {
826 lag_index_direction_ = 1; 826 lag_index_direction_ = 1;
827 } 827 }
828 if (current_lag_index_ >= kNumLags - 1) { 828 if (current_lag_index_ >= kNumLags - 1) {
829 lag_index_direction_ = -1; 829 lag_index_direction_ = -1;
(...skipping 11 matching lines...) Expand all
841 841
842 // TODO(turajs): This can be moved to BackgroundNoise class. 842 // TODO(turajs): This can be moved to BackgroundNoise class.
843 void Expand::GenerateBackgroundNoise(int16_t* random_vector, 843 void Expand::GenerateBackgroundNoise(int16_t* random_vector,
844 size_t channel, 844 size_t channel,
845 int mute_slope, 845 int mute_slope,
846 bool too_many_expands, 846 bool too_many_expands,
847 size_t num_noise_samples, 847 size_t num_noise_samples,
848 int16_t* buffer) { 848 int16_t* buffer) {
849 static const int kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder; 849 static const int kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder;
850 int16_t scaled_random_vector[kMaxSampleRate / 8000 * 125]; 850 int16_t scaled_random_vector[kMaxSampleRate / 8000 * 125];
851 assert(static_cast<size_t>(kMaxSampleRate / 8000 * 125) >= num_noise_samples); 851 assert(num_noise_samples <= static_cast<size_t>(kMaxSampleRate / 8000 * 125));
kwiberg-webrtc 2015/06/10 11:58:32 DCHECK_LE?
852 int16_t* noise_samples = &buffer[kNoiseLpcOrder]; 852 int16_t* noise_samples = &buffer[kNoiseLpcOrder];
853 if (background_noise_->initialized()) { 853 if (background_noise_->initialized()) {
854 // Use background noise parameters. 854 // Use background noise parameters.
855 memcpy(noise_samples - kNoiseLpcOrder, 855 memcpy(noise_samples - kNoiseLpcOrder,
856 background_noise_->FilterState(channel), 856 background_noise_->FilterState(channel),
857 sizeof(int16_t) * kNoiseLpcOrder); 857 sizeof(int16_t) * kNoiseLpcOrder);
858 858
859 int dc_offset = 0; 859 int dc_offset = 0;
860 if (background_noise_->ScaleShift(channel) > 1) { 860 if (background_noise_->ScaleShift(channel) > 1) {
861 dc_offset = 1 << (background_noise_->ScaleShift(channel) - 1); 861 dc_offset = 1 << (background_noise_->ScaleShift(channel) - 1);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; 938 const size_t kMaxRandSamples = RandomVector::kRandomTableSize;
939 while (samples_generated < length) { 939 while (samples_generated < length) {
940 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); 940 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples);
941 random_vector_->IncreaseSeedIncrement(seed_increment); 941 random_vector_->IncreaseSeedIncrement(seed_increment);
942 random_vector_->Generate(rand_length, &random_vector[samples_generated]); 942 random_vector_->Generate(rand_length, &random_vector[samples_generated]);
943 samples_generated += rand_length; 943 samples_generated += rand_length;
944 } 944 }
945 } 945 }
946 946
947 } // namespace webrtc 947 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698