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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/neteq/expand.cc
diff --git a/webrtc/modules/audio_coding/neteq/expand.cc b/webrtc/modules/audio_coding/neteq/expand.cc
index 5cb18db462a7a260bf6aa56880be0a27b81b19c7..c2c88c83a4f0d69fc08aeea14b2b0e3a055bf2a9 100644
--- a/webrtc/modules/audio_coding/neteq/expand.cc
+++ b/webrtc/modules/audio_coding/neteq/expand.cc
@@ -112,25 +112,33 @@ int Expand::Process(AudioMultiVector* output) {
// Use only expand_vector0.
assert(expansion_vector_position + temp_length <=
parameters.expand_vector0.Size());
- memcpy(voiced_vector_storage,
- &parameters.expand_vector0[expansion_vector_position],
- sizeof(int16_t) * temp_length);
+ parameters.expand_vector0.CopyTo(temp_length, expansion_vector_position,
+ voiced_vector_storage);
} else if (current_lag_index_ == 1) {
+ std::unique_ptr<int16_t[]> temp_0(new int16_t[temp_length]);
+ parameters.expand_vector0.CopyTo(temp_length, expansion_vector_position,
+ temp_0.get());
+ std::unique_ptr<int16_t[]> temp_1(new int16_t[temp_length]);
+ parameters.expand_vector1.CopyTo(temp_length, expansion_vector_position,
+ temp_1.get());
// Mix 3/4 of expand_vector0 with 1/4 of expand_vector1.
- WebRtcSpl_ScaleAndAddVectorsWithRound(
- &parameters.expand_vector0[expansion_vector_position], 3,
- &parameters.expand_vector1[expansion_vector_position], 1, 2,
- voiced_vector_storage, temp_length);
+ WebRtcSpl_ScaleAndAddVectorsWithRound(temp_0.get(), 3, temp_1.get(), 1, 2,
+ voiced_vector_storage, temp_length);
} else if (current_lag_index_ == 2) {
// Mix 1/2 of expand_vector0 with 1/2 of expand_vector1.
assert(expansion_vector_position + temp_length <=
parameters.expand_vector0.Size());
assert(expansion_vector_position + temp_length <=
parameters.expand_vector1.Size());
- WebRtcSpl_ScaleAndAddVectorsWithRound(
- &parameters.expand_vector0[expansion_vector_position], 1,
- &parameters.expand_vector1[expansion_vector_position], 1, 1,
- voiced_vector_storage, temp_length);
+
+ std::unique_ptr<int16_t[]> temp_0(new int16_t[temp_length]);
+ parameters.expand_vector0.CopyTo(temp_length, expansion_vector_position,
+ temp_0.get());
+ std::unique_ptr<int16_t[]> temp_1(new int16_t[temp_length]);
+ parameters.expand_vector1.CopyTo(temp_length, expansion_vector_position,
+ temp_1.get());
+ WebRtcSpl_ScaleAndAddVectorsWithRound(temp_0.get(), 1, temp_1.get(), 1, 1,
+ voiced_vector_storage, temp_length);
}
// Get tapering window parameters. Values are in Q15.
@@ -299,8 +307,7 @@ int Expand::Process(AudioMultiVector* output) {
} else {
assert(output->Size() == current_lag);
}
- memcpy(&(*output)[channel_ix][0], temp_data,
- sizeof(temp_data[0]) * current_lag);
+ (*output)[channel_ix].OverwriteAt(temp_data, current_lag, 0);
}
// Increase call number and cap it.
@@ -373,8 +380,11 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
size_t fs_mult_lpc_analysis_len = fs_mult * kLpcAnalysisLength;
const size_t signal_length = static_cast<size_t>(256 * fs_mult);
- const int16_t* audio_history =
- &(*sync_buffer_)[0][sync_buffer_->Size() - signal_length];
+
+ const size_t audio_history_position = sync_buffer_->Size() - signal_length;
+ std::unique_ptr<int16_t[]> audio_history(new int16_t[signal_length]);
+ (*sync_buffer_)[0].CopyTo(signal_length, audio_history_position,
+ audio_history.get());
// Initialize.
InitializeForAnExpandPeriod();
@@ -383,7 +393,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
size_t correlation_length = 51; // TODO(hlundin): Legacy bit-exactness.
// If it is decided to break bit-exactness |correlation_length| should be
// initialized to the return value of Correlation().
- Correlation(audio_history, signal_length, correlation_vector);
+ Correlation(audio_history.get(), signal_length, correlation_vector);
// Find peaks in correlation vector.
DspHelper::PeakDetection(correlation_vector, correlation_length,
@@ -540,12 +550,14 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
parameters.expand_vector1.Extend(
expansion_length - parameters.expand_vector1.Size());
}
- WebRtcSpl_AffineTransformVector(&parameters.expand_vector1[0],
+ std::unique_ptr<int16_t[]> temp_1(new int16_t[expansion_length]);
+ WebRtcSpl_AffineTransformVector(temp_1.get(),
const_cast<int16_t*>(vector2),
amplitude_ratio,
4096,
13,
expansion_length);
+ parameters.expand_vector1.OverwriteAt(temp_1.get(), expansion_length, 0);
} else {
// Energy change constraint not fulfilled. Only use last vector.
parameters.expand_vector0.Clear();

Powered by Google App Engine
This is Rietveld 408576698