From 11b6f6857f07c5254157656f68ae6f16a1b77198 Mon Sep 17 00:00:00 2001 From: Henrik Lundin Date: Mon, 29 Jun 2020 12:17:42 +0200 Subject: [PATCH] Replace slave -> helper, master -> reference A slight simplification of the NetEq code is also included. The subtrees below common_audio, modules/audio_coding and modules/audio_processing were scanned while making this CL. Bug: webrtc:11680 Change-Id: I33bb1c75b2e3d1c6793fd1c5741ca59f4b6e8455 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178361 Reviewed-by: Sam Zackrisson Commit-Queue: Henrik Lundin Cr-Commit-Position: refs/heads/master@{#31578} --- common_audio/resampler/include/resampler.h | 4 +-- common_audio/resampler/resampler.cc | 38 +++++++++++----------- modules/audio_coding/neteq/merge.cc | 2 +- modules/audio_coding/neteq/time_stretch.cc | 4 +-- modules/audio_coding/neteq/time_stretch.h | 4 +-- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/common_audio/resampler/include/resampler.h b/common_audio/resampler/include/resampler.h index 04c487b331..41940f9a12 100644 --- a/common_audio/resampler/include/resampler.h +++ b/common_audio/resampler/include/resampler.h @@ -90,8 +90,8 @@ class Resampler { size_t num_channels_; // Extra instance for stereo - Resampler* slave_left_; - Resampler* slave_right_; + Resampler* helper_left_; + Resampler* helper_right_; }; } // namespace webrtc diff --git a/common_audio/resampler/resampler.cc b/common_audio/resampler/resampler.cc index ce38ef56de..ccfed5a014 100644 --- a/common_audio/resampler/resampler.cc +++ b/common_audio/resampler/resampler.cc @@ -37,8 +37,8 @@ Resampler::Resampler() my_out_frequency_khz_(0), my_mode_(kResamplerMode1To1), num_channels_(0), - slave_left_(nullptr), - slave_right_(nullptr) {} + helper_left_(nullptr), + helper_right_(nullptr) {} Resampler::Resampler(int inFreq, int outFreq, size_t num_channels) : Resampler() { @@ -61,11 +61,11 @@ Resampler::~Resampler() { if (out_buffer_) { free(out_buffer_); } - if (slave_left_) { - delete slave_left_; + if (helper_left_) { + delete helper_left_; } - if (slave_right_) { - delete slave_right_; + if (helper_right_) { + delete helper_right_; } } @@ -120,13 +120,13 @@ int Resampler::Reset(int inFreq, int outFreq, size_t num_channels) { free(out_buffer_); out_buffer_ = nullptr; } - if (slave_left_) { - delete slave_left_; - slave_left_ = nullptr; + if (helper_left_) { + delete helper_left_; + helper_left_ = nullptr; } - if (slave_right_) { - delete slave_right_; - slave_right_ = nullptr; + if (helper_right_) { + delete helper_right_; + helper_right_ = nullptr; } in_buffer_size_ = 0; @@ -140,8 +140,8 @@ int Resampler::Reset(int inFreq, int outFreq, size_t num_channels) { if (num_channels_ == 2) { // Create two mono resamplers. - slave_left_ = new Resampler(inFreq, outFreq, 1); - slave_right_ = new Resampler(inFreq, outFreq, 1); + helper_left_ = new Resampler(inFreq, outFreq, 1); + helper_right_ = new Resampler(inFreq, outFreq, 1); } // Now create the states we need. @@ -401,7 +401,7 @@ int Resampler::Push(const int16_t* samplesIn, size_t maxLen, size_t& outLen) { if (num_channels_ == 2) { - // Split up the signal and call the slave object for each channel + // Split up the signal and call the helper object for each channel int16_t* left = static_cast(malloc(lengthIn * sizeof(int16_t) / 2)); int16_t* right = @@ -422,10 +422,10 @@ int Resampler::Push(const int16_t* samplesIn, size_t actualOutLen_left = 0; size_t actualOutLen_right = 0; // Do resampling for right channel - res |= slave_left_->Push(left, lengthIn, out_left, maxLen / 2, - actualOutLen_left); - res |= slave_right_->Push(right, lengthIn, out_right, maxLen / 2, - actualOutLen_right); + res |= helper_left_->Push(left, lengthIn, out_left, maxLen / 2, + actualOutLen_left); + res |= helper_right_->Push(right, lengthIn, out_right, maxLen / 2, + actualOutLen_right); if (res || (actualOutLen_left != actualOutLen_right)) { free(left); free(right); diff --git a/modules/audio_coding/neteq/merge.cc b/modules/audio_coding/neteq/merge.cc index 552192d910..f1f2cc97e3 100644 --- a/modules/audio_coding/neteq/merge.cc +++ b/modules/audio_coding/neteq/merge.cc @@ -80,7 +80,7 @@ size_t Merge::Process(int16_t* input, if (channel == 0) { // Downsample, correlate, and find strongest correlation period for the - // master (i.e., first) channel only. + // reference (i.e., first) channel only. // Downsample to 4kHz sample rate. Downsample(input_channel.get(), input_length_per_channel, expanded_channel.get(), expanded_length); diff --git a/modules/audio_coding/neteq/time_stretch.cc b/modules/audio_coding/neteq/time_stretch.cc index 560d9be56d..ba24e0bfc3 100644 --- a/modules/audio_coding/neteq/time_stretch.cc +++ b/modules/audio_coding/neteq/time_stretch.cc @@ -43,7 +43,7 @@ TimeStretch::ReturnCodes TimeStretch::Process(const int16_t* input, signal_len = input_len / num_channels_; signal_array.reset(new int16_t[signal_len]); signal = signal_array.get(); - size_t j = master_channel_; + size_t j = kRefChannel; for (size_t i = 0; i < signal_len; ++i) { signal_array[i] = input[j]; j += num_channels_; @@ -187,7 +187,7 @@ bool TimeStretch::SpeechDetection(int32_t vec1_energy, (static_cast(vec1_energy) + vec2_energy) / 16); int32_t right_side; if (background_noise_.initialized()) { - right_side = background_noise_.Energy(master_channel_); + right_side = background_noise_.Energy(kRefChannel); } else { // If noise parameters have not been estimated, use a fixed threshold. right_side = 75000; diff --git a/modules/audio_coding/neteq/time_stretch.h b/modules/audio_coding/neteq/time_stretch.h index 9f866493d9..aede9cadf3 100644 --- a/modules/audio_coding/neteq/time_stretch.h +++ b/modules/audio_coding/neteq/time_stretch.h @@ -40,13 +40,11 @@ class TimeStretch { : sample_rate_hz_(sample_rate_hz), fs_mult_(sample_rate_hz / 8000), num_channels_(num_channels), - master_channel_(0), // First channel is master. background_noise_(background_noise), max_input_value_(0) { assert(sample_rate_hz_ == 8000 || sample_rate_hz_ == 16000 || sample_rate_hz_ == 32000 || sample_rate_hz_ == 48000); assert(num_channels_ > 0); - assert(master_channel_ < num_channels_); memset(auto_correlation_, 0, sizeof(auto_correlation_)); } @@ -86,11 +84,11 @@ class TimeStretch { static const size_t kMaxLag = 60; static const size_t kDownsampledLen = kCorrelationLen + kMaxLag; static const int kCorrelationThreshold = 14746; // 0.9 in Q14. + static constexpr size_t kRefChannel = 0; // First channel is reference. const int sample_rate_hz_; const int fs_mult_; // Sample rate multiplier = sample_rate_hz_ / 8000. const size_t num_channels_; - const size_t master_channel_; const BackgroundNoise& background_noise_; int16_t max_input_value_; int16_t downsampled_input_[kDownsampledLen];