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

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

Issue 1230503003: Update a ton of audio code to use size_t more correctly and in general reduce (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 4 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 29 matching lines...) Expand all
40 consecutive_expands_(0), 40 consecutive_expands_(0),
41 background_noise_(background_noise), 41 background_noise_(background_noise),
42 statistics_(statistics), 42 statistics_(statistics),
43 overlap_length_(5 * fs / 8000), 43 overlap_length_(5 * fs / 8000),
44 lag_index_direction_(0), 44 lag_index_direction_(0),
45 current_lag_index_(0), 45 current_lag_index_(0),
46 stop_muting_(false), 46 stop_muting_(false),
47 expand_duration_samples_(0), 47 expand_duration_samples_(0),
48 channel_parameters_(new ChannelParameters[num_channels_]) { 48 channel_parameters_(new ChannelParameters[num_channels_]) {
49 assert(fs == 8000 || fs == 16000 || fs == 32000 || fs == 48000); 49 assert(fs == 8000 || fs == 16000 || fs == 32000 || fs == 48000);
50 assert(fs <= kMaxSampleRate); // Should not be possible. 50 assert(fs <= static_cast<int>(kMaxSampleRate)); // Should not be possible.
51 assert(num_channels_ > 0); 51 assert(num_channels_ > 0);
52 memset(expand_lags_, 0, sizeof(expand_lags_)); 52 memset(expand_lags_, 0, sizeof(expand_lags_));
53 Reset(); 53 Reset();
54 } 54 }
55 55
56 Expand::~Expand() = default; 56 Expand::~Expand() = default;
57 57
58 void Expand::Reset() { 58 void Expand::Reset() {
59 first_expand_ = true; 59 first_expand_ = true;
60 consecutive_expands_ = 0; 60 consecutive_expands_ = 0;
61 max_lag_ = 0; 61 max_lag_ = 0;
62 for (size_t ix = 0; ix < num_channels_; ++ix) { 62 for (size_t ix = 0; ix < num_channels_; ++ix) {
63 channel_parameters_[ix].expand_vector0.Clear(); 63 channel_parameters_[ix].expand_vector0.Clear();
64 channel_parameters_[ix].expand_vector1.Clear(); 64 channel_parameters_[ix].expand_vector1.Clear();
65 } 65 }
66 } 66 }
67 67
68 int Expand::Process(AudioMultiVector* output) { 68 int Expand::Process(AudioMultiVector* output) {
69 int16_t random_vector[kMaxSampleRate / 8000 * 120 + 30]; 69 int16_t random_vector[kMaxSampleRate / 8000 * 120 + 30];
70 int16_t scaled_random_vector[kMaxSampleRate / 8000 * 125]; 70 int16_t scaled_random_vector[kMaxSampleRate / 8000 * 125];
71 static const int kTempDataSize = 3600; 71 static const int kTempDataSize = 3600;
72 int16_t temp_data[kTempDataSize]; // TODO(hlundin) Remove this. 72 int16_t temp_data[kTempDataSize]; // TODO(hlundin) Remove this.
73 int16_t* voiced_vector_storage = temp_data; 73 int16_t* voiced_vector_storage = temp_data;
74 int16_t* voiced_vector = &voiced_vector_storage[overlap_length_]; 74 int16_t* voiced_vector = &voiced_vector_storage[overlap_length_];
75 static const int kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder; 75 static const size_t kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder;
76 int16_t unvoiced_array_memory[kNoiseLpcOrder + kMaxSampleRate / 8000 * 125]; 76 int16_t unvoiced_array_memory[kNoiseLpcOrder + kMaxSampleRate / 8000 * 125];
77 int16_t* unvoiced_vector = unvoiced_array_memory + kUnvoicedLpcOrder; 77 int16_t* unvoiced_vector = unvoiced_array_memory + kUnvoicedLpcOrder;
78 int16_t* noise_vector = unvoiced_array_memory + kNoiseLpcOrder; 78 int16_t* noise_vector = unvoiced_array_memory + kNoiseLpcOrder;
79 79
80 int fs_mult = fs_hz_ / 8000; 80 int fs_mult = fs_hz_ / 8000;
81 81
82 if (first_expand_) { 82 if (first_expand_) {
83 // Perform initial setup if this is the first expansion since last reset. 83 // Perform initial setup if this is the first expansion since last reset.
84 AnalyzeSignal(random_vector); 84 AnalyzeSignal(random_vector);
85 first_expand_ = false; 85 first_expand_ = false;
86 expand_duration_samples_ = 0; 86 expand_duration_samples_ = 0;
87 } else { 87 } else {
88 // This is not the first expansion, parameters are already estimated. 88 // This is not the first expansion, parameters are already estimated.
89 // Extract a noise segment. 89 // Extract a noise segment.
90 int16_t rand_length = max_lag_; 90 size_t rand_length = max_lag_;
91 // This only applies to SWB where length could be larger than 256. 91 // This only applies to SWB where length could be larger than 256.
92 assert(rand_length <= kMaxSampleRate / 8000 * 120 + 30); 92 assert(rand_length <= kMaxSampleRate / 8000 * 120 + 30);
93 GenerateRandomVector(2, rand_length, random_vector); 93 GenerateRandomVector(2, rand_length, random_vector);
94 } 94 }
95 95
96 96
97 // Generate signal. 97 // Generate signal.
98 UpdateLagIndex(); 98 UpdateLagIndex();
99 99
100 // Voiced part. 100 // Voiced part.
(...skipping 11 matching lines...) Expand all
112 assert(expansion_vector_position + temp_length <= 112 assert(expansion_vector_position + temp_length <=
113 parameters.expand_vector0.Size()); 113 parameters.expand_vector0.Size());
114 memcpy(voiced_vector_storage, 114 memcpy(voiced_vector_storage,
115 &parameters.expand_vector0[expansion_vector_position], 115 &parameters.expand_vector0[expansion_vector_position],
116 sizeof(int16_t) * temp_length); 116 sizeof(int16_t) * temp_length);
117 } else if (current_lag_index_ == 1) { 117 } else if (current_lag_index_ == 1) {
118 // Mix 3/4 of expand_vector0 with 1/4 of expand_vector1. 118 // Mix 3/4 of expand_vector0 with 1/4 of expand_vector1.
119 WebRtcSpl_ScaleAndAddVectorsWithRound( 119 WebRtcSpl_ScaleAndAddVectorsWithRound(
120 &parameters.expand_vector0[expansion_vector_position], 3, 120 &parameters.expand_vector0[expansion_vector_position], 3,
121 &parameters.expand_vector1[expansion_vector_position], 1, 2, 121 &parameters.expand_vector1[expansion_vector_position], 1, 2,
122 voiced_vector_storage, static_cast<int>(temp_length)); 122 voiced_vector_storage, temp_length);
123 } else if (current_lag_index_ == 2) { 123 } else if (current_lag_index_ == 2) {
124 // Mix 1/2 of expand_vector0 with 1/2 of expand_vector1. 124 // Mix 1/2 of expand_vector0 with 1/2 of expand_vector1.
125 assert(expansion_vector_position + temp_length <= 125 assert(expansion_vector_position + temp_length <=
126 parameters.expand_vector0.Size()); 126 parameters.expand_vector0.Size());
127 assert(expansion_vector_position + temp_length <= 127 assert(expansion_vector_position + temp_length <=
128 parameters.expand_vector1.Size()); 128 parameters.expand_vector1.Size());
129 WebRtcSpl_ScaleAndAddVectorsWithRound( 129 WebRtcSpl_ScaleAndAddVectorsWithRound(
130 &parameters.expand_vector0[expansion_vector_position], 1, 130 &parameters.expand_vector0[expansion_vector_position], 1,
131 &parameters.expand_vector1[expansion_vector_position], 1, 1, 131 &parameters.expand_vector1[expansion_vector_position], 1, 1,
132 voiced_vector_storage, static_cast<int>(temp_length)); 132 voiced_vector_storage, temp_length);
133 } 133 }
134 134
135 // Get tapering window parameters. Values are in Q15. 135 // Get tapering window parameters. Values are in Q15.
136 int16_t muting_window, muting_window_increment; 136 int16_t muting_window, muting_window_increment;
137 int16_t unmuting_window, unmuting_window_increment; 137 int16_t unmuting_window, unmuting_window_increment;
138 if (fs_hz_ == 8000) { 138 if (fs_hz_ == 8000) {
139 muting_window = DspHelper::kMuteFactorStart8kHz; 139 muting_window = DspHelper::kMuteFactorStart8kHz;
140 muting_window_increment = DspHelper::kMuteFactorIncrement8kHz; 140 muting_window_increment = DspHelper::kMuteFactorIncrement8kHz;
141 unmuting_window = DspHelper::kUnmuteFactorStart8kHz; 141 unmuting_window = DspHelper::kUnmuteFactorStart8kHz;
142 unmuting_window_increment = DspHelper::kUnmuteFactorIncrement8kHz; 142 unmuting_window_increment = DspHelper::kUnmuteFactorIncrement8kHz;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // Filter |scaled_random_vector| through |ar_filter_|. 189 // Filter |scaled_random_vector| through |ar_filter_|.
190 memcpy(unvoiced_vector - kUnvoicedLpcOrder, parameters.ar_filter_state, 190 memcpy(unvoiced_vector - kUnvoicedLpcOrder, parameters.ar_filter_state,
191 sizeof(int16_t) * kUnvoicedLpcOrder); 191 sizeof(int16_t) * kUnvoicedLpcOrder);
192 int32_t add_constant = 0; 192 int32_t add_constant = 0;
193 if (parameters.ar_gain_scale > 0) { 193 if (parameters.ar_gain_scale > 0) {
194 add_constant = 1 << (parameters.ar_gain_scale - 1); 194 add_constant = 1 << (parameters.ar_gain_scale - 1);
195 } 195 }
196 WebRtcSpl_AffineTransformVector(scaled_random_vector, random_vector, 196 WebRtcSpl_AffineTransformVector(scaled_random_vector, random_vector,
197 parameters.ar_gain, add_constant, 197 parameters.ar_gain, add_constant,
198 parameters.ar_gain_scale, 198 parameters.ar_gain_scale,
199 static_cast<int>(current_lag)); 199 current_lag);
200 WebRtcSpl_FilterARFastQ12(scaled_random_vector, unvoiced_vector, 200 WebRtcSpl_FilterARFastQ12(scaled_random_vector, unvoiced_vector,
201 parameters.ar_filter, kUnvoicedLpcOrder + 1, 201 parameters.ar_filter, kUnvoicedLpcOrder + 1,
202 static_cast<int>(current_lag)); 202 current_lag);
203 memcpy(parameters.ar_filter_state, 203 memcpy(parameters.ar_filter_state,
204 &(unvoiced_vector[current_lag - kUnvoicedLpcOrder]), 204 &(unvoiced_vector[current_lag - kUnvoicedLpcOrder]),
205 sizeof(int16_t) * kUnvoicedLpcOrder); 205 sizeof(int16_t) * kUnvoicedLpcOrder);
206 206
207 // Combine voiced and unvoiced contributions. 207 // Combine voiced and unvoiced contributions.
208 208
209 // Set a suitable cross-fading slope. 209 // Set a suitable cross-fading slope.
210 // For lag = 210 // For lag =
211 // <= 31 * fs_mult => go from 1 to 0 in about 8 ms; 211 // <= 31 * fs_mult => go from 1 to 0 in about 8 ms;
212 // (>= 31 .. <= 63) * fs_mult => go from 1 to 0 in about 16 ms; 212 // (>= 31 .. <= 63) * fs_mult => go from 1 to 0 in about 16 ms;
213 // >= 64 * fs_mult => go from 1 to 0 in about 32 ms. 213 // >= 64 * fs_mult => go from 1 to 0 in about 32 ms.
214 // temp_shift = getbits(max_lag_) - 5. 214 // temp_shift = getbits(max_lag_) - 5.
215 int temp_shift = (31 - WebRtcSpl_NormW32(max_lag_)) - 5; 215 int temp_shift =
216 (31 - WebRtcSpl_NormW32(rtc::checked_cast<int32_t>(max_lag_))) - 5;
216 int16_t mix_factor_increment = 256 >> temp_shift; 217 int16_t mix_factor_increment = 256 >> temp_shift;
217 if (stop_muting_) { 218 if (stop_muting_) {
218 mix_factor_increment = 0; 219 mix_factor_increment = 0;
219 } 220 }
220 221
221 // Create combined signal by shifting in more and more of unvoiced part. 222 // Create combined signal by shifting in more and more of unvoiced part.
222 temp_shift = 8 - temp_shift; // = getbits(mix_factor_increment). 223 temp_shift = 8 - temp_shift; // = getbits(mix_factor_increment).
223 size_t temp_length = (parameters.current_voice_mix_factor - 224 size_t temp_length = (parameters.current_voice_mix_factor -
224 parameters.voice_mix_factor) >> temp_shift; 225 parameters.voice_mix_factor) >> temp_shift;
225 temp_length = std::min(temp_length, current_lag); 226 temp_length = std::min(temp_length, current_lag);
226 DspHelper::CrossFade(voiced_vector, unvoiced_vector, temp_length, 227 DspHelper::CrossFade(voiced_vector, unvoiced_vector, temp_length,
227 &parameters.current_voice_mix_factor, 228 &parameters.current_voice_mix_factor,
228 mix_factor_increment, temp_data); 229 mix_factor_increment, temp_data);
229 230
230 // End of cross-fading period was reached before end of expanded signal 231 // End of cross-fading period was reached before end of expanded signal
231 // path. Mix the rest with a fixed mixing factor. 232 // path. Mix the rest with a fixed mixing factor.
232 if (temp_length < current_lag) { 233 if (temp_length < current_lag) {
233 if (mix_factor_increment != 0) { 234 if (mix_factor_increment != 0) {
234 parameters.current_voice_mix_factor = parameters.voice_mix_factor; 235 parameters.current_voice_mix_factor = parameters.voice_mix_factor;
235 } 236 }
236 int16_t temp_scale = 16384 - parameters.current_voice_mix_factor; 237 int16_t temp_scale = 16384 - parameters.current_voice_mix_factor;
237 WebRtcSpl_ScaleAndAddVectorsWithRound( 238 WebRtcSpl_ScaleAndAddVectorsWithRound(
238 voiced_vector + temp_length, parameters.current_voice_mix_factor, 239 voiced_vector + temp_length, parameters.current_voice_mix_factor,
239 unvoiced_vector + temp_length, temp_scale, 14, 240 unvoiced_vector + temp_length, temp_scale, 14,
240 temp_data + temp_length, static_cast<int>(current_lag - temp_length)); 241 temp_data + temp_length, current_lag - temp_length);
241 } 242 }
242 243
243 // Select muting slope depending on how many consecutive expands we have 244 // Select muting slope depending on how many consecutive expands we have
244 // done. 245 // done.
245 if (consecutive_expands_ == 3) { 246 if (consecutive_expands_ == 3) {
246 // Let the mute factor decrease from 1.0 to 0.95 in 6.25 ms. 247 // Let the mute factor decrease from 1.0 to 0.95 in 6.25 ms.
247 // mute_slope = 0.0010 / fs_mult in Q20. 248 // mute_slope = 0.0010 / fs_mult in Q20.
248 parameters.mute_slope = std::max(parameters.mute_slope, 1049 / fs_mult); 249 parameters.mute_slope = std::max(parameters.mute_slope, 1049 / fs_mult);
249 } 250 }
250 if (consecutive_expands_ == 7) { 251 if (consecutive_expands_ == 7) {
251 // Let the mute factor decrease from 1.0 to 0.90 in 6.25 ms. 252 // Let the mute factor decrease from 1.0 to 0.90 in 6.25 ms.
252 // mute_slope = 0.0020 / fs_mult in Q20. 253 // mute_slope = 0.0020 / fs_mult in Q20.
253 parameters.mute_slope = std::max(parameters.mute_slope, 2097 / fs_mult); 254 parameters.mute_slope = std::max(parameters.mute_slope, 2097 / fs_mult);
254 } 255 }
255 256
256 // Mute segment according to slope value. 257 // Mute segment according to slope value.
257 if ((consecutive_expands_ != 0) || !parameters.onset) { 258 if ((consecutive_expands_ != 0) || !parameters.onset) {
258 // Mute to the previous level, then continue with the muting. 259 // Mute to the previous level, then continue with the muting.
259 WebRtcSpl_AffineTransformVector(temp_data, temp_data, 260 WebRtcSpl_AffineTransformVector(temp_data, temp_data,
260 parameters.mute_factor, 8192, 261 parameters.mute_factor, 8192,
261 14, static_cast<int>(current_lag)); 262 14, current_lag);
262 263
263 if (!stop_muting_) { 264 if (!stop_muting_) {
264 DspHelper::MuteSignal(temp_data, parameters.mute_slope, current_lag); 265 DspHelper::MuteSignal(temp_data, parameters.mute_slope, current_lag);
265 266
266 // Shift by 6 to go from Q20 to Q14. 267 // Shift by 6 to go from Q20 to Q14.
267 // TODO(hlundin): Adding 8192 before shifting 6 steps seems wrong. 268 // TODO(hlundin): Adding 8192 before shifting 6 steps seems wrong.
268 // Legacy. 269 // Legacy.
269 int16_t gain = static_cast<int16_t>(16384 - 270 int16_t gain = static_cast<int16_t>(16384 -
270 (((current_lag * parameters.mute_slope) + 8192) >> 6)); 271 (((current_lag * parameters.mute_slope) + 8192) >> 6));
271 gain = ((gain * parameters.mute_factor) + 8192) >> 14; 272 gain = ((gain * parameters.mute_factor) + 8192) >> 14;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 345 }
345 346
346 bool Expand::TooManyExpands() { 347 bool Expand::TooManyExpands() {
347 return consecutive_expands_ >= kMaxConsecutiveExpands; 348 return consecutive_expands_ >= kMaxConsecutiveExpands;
348 } 349 }
349 350
350 void Expand::AnalyzeSignal(int16_t* random_vector) { 351 void Expand::AnalyzeSignal(int16_t* random_vector) {
351 int32_t auto_correlation[kUnvoicedLpcOrder + 1]; 352 int32_t auto_correlation[kUnvoicedLpcOrder + 1];
352 int16_t reflection_coeff[kUnvoicedLpcOrder]; 353 int16_t reflection_coeff[kUnvoicedLpcOrder];
353 int16_t correlation_vector[kMaxSampleRate / 8000 * 102]; 354 int16_t correlation_vector[kMaxSampleRate / 8000 * 102];
354 int best_correlation_index[kNumCorrelationCandidates]; 355 size_t best_correlation_index[kNumCorrelationCandidates];
355 int16_t best_correlation[kNumCorrelationCandidates]; 356 int16_t best_correlation[kNumCorrelationCandidates];
356 int16_t best_distortion_index[kNumCorrelationCandidates]; 357 size_t best_distortion_index[kNumCorrelationCandidates];
357 int16_t best_distortion[kNumCorrelationCandidates]; 358 int16_t best_distortion[kNumCorrelationCandidates];
358 int32_t correlation_vector2[(99 * kMaxSampleRate / 8000) + 1]; 359 int32_t correlation_vector2[(99 * kMaxSampleRate / 8000) + 1];
359 int32_t best_distortion_w32[kNumCorrelationCandidates]; 360 int32_t best_distortion_w32[kNumCorrelationCandidates];
360 static const int kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder; 361 static const size_t kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder;
361 int16_t unvoiced_array_memory[kNoiseLpcOrder + kMaxSampleRate / 8000 * 125]; 362 int16_t unvoiced_array_memory[kNoiseLpcOrder + kMaxSampleRate / 8000 * 125];
362 int16_t* unvoiced_vector = unvoiced_array_memory + kUnvoicedLpcOrder; 363 int16_t* unvoiced_vector = unvoiced_array_memory + kUnvoicedLpcOrder;
363 364
364 int fs_mult = fs_hz_ / 8000; 365 int fs_mult = fs_hz_ / 8000;
365 366
366 // Pre-calculate common multiplications with fs_mult. 367 // Pre-calculate common multiplications with fs_mult.
367 int fs_mult_4 = fs_mult * 4; 368 size_t fs_mult_4 = static_cast<size_t>(fs_mult * 4);
368 int fs_mult_20 = fs_mult * 20; 369 size_t fs_mult_20 = static_cast<size_t>(fs_mult * 20);
369 int fs_mult_120 = fs_mult * 120; 370 size_t fs_mult_120 = static_cast<size_t>(fs_mult * 120);
370 int fs_mult_dist_len = fs_mult * kDistortionLength; 371 size_t fs_mult_dist_len = fs_mult * kDistortionLength;
371 int fs_mult_lpc_analysis_len = fs_mult * kLpcAnalysisLength; 372 size_t fs_mult_lpc_analysis_len = fs_mult * kLpcAnalysisLength;
372 373
373 const size_t signal_length = 256 * fs_mult; 374 const size_t signal_length = static_cast<size_t>(256 * fs_mult);
374 const int16_t* audio_history = 375 const int16_t* audio_history =
375 &(*sync_buffer_)[0][sync_buffer_->Size() - signal_length]; 376 &(*sync_buffer_)[0][sync_buffer_->Size() - signal_length];
376 377
377 // Initialize. 378 // Initialize.
378 InitializeForAnExpandPeriod(); 379 InitializeForAnExpandPeriod();
379 380
380 // Calculate correlation in downsampled domain (4 kHz sample rate). 381 // Calculate correlation in downsampled domain (4 kHz sample rate).
381 int correlation_scale; 382 int correlation_scale;
382 int correlation_length = 51; // TODO(hlundin): Legacy bit-exactness. 383 size_t correlation_length = 51; // TODO(hlundin): Legacy bit-exactness.
383 // If it is decided to break bit-exactness |correlation_length| should be 384 // If it is decided to break bit-exactness |correlation_length| should be
384 // initialized to the return value of Correlation(). 385 // initialized to the return value of Correlation().
385 Correlation(audio_history, signal_length, correlation_vector, 386 Correlation(audio_history, signal_length, correlation_vector,
386 &correlation_scale); 387 &correlation_scale);
387 388
388 // Find peaks in correlation vector. 389 // Find peaks in correlation vector.
389 DspHelper::PeakDetection(correlation_vector, correlation_length, 390 DspHelper::PeakDetection(correlation_vector, correlation_length,
390 kNumCorrelationCandidates, fs_mult, 391 kNumCorrelationCandidates, fs_mult,
391 best_correlation_index, best_correlation); 392 best_correlation_index, best_correlation);
392 393
393 // Adjust peak locations; cross-correlation lags start at 2.5 ms 394 // Adjust peak locations; cross-correlation lags start at 2.5 ms
394 // (20 * fs_mult samples). 395 // (20 * fs_mult samples).
395 best_correlation_index[0] += fs_mult_20; 396 best_correlation_index[0] += fs_mult_20;
396 best_correlation_index[1] += fs_mult_20; 397 best_correlation_index[1] += fs_mult_20;
397 best_correlation_index[2] += fs_mult_20; 398 best_correlation_index[2] += fs_mult_20;
398 399
399 // Calculate distortion around the |kNumCorrelationCandidates| best lags. 400 // Calculate distortion around the |kNumCorrelationCandidates| best lags.
400 int distortion_scale = 0; 401 int distortion_scale = 0;
401 for (int i = 0; i < kNumCorrelationCandidates; i++) { 402 for (size_t i = 0; i < kNumCorrelationCandidates; i++) {
402 int16_t min_index = std::max(fs_mult_20, 403 size_t min_index = std::max(fs_mult_20,
403 best_correlation_index[i] - fs_mult_4); 404 best_correlation_index[i] - fs_mult_4);
404 int16_t max_index = std::min(fs_mult_120 - 1, 405 size_t max_index = std::min(fs_mult_120 - 1,
405 best_correlation_index[i] + fs_mult_4); 406 best_correlation_index[i] + fs_mult_4);
406 best_distortion_index[i] = DspHelper::MinDistortion( 407 best_distortion_index[i] = DspHelper::MinDistortion(
407 &(audio_history[signal_length - fs_mult_dist_len]), min_index, 408 &(audio_history[signal_length - fs_mult_dist_len]), min_index,
408 max_index, fs_mult_dist_len, &best_distortion_w32[i]); 409 max_index, fs_mult_dist_len, &best_distortion_w32[i]);
409 distortion_scale = std::max(16 - WebRtcSpl_NormW32(best_distortion_w32[i]), 410 distortion_scale = std::max(16 - WebRtcSpl_NormW32(best_distortion_w32[i]),
410 distortion_scale); 411 distortion_scale);
411 } 412 }
412 // Shift the distortion values to fit in 16 bits. 413 // Shift the distortion values to fit in 16 bits.
413 WebRtcSpl_VectorBitShiftW32ToW16(best_distortion, kNumCorrelationCandidates, 414 WebRtcSpl_VectorBitShiftW32ToW16(best_distortion, kNumCorrelationCandidates,
414 best_distortion_w32, distortion_scale); 415 best_distortion_w32, distortion_scale);
415 416
416 // Find the maximizing index |i| of the cost function 417 // Find the maximizing index |i| of the cost function
417 // f[i] = best_correlation[i] / best_distortion[i]. 418 // f[i] = best_correlation[i] / best_distortion[i].
418 int32_t best_ratio = std::numeric_limits<int32_t>::min(); 419 int32_t best_ratio = std::numeric_limits<int32_t>::min();
419 int best_index = std::numeric_limits<int>::max(); 420 size_t best_index = std::numeric_limits<size_t>::max();
420 for (int i = 0; i < kNumCorrelationCandidates; ++i) { 421 for (size_t i = 0; i < kNumCorrelationCandidates; ++i) {
421 int32_t ratio; 422 int32_t ratio;
422 if (best_distortion[i] > 0) { 423 if (best_distortion[i] > 0) {
423 ratio = (best_correlation[i] << 16) / best_distortion[i]; 424 ratio = (best_correlation[i] << 16) / best_distortion[i];
424 } else if (best_correlation[i] == 0) { 425 } else if (best_correlation[i] == 0) {
425 ratio = 0; // No correlation set result to zero. 426 ratio = 0; // No correlation set result to zero.
426 } else { 427 } else {
427 ratio = std::numeric_limits<int32_t>::max(); // Denominator is zero. 428 ratio = std::numeric_limits<int32_t>::max(); // Denominator is zero.
428 } 429 }
429 if (ratio > best_ratio) { 430 if (ratio > best_ratio) {
430 best_index = i; 431 best_index = i;
431 best_ratio = ratio; 432 best_ratio = ratio;
432 } 433 }
433 } 434 }
434 435
435 int distortion_lag = best_distortion_index[best_index]; 436 size_t distortion_lag = best_distortion_index[best_index];
436 int correlation_lag = best_correlation_index[best_index]; 437 size_t correlation_lag = best_correlation_index[best_index];
437 max_lag_ = std::max(distortion_lag, correlation_lag); 438 max_lag_ = std::max(distortion_lag, correlation_lag);
438 439
439 // Calculate the exact best correlation in the range between 440 // Calculate the exact best correlation in the range between
440 // |correlation_lag| and |distortion_lag|. 441 // |correlation_lag| and |distortion_lag|.
441 correlation_length = 442 correlation_length =
442 std::max(std::min(distortion_lag + 10, fs_mult_120), 60 * fs_mult); 443 std::max(std::min(distortion_lag + 10, fs_mult_120),
444 static_cast<size_t>(60 * fs_mult));
443 445
444 int start_index = std::min(distortion_lag, correlation_lag); 446 size_t start_index = std::min(distortion_lag, correlation_lag);
445 int correlation_lags = 447 size_t correlation_lags = static_cast<size_t>(
446 WEBRTC_SPL_ABS_W16((distortion_lag-correlation_lag)) + 1; 448 WEBRTC_SPL_ABS_W16((distortion_lag-correlation_lag)) + 1);
447 assert(correlation_lags <= 99 * fs_mult + 1); // Cannot be larger. 449 assert(correlation_lags <= static_cast<size_t>(99 * fs_mult + 1));
448 450
449 for (size_t channel_ix = 0; channel_ix < num_channels_; ++channel_ix) { 451 for (size_t channel_ix = 0; channel_ix < num_channels_; ++channel_ix) {
450 ChannelParameters& parameters = channel_parameters_[channel_ix]; 452 ChannelParameters& parameters = channel_parameters_[channel_ix];
451 // Calculate suitable scaling. 453 // Calculate suitable scaling.
452 int16_t signal_max = WebRtcSpl_MaxAbsValueW16( 454 int16_t signal_max = WebRtcSpl_MaxAbsValueW16(
453 &audio_history[signal_length - correlation_length - start_index 455 &audio_history[signal_length - correlation_length - start_index
454 - correlation_lags], 456 - correlation_lags],
455 correlation_length + start_index + correlation_lags - 1); 457 correlation_length + start_index + correlation_lags - 1);
456 correlation_scale = (31 - WebRtcSpl_NormW32(signal_max * signal_max)) + 458 correlation_scale = (31 - WebRtcSpl_NormW32(signal_max * signal_max)) +
457 (31 - WebRtcSpl_NormW32(correlation_length)) - 31; 459 (31 - WebRtcSpl_NormW32(static_cast<int32_t>(correlation_length))) - 31;
458 correlation_scale = std::max(0, correlation_scale); 460 correlation_scale = std::max(0, correlation_scale);
459 461
460 // Calculate the correlation, store in |correlation_vector2|. 462 // Calculate the correlation, store in |correlation_vector2|.
461 WebRtcSpl_CrossCorrelation( 463 WebRtcSpl_CrossCorrelation(
462 correlation_vector2, 464 correlation_vector2,
463 &(audio_history[signal_length - correlation_length]), 465 &(audio_history[signal_length - correlation_length]),
464 &(audio_history[signal_length - correlation_length - start_index]), 466 &(audio_history[signal_length - correlation_length - start_index]),
465 correlation_length, correlation_lags, correlation_scale, -1); 467 correlation_length, correlation_lags, correlation_scale, -1);
466 468
467 // Find maximizing index. 469 // Find maximizing index.
468 best_index = WebRtcSpl_MaxIndexW32(correlation_vector2, correlation_lags); 470 best_index = static_cast<size_t>(
471 WebRtcSpl_MaxIndexW32(correlation_vector2, correlation_lags));
469 int32_t max_correlation = correlation_vector2[best_index]; 472 int32_t max_correlation = correlation_vector2[best_index];
470 // Compensate index with start offset. 473 // Compensate index with start offset.
471 best_index = best_index + start_index; 474 best_index = best_index + start_index;
472 475
473 // Calculate energies. 476 // Calculate energies.
474 int32_t energy1 = WebRtcSpl_DotProductWithScale( 477 int32_t energy1 = WebRtcSpl_DotProductWithScale(
475 &(audio_history[signal_length - correlation_length]), 478 &(audio_history[signal_length - correlation_length]),
476 &(audio_history[signal_length - correlation_length]), 479 &(audio_history[signal_length - correlation_length]),
477 correlation_length, correlation_scale); 480 correlation_length, correlation_scale);
478 int32_t energy2 = WebRtcSpl_DotProductWithScale( 481 int32_t energy2 = WebRtcSpl_DotProductWithScale(
(...skipping 22 matching lines...) Expand all
501 corr_coefficient = WebRtcSpl_DivW32W16(max_correlation, 504 corr_coefficient = WebRtcSpl_DivW32W16(max_correlation,
502 sqrt_energy_product); 505 sqrt_energy_product);
503 // Cap at 1.0 in Q14. 506 // Cap at 1.0 in Q14.
504 corr_coefficient = std::min(16384, corr_coefficient); 507 corr_coefficient = std::min(16384, corr_coefficient);
505 } else { 508 } else {
506 corr_coefficient = 0; 509 corr_coefficient = 0;
507 } 510 }
508 511
509 // Extract the two vectors expand_vector0 and expand_vector1 from 512 // Extract the two vectors expand_vector0 and expand_vector1 from
510 // |audio_history|. 513 // |audio_history|.
511 int16_t expansion_length = static_cast<int16_t>(max_lag_ + overlap_length_); 514 size_t expansion_length = max_lag_ + overlap_length_;
512 const int16_t* vector1 = &(audio_history[signal_length - expansion_length]); 515 const int16_t* vector1 = &(audio_history[signal_length - expansion_length]);
513 const int16_t* vector2 = vector1 - distortion_lag; 516 const int16_t* vector2 = vector1 - distortion_lag;
514 // Normalize the second vector to the same energy as the first. 517 // Normalize the second vector to the same energy as the first.
515 energy1 = WebRtcSpl_DotProductWithScale(vector1, vector1, expansion_length, 518 energy1 = WebRtcSpl_DotProductWithScale(vector1, vector1, expansion_length,
516 correlation_scale); 519 correlation_scale);
517 energy2 = WebRtcSpl_DotProductWithScale(vector2, vector2, expansion_length, 520 energy2 = WebRtcSpl_DotProductWithScale(vector2, vector2, expansion_length,
518 correlation_scale); 521 correlation_scale);
519 // Confirm that amplitude ratio sqrt(energy1 / energy2) is within 0.5 - 2.0, 522 // Confirm that amplitude ratio sqrt(energy1 / energy2) is within 0.5 - 2.0,
520 // i.e., energy1 / energy1 is within 0.25 - 4. 523 // i.e., energy1 / energy1 is within 0.25 - 4.
521 int16_t amplitude_ratio; 524 int16_t amplitude_ratio;
522 if ((energy1 / 4 < energy2) && (energy1 > energy2 / 4)) { 525 if ((energy1 / 4 < energy2) && (energy1 > energy2 / 4)) {
523 // Energy constraint fulfilled. Use both vectors and scale them 526 // Energy constraint fulfilled. Use both vectors and scale them
524 // accordingly. 527 // accordingly.
525 int32_t scaled_energy2 = std::max(16 - WebRtcSpl_NormW32(energy2), 0); 528 int32_t scaled_energy2 = std::max(16 - WebRtcSpl_NormW32(energy2), 0);
526 int32_t scaled_energy1 = scaled_energy2 - 13; 529 int32_t scaled_energy1 = scaled_energy2 - 13;
527 // Calculate scaled_energy1 / scaled_energy2 in Q13. 530 // Calculate scaled_energy1 / scaled_energy2 in Q13.
528 int32_t energy_ratio = WebRtcSpl_DivW32W16( 531 int32_t energy_ratio = WebRtcSpl_DivW32W16(
529 WEBRTC_SPL_SHIFT_W32(energy1, -scaled_energy1), 532 WEBRTC_SPL_SHIFT_W32(energy1, -scaled_energy1),
530 energy2 >> scaled_energy2); 533 static_cast<int16_t>(energy2 >> scaled_energy2));
531 // Calculate sqrt ratio in Q13 (sqrt of en1/en2 in Q26). 534 // Calculate sqrt ratio in Q13 (sqrt of en1/en2 in Q26).
532 amplitude_ratio = WebRtcSpl_SqrtFloor(energy_ratio << 13); 535 amplitude_ratio =
536 static_cast<int16_t>(WebRtcSpl_SqrtFloor(energy_ratio << 13));
533 // Copy the two vectors and give them the same energy. 537 // Copy the two vectors and give them the same energy.
534 parameters.expand_vector0.Clear(); 538 parameters.expand_vector0.Clear();
535 parameters.expand_vector0.PushBack(vector1, expansion_length); 539 parameters.expand_vector0.PushBack(vector1, expansion_length);
536 parameters.expand_vector1.Clear(); 540 parameters.expand_vector1.Clear();
537 if (parameters.expand_vector1.Size() < 541 if (parameters.expand_vector1.Size() < expansion_length) {
538 static_cast<size_t>(expansion_length)) {
539 parameters.expand_vector1.Extend( 542 parameters.expand_vector1.Extend(
540 expansion_length - parameters.expand_vector1.Size()); 543 expansion_length - parameters.expand_vector1.Size());
541 } 544 }
542 WebRtcSpl_AffineTransformVector(&parameters.expand_vector1[0], 545 WebRtcSpl_AffineTransformVector(&parameters.expand_vector1[0],
543 const_cast<int16_t*>(vector2), 546 const_cast<int16_t*>(vector2),
544 amplitude_ratio, 547 amplitude_ratio,
545 4096, 548 4096,
546 13, 549 13,
547 expansion_length); 550 expansion_length);
548 } else { 551 } else {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 if (stability != 1) { 622 if (stability != 1) {
620 // Set first coefficient to 4096 (1.0 in Q12). 623 // Set first coefficient to 4096 (1.0 in Q12).
621 parameters.ar_filter[0] = 4096; 624 parameters.ar_filter[0] = 4096;
622 // Set remaining |kUnvoicedLpcOrder| coefficients to zero. 625 // Set remaining |kUnvoicedLpcOrder| coefficients to zero.
623 WebRtcSpl_MemSetW16(parameters.ar_filter + 1, 0, kUnvoicedLpcOrder); 626 WebRtcSpl_MemSetW16(parameters.ar_filter + 1, 0, kUnvoicedLpcOrder);
624 } 627 }
625 } 628 }
626 629
627 if (channel_ix == 0) { 630 if (channel_ix == 0) {
628 // Extract a noise segment. 631 // Extract a noise segment.
629 int16_t noise_length; 632 size_t noise_length;
630 if (distortion_lag < 40) { 633 if (distortion_lag < 40) {
631 noise_length = 2 * distortion_lag + 30; 634 noise_length = 2 * distortion_lag + 30;
632 } else { 635 } else {
633 noise_length = distortion_lag + 30; 636 noise_length = distortion_lag + 30;
634 } 637 }
635 if (noise_length <= RandomVector::kRandomTableSize) { 638 if (noise_length <= RandomVector::kRandomTableSize) {
636 memcpy(random_vector, RandomVector::kRandomTable, 639 memcpy(random_vector, RandomVector::kRandomTable,
637 sizeof(int16_t) * noise_length); 640 sizeof(int16_t) * noise_length);
638 } else { 641 } else {
639 // Only applies to SWB where length could be larger than 642 // Only applies to SWB where length could be larger than
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 memset(ar_filter, 0, sizeof(ar_filter)); 764 memset(ar_filter, 0, sizeof(ar_filter));
762 memset(ar_filter_state, 0, sizeof(ar_filter_state)); 765 memset(ar_filter_state, 0, sizeof(ar_filter_state));
763 } 766 }
764 767
765 void Expand::Correlation(const int16_t* input, 768 void Expand::Correlation(const int16_t* input,
766 size_t input_length, 769 size_t input_length,
767 int16_t* output, 770 int16_t* output,
768 int* output_scale) const { 771 int* output_scale) const {
769 // Set parameters depending on sample rate. 772 // Set parameters depending on sample rate.
770 const int16_t* filter_coefficients; 773 const int16_t* filter_coefficients;
771 int16_t num_coefficients; 774 size_t num_coefficients;
772 int16_t downsampling_factor; 775 int16_t downsampling_factor;
773 if (fs_hz_ == 8000) { 776 if (fs_hz_ == 8000) {
774 num_coefficients = 3; 777 num_coefficients = 3;
775 downsampling_factor = 2; 778 downsampling_factor = 2;
776 filter_coefficients = DspHelper::kDownsample8kHzTbl; 779 filter_coefficients = DspHelper::kDownsample8kHzTbl;
777 } else if (fs_hz_ == 16000) { 780 } else if (fs_hz_ == 16000) {
778 num_coefficients = 5; 781 num_coefficients = 5;
779 downsampling_factor = 4; 782 downsampling_factor = 4;
780 filter_coefficients = DspHelper::kDownsample16kHzTbl; 783 filter_coefficients = DspHelper::kDownsample16kHzTbl;
781 } else if (fs_hz_ == 32000) { 784 } else if (fs_hz_ == 32000) {
782 num_coefficients = 7; 785 num_coefficients = 7;
783 downsampling_factor = 8; 786 downsampling_factor = 8;
784 filter_coefficients = DspHelper::kDownsample32kHzTbl; 787 filter_coefficients = DspHelper::kDownsample32kHzTbl;
785 } else { // fs_hz_ == 48000. 788 } else { // fs_hz_ == 48000.
786 num_coefficients = 7; 789 num_coefficients = 7;
787 downsampling_factor = 12; 790 downsampling_factor = 12;
788 filter_coefficients = DspHelper::kDownsample48kHzTbl; 791 filter_coefficients = DspHelper::kDownsample48kHzTbl;
789 } 792 }
790 793
791 // Correlate from lag 10 to lag 60 in downsampled domain. 794 // Correlate from lag 10 to lag 60 in downsampled domain.
792 // (Corresponds to 20-120 for narrow-band, 40-240 for wide-band, and so on.) 795 // (Corresponds to 20-120 for narrow-band, 40-240 for wide-band, and so on.)
793 static const int kCorrelationStartLag = 10; 796 static const size_t kCorrelationStartLag = 10;
794 static const int kNumCorrelationLags = 54; 797 static const size_t kNumCorrelationLags = 54;
795 static const int kCorrelationLength = 60; 798 static const size_t kCorrelationLength = 60;
796 // Downsample to 4 kHz sample rate. 799 // Downsample to 4 kHz sample rate.
797 static const int kDownsampledLength = kCorrelationStartLag 800 static const size_t kDownsampledLength = kCorrelationStartLag
798 + kNumCorrelationLags + kCorrelationLength; 801 + kNumCorrelationLags + kCorrelationLength;
799 int16_t downsampled_input[kDownsampledLength]; 802 int16_t downsampled_input[kDownsampledLength];
800 static const int kFilterDelay = 0; 803 static const size_t kFilterDelay = 0;
801 WebRtcSpl_DownsampleFast( 804 WebRtcSpl_DownsampleFast(
802 input + input_length - kDownsampledLength * downsampling_factor, 805 input + input_length - kDownsampledLength * downsampling_factor,
803 kDownsampledLength * downsampling_factor, downsampled_input, 806 kDownsampledLength * downsampling_factor, downsampled_input,
804 kDownsampledLength, filter_coefficients, num_coefficients, 807 kDownsampledLength, filter_coefficients, num_coefficients,
805 downsampling_factor, kFilterDelay); 808 downsampling_factor, kFilterDelay);
806 809
807 // Normalize |downsampled_input| to using all 16 bits. 810 // Normalize |downsampled_input| to using all 16 bits.
808 int16_t max_value = WebRtcSpl_MaxAbsValueW16(downsampled_input, 811 int16_t max_value = WebRtcSpl_MaxAbsValueW16(downsampled_input,
809 kDownsampledLength); 812 kDownsampledLength);
810 int16_t norm_shift = 16 - WebRtcSpl_NormW32(max_value); 813 int16_t norm_shift = 16 - WebRtcSpl_NormW32(max_value);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 fs, num_channels); 855 fs, num_channels);
853 } 856 }
854 857
855 // TODO(turajs): This can be moved to BackgroundNoise class. 858 // TODO(turajs): This can be moved to BackgroundNoise class.
856 void Expand::GenerateBackgroundNoise(int16_t* random_vector, 859 void Expand::GenerateBackgroundNoise(int16_t* random_vector,
857 size_t channel, 860 size_t channel,
858 int mute_slope, 861 int mute_slope,
859 bool too_many_expands, 862 bool too_many_expands,
860 size_t num_noise_samples, 863 size_t num_noise_samples,
861 int16_t* buffer) { 864 int16_t* buffer) {
862 static const int kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder; 865 static const size_t kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder;
863 int16_t scaled_random_vector[kMaxSampleRate / 8000 * 125]; 866 int16_t scaled_random_vector[kMaxSampleRate / 8000 * 125];
864 assert(num_noise_samples <= static_cast<size_t>(kMaxSampleRate / 8000 * 125)); 867 assert(num_noise_samples <= (kMaxSampleRate / 8000 * 125));
865 int16_t* noise_samples = &buffer[kNoiseLpcOrder]; 868 int16_t* noise_samples = &buffer[kNoiseLpcOrder];
866 if (background_noise_->initialized()) { 869 if (background_noise_->initialized()) {
867 // Use background noise parameters. 870 // Use background noise parameters.
868 memcpy(noise_samples - kNoiseLpcOrder, 871 memcpy(noise_samples - kNoiseLpcOrder,
869 background_noise_->FilterState(channel), 872 background_noise_->FilterState(channel),
870 sizeof(int16_t) * kNoiseLpcOrder); 873 sizeof(int16_t) * kNoiseLpcOrder);
871 874
872 int dc_offset = 0; 875 int dc_offset = 0;
873 if (background_noise_->ScaleShift(channel) > 1) { 876 if (background_noise_->ScaleShift(channel) > 1) {
874 dc_offset = 1 << (background_noise_->ScaleShift(channel) - 1); 877 dc_offset = 1 << (background_noise_->ScaleShift(channel) - 1);
875 } 878 }
876 879
877 // Scale random vector to correct energy level. 880 // Scale random vector to correct energy level.
878 WebRtcSpl_AffineTransformVector( 881 WebRtcSpl_AffineTransformVector(
879 scaled_random_vector, random_vector, 882 scaled_random_vector, random_vector,
880 background_noise_->Scale(channel), dc_offset, 883 background_noise_->Scale(channel), dc_offset,
881 background_noise_->ScaleShift(channel), 884 background_noise_->ScaleShift(channel),
882 static_cast<int>(num_noise_samples)); 885 num_noise_samples);
883 886
884 WebRtcSpl_FilterARFastQ12(scaled_random_vector, noise_samples, 887 WebRtcSpl_FilterARFastQ12(scaled_random_vector, noise_samples,
885 background_noise_->Filter(channel), 888 background_noise_->Filter(channel),
886 kNoiseLpcOrder + 1, 889 kNoiseLpcOrder + 1,
887 static_cast<int>(num_noise_samples)); 890 num_noise_samples);
888 891
889 background_noise_->SetFilterState( 892 background_noise_->SetFilterState(
890 channel, 893 channel,
891 &(noise_samples[num_noise_samples - kNoiseLpcOrder]), 894 &(noise_samples[num_noise_samples - kNoiseLpcOrder]),
892 kNoiseLpcOrder); 895 kNoiseLpcOrder);
893 896
894 // Unmute the background noise. 897 // Unmute the background noise.
895 int16_t bgn_mute_factor = background_noise_->MuteFactor(channel); 898 int16_t bgn_mute_factor = background_noise_->MuteFactor(channel);
896 NetEq::BackgroundNoiseMode bgn_mode = background_noise_->mode(); 899 NetEq::BackgroundNoiseMode bgn_mode = background_noise_->mode();
897 if (bgn_mode == NetEq::kBgnFade && too_many_expands && 900 if (bgn_mode == NetEq::kBgnFade && too_many_expands &&
(...skipping 26 matching lines...) Expand all
924 static_cast<int>(num_noise_samples), 927 static_cast<int>(num_noise_samples),
925 &bgn_mute_factor, 928 &bgn_mute_factor,
926 mute_slope, 929 mute_slope,
927 noise_samples); 930 noise_samples);
928 } else { 931 } else {
929 // kBgnOn and stop muting, or 932 // kBgnOn and stop muting, or
930 // kBgnOff (mute factor is always 0), or 933 // kBgnOff (mute factor is always 0), or
931 // kBgnFade has reached 0. 934 // kBgnFade has reached 0.
932 WebRtcSpl_AffineTransformVector(noise_samples, noise_samples, 935 WebRtcSpl_AffineTransformVector(noise_samples, noise_samples,
933 bgn_mute_factor, 8192, 14, 936 bgn_mute_factor, 8192, 14,
934 static_cast<int>(num_noise_samples)); 937 num_noise_samples);
935 } 938 }
936 } 939 }
937 // Update mute_factor in BackgroundNoise class. 940 // Update mute_factor in BackgroundNoise class.
938 background_noise_->SetMuteFactor(channel, bgn_mute_factor); 941 background_noise_->SetMuteFactor(channel, bgn_mute_factor);
939 } else { 942 } else {
940 // BGN parameters have not been initialized; use zero noise. 943 // BGN parameters have not been initialized; use zero noise.
941 memset(noise_samples, 0, sizeof(int16_t) * num_noise_samples); 944 memset(noise_samples, 0, sizeof(int16_t) * num_noise_samples);
942 } 945 }
943 } 946 }
944 947
945 void Expand::GenerateRandomVector(int16_t seed_increment, 948 void Expand::GenerateRandomVector(int16_t seed_increment,
946 size_t length, 949 size_t length,
947 int16_t* random_vector) { 950 int16_t* random_vector) {
948 // TODO(turajs): According to hlundin The loop should not be needed. Should be 951 // TODO(turajs): According to hlundin The loop should not be needed. Should be
949 // just as good to generate all of the vector in one call. 952 // just as good to generate all of the vector in one call.
950 size_t samples_generated = 0; 953 size_t samples_generated = 0;
951 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; 954 const size_t kMaxRandSamples = RandomVector::kRandomTableSize;
952 while (samples_generated < length) { 955 while (samples_generated < length) {
953 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); 956 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples);
954 random_vector_->IncreaseSeedIncrement(seed_increment); 957 random_vector_->IncreaseSeedIncrement(seed_increment);
955 random_vector_->Generate(rand_length, &random_vector[samples_generated]); 958 random_vector_->Generate(rand_length, &random_vector[samples_generated]);
956 samples_generated += rand_length; 959 samples_generated += rand_length;
957 } 960 }
958 } 961 }
959 962
960 } // namespace webrtc 963 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/expand.h ('k') | webrtc/modules/audio_coding/neteq/interface/neteq.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698