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

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

Issue 1948483002: Using ring buffer for AudioVector in NetEq. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // Copy lag+overlap data. 105 // Copy lag+overlap data.
106 size_t expansion_vector_position = expansion_vector_length - current_lag - 106 size_t expansion_vector_position = expansion_vector_length - current_lag -
107 overlap_length_; 107 overlap_length_;
108 size_t temp_length = current_lag + overlap_length_; 108 size_t temp_length = current_lag + overlap_length_;
109 for (size_t channel_ix = 0; channel_ix < num_channels_; ++channel_ix) { 109 for (size_t channel_ix = 0; channel_ix < num_channels_; ++channel_ix) {
110 ChannelParameters& parameters = channel_parameters_[channel_ix]; 110 ChannelParameters& parameters = channel_parameters_[channel_ix];
111 if (current_lag_index_ == 0) { 111 if (current_lag_index_ == 0) {
112 // Use only expand_vector0. 112 // Use only expand_vector0.
113 assert(expansion_vector_position + temp_length <= 113 assert(expansion_vector_position + temp_length <=
114 parameters.expand_vector0.Size()); 114 parameters.expand_vector0.Size());
115 memcpy(voiced_vector_storage, 115 parameters.expand_vector0.CopyTo(temp_length, expansion_vector_position,
116 &parameters.expand_vector0[expansion_vector_position], 116 voiced_vector_storage);
117 sizeof(int16_t) * temp_length);
118 } else if (current_lag_index_ == 1) { 117 } else if (current_lag_index_ == 1) {
118 std::unique_ptr<int16_t[]> temp_0(new int16_t[temp_length]);
119 parameters.expand_vector0.CopyTo(temp_length, expansion_vector_position,
120 temp_0.get());
121 std::unique_ptr<int16_t[]> temp_1(new int16_t[temp_length]);
122 parameters.expand_vector1.CopyTo(temp_length, expansion_vector_position,
123 temp_1.get());
119 // Mix 3/4 of expand_vector0 with 1/4 of expand_vector1. 124 // Mix 3/4 of expand_vector0 with 1/4 of expand_vector1.
120 WebRtcSpl_ScaleAndAddVectorsWithRound( 125 WebRtcSpl_ScaleAndAddVectorsWithRound(temp_0.get(), 3, temp_1.get(), 1, 2,
121 &parameters.expand_vector0[expansion_vector_position], 3, 126 voiced_vector_storage, temp_length);
122 &parameters.expand_vector1[expansion_vector_position], 1, 2,
123 voiced_vector_storage, temp_length);
124 } else if (current_lag_index_ == 2) { 127 } else if (current_lag_index_ == 2) {
125 // Mix 1/2 of expand_vector0 with 1/2 of expand_vector1. 128 // Mix 1/2 of expand_vector0 with 1/2 of expand_vector1.
126 assert(expansion_vector_position + temp_length <= 129 assert(expansion_vector_position + temp_length <=
127 parameters.expand_vector0.Size()); 130 parameters.expand_vector0.Size());
128 assert(expansion_vector_position + temp_length <= 131 assert(expansion_vector_position + temp_length <=
129 parameters.expand_vector1.Size()); 132 parameters.expand_vector1.Size());
130 WebRtcSpl_ScaleAndAddVectorsWithRound( 133
131 &parameters.expand_vector0[expansion_vector_position], 1, 134 std::unique_ptr<int16_t[]> temp_0(new int16_t[temp_length]);
132 &parameters.expand_vector1[expansion_vector_position], 1, 1, 135 parameters.expand_vector0.CopyTo(temp_length, expansion_vector_position,
133 voiced_vector_storage, temp_length); 136 temp_0.get());
137 std::unique_ptr<int16_t[]> temp_1(new int16_t[temp_length]);
138 parameters.expand_vector1.CopyTo(temp_length, expansion_vector_position,
139 temp_1.get());
140 WebRtcSpl_ScaleAndAddVectorsWithRound(temp_0.get(), 1, temp_1.get(), 1, 1,
141 voiced_vector_storage, temp_length);
134 } 142 }
135 143
136 // Get tapering window parameters. Values are in Q15. 144 // Get tapering window parameters. Values are in Q15.
137 int16_t muting_window, muting_window_increment; 145 int16_t muting_window, muting_window_increment;
138 int16_t unmuting_window, unmuting_window_increment; 146 int16_t unmuting_window, unmuting_window_increment;
139 if (fs_hz_ == 8000) { 147 if (fs_hz_ == 8000) {
140 muting_window = DspHelper::kMuteFactorStart8kHz; 148 muting_window = DspHelper::kMuteFactorStart8kHz;
141 muting_window_increment = DspHelper::kMuteFactorIncrement8kHz; 149 muting_window_increment = DspHelper::kMuteFactorIncrement8kHz;
142 unmuting_window = DspHelper::kUnmuteFactorStart8kHz; 150 unmuting_window = DspHelper::kUnmuteFactorStart8kHz;
143 unmuting_window_increment = DspHelper::kUnmuteFactorIncrement8kHz; 151 unmuting_window_increment = DspHelper::kUnmuteFactorIncrement8kHz;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 300
293 // Add background noise to the combined voiced-unvoiced signal. 301 // Add background noise to the combined voiced-unvoiced signal.
294 for (size_t i = 0; i < current_lag; i++) { 302 for (size_t i = 0; i < current_lag; i++) {
295 temp_data[i] = temp_data[i] + noise_vector[i]; 303 temp_data[i] = temp_data[i] + noise_vector[i];
296 } 304 }
297 if (channel_ix == 0) { 305 if (channel_ix == 0) {
298 output->AssertSize(current_lag); 306 output->AssertSize(current_lag);
299 } else { 307 } else {
300 assert(output->Size() == current_lag); 308 assert(output->Size() == current_lag);
301 } 309 }
302 memcpy(&(*output)[channel_ix][0], temp_data, 310 (*output)[channel_ix].OverwriteAt(temp_data, current_lag, 0);
303 sizeof(temp_data[0]) * current_lag);
304 } 311 }
305 312
306 // Increase call number and cap it. 313 // Increase call number and cap it.
307 consecutive_expands_ = consecutive_expands_ >= kMaxConsecutiveExpands ? 314 consecutive_expands_ = consecutive_expands_ >= kMaxConsecutiveExpands ?
308 kMaxConsecutiveExpands : consecutive_expands_ + 1; 315 kMaxConsecutiveExpands : consecutive_expands_ + 1;
309 expand_duration_samples_ += output->Size(); 316 expand_duration_samples_ += output->Size();
310 // Clamp the duration counter at 2 seconds. 317 // Clamp the duration counter at 2 seconds.
311 expand_duration_samples_ = 318 expand_duration_samples_ =
312 std::min(expand_duration_samples_, rtc::checked_cast<size_t>(fs_hz_ * 2)); 319 std::min(expand_duration_samples_, rtc::checked_cast<size_t>(fs_hz_ * 2));
313 return 0; 320 return 0;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 int fs_mult = fs_hz_ / 8000; 373 int fs_mult = fs_hz_ / 8000;
367 374
368 // Pre-calculate common multiplications with fs_mult. 375 // Pre-calculate common multiplications with fs_mult.
369 size_t fs_mult_4 = static_cast<size_t>(fs_mult * 4); 376 size_t fs_mult_4 = static_cast<size_t>(fs_mult * 4);
370 size_t fs_mult_20 = static_cast<size_t>(fs_mult * 20); 377 size_t fs_mult_20 = static_cast<size_t>(fs_mult * 20);
371 size_t fs_mult_120 = static_cast<size_t>(fs_mult * 120); 378 size_t fs_mult_120 = static_cast<size_t>(fs_mult * 120);
372 size_t fs_mult_dist_len = fs_mult * kDistortionLength; 379 size_t fs_mult_dist_len = fs_mult * kDistortionLength;
373 size_t fs_mult_lpc_analysis_len = fs_mult * kLpcAnalysisLength; 380 size_t fs_mult_lpc_analysis_len = fs_mult * kLpcAnalysisLength;
374 381
375 const size_t signal_length = static_cast<size_t>(256 * fs_mult); 382 const size_t signal_length = static_cast<size_t>(256 * fs_mult);
376 const int16_t* audio_history = 383
377 &(*sync_buffer_)[0][sync_buffer_->Size() - signal_length]; 384 const size_t audio_history_position = sync_buffer_->Size() - signal_length;
385 std::unique_ptr<int16_t[]> audio_history(new int16_t[signal_length]);
386 (*sync_buffer_)[0].CopyTo(signal_length, audio_history_position,
387 audio_history.get());
378 388
379 // Initialize. 389 // Initialize.
380 InitializeForAnExpandPeriod(); 390 InitializeForAnExpandPeriod();
381 391
382 // Calculate correlation in downsampled domain (4 kHz sample rate). 392 // Calculate correlation in downsampled domain (4 kHz sample rate).
383 size_t correlation_length = 51; // TODO(hlundin): Legacy bit-exactness. 393 size_t correlation_length = 51; // TODO(hlundin): Legacy bit-exactness.
384 // If it is decided to break bit-exactness |correlation_length| should be 394 // If it is decided to break bit-exactness |correlation_length| should be
385 // initialized to the return value of Correlation(). 395 // initialized to the return value of Correlation().
386 Correlation(audio_history, signal_length, correlation_vector); 396 Correlation(audio_history.get(), signal_length, correlation_vector);
387 397
388 // Find peaks in correlation vector. 398 // Find peaks in correlation vector.
389 DspHelper::PeakDetection(correlation_vector, correlation_length, 399 DspHelper::PeakDetection(correlation_vector, correlation_length,
390 kNumCorrelationCandidates, fs_mult, 400 kNumCorrelationCandidates, fs_mult,
391 best_correlation_index, best_correlation); 401 best_correlation_index, best_correlation);
392 402
393 // Adjust peak locations; cross-correlation lags start at 2.5 ms 403 // Adjust peak locations; cross-correlation lags start at 2.5 ms
394 // (20 * fs_mult samples). 404 // (20 * fs_mult samples).
395 best_correlation_index[0] += fs_mult_20; 405 best_correlation_index[0] += fs_mult_20;
396 best_correlation_index[1] += fs_mult_20; 406 best_correlation_index[1] += fs_mult_20;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 amplitude_ratio = 543 amplitude_ratio =
534 static_cast<int16_t>(WebRtcSpl_SqrtFloor(energy_ratio << 13)); 544 static_cast<int16_t>(WebRtcSpl_SqrtFloor(energy_ratio << 13));
535 // Copy the two vectors and give them the same energy. 545 // Copy the two vectors and give them the same energy.
536 parameters.expand_vector0.Clear(); 546 parameters.expand_vector0.Clear();
537 parameters.expand_vector0.PushBack(vector1, expansion_length); 547 parameters.expand_vector0.PushBack(vector1, expansion_length);
538 parameters.expand_vector1.Clear(); 548 parameters.expand_vector1.Clear();
539 if (parameters.expand_vector1.Size() < expansion_length) { 549 if (parameters.expand_vector1.Size() < expansion_length) {
540 parameters.expand_vector1.Extend( 550 parameters.expand_vector1.Extend(
541 expansion_length - parameters.expand_vector1.Size()); 551 expansion_length - parameters.expand_vector1.Size());
542 } 552 }
543 WebRtcSpl_AffineTransformVector(&parameters.expand_vector1[0], 553 std::unique_ptr<int16_t[]> temp_1(new int16_t[expansion_length]);
554 WebRtcSpl_AffineTransformVector(temp_1.get(),
544 const_cast<int16_t*>(vector2), 555 const_cast<int16_t*>(vector2),
545 amplitude_ratio, 556 amplitude_ratio,
546 4096, 557 4096,
547 13, 558 13,
548 expansion_length); 559 expansion_length);
560 parameters.expand_vector1.OverwriteAt(temp_1.get(), expansion_length, 0);
549 } else { 561 } else {
550 // Energy change constraint not fulfilled. Only use last vector. 562 // Energy change constraint not fulfilled. Only use last vector.
551 parameters.expand_vector0.Clear(); 563 parameters.expand_vector0.Clear();
552 parameters.expand_vector0.PushBack(vector1, expansion_length); 564 parameters.expand_vector0.PushBack(vector1, expansion_length);
553 // Copy from expand_vector0 to expand_vector1. 565 // Copy from expand_vector0 to expand_vector1.
554 parameters.expand_vector0.CopyTo(&parameters.expand_vector1); 566 parameters.expand_vector0.CopyTo(&parameters.expand_vector1);
555 // Set the energy_ratio since it is used by muting slope. 567 // Set the energy_ratio since it is used by muting slope.
556 if ((energy1 / 4 < energy2) || (energy2 == 0)) { 568 if ((energy1 / 4 < energy2) || (energy2 == 0)) {
557 amplitude_ratio = 4096; // 0.5 in Q13. 569 amplitude_ratio = 4096; // 0.5 in Q13.
558 } else { 570 } else {
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; 950 const size_t kMaxRandSamples = RandomVector::kRandomTableSize;
939 while (samples_generated < length) { 951 while (samples_generated < length) {
940 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); 952 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples);
941 random_vector_->IncreaseSeedIncrement(seed_increment); 953 random_vector_->IncreaseSeedIncrement(seed_increment);
942 random_vector_->Generate(rand_length, &random_vector[samples_generated]); 954 random_vector_->Generate(rand_length, &random_vector[samples_generated]);
943 samples_generated += rand_length; 955 samples_generated += rand_length;
944 } 956 }
945 } 957 }
946 958
947 } // namespace webrtc 959 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698