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 <saza@webrtc.org>
Commit-Queue: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31578}
This commit is contained in:
Henrik Lundin
2020-06-29 12:17:42 +02:00
committed by Commit Bot
parent d21f7ab174
commit 11b6f6857f
5 changed files with 25 additions and 27 deletions

View File

@ -90,8 +90,8 @@ class Resampler {
size_t num_channels_; size_t num_channels_;
// Extra instance for stereo // Extra instance for stereo
Resampler* slave_left_; Resampler* helper_left_;
Resampler* slave_right_; Resampler* helper_right_;
}; };
} // namespace webrtc } // namespace webrtc

View File

@ -37,8 +37,8 @@ Resampler::Resampler()
my_out_frequency_khz_(0), my_out_frequency_khz_(0),
my_mode_(kResamplerMode1To1), my_mode_(kResamplerMode1To1),
num_channels_(0), num_channels_(0),
slave_left_(nullptr), helper_left_(nullptr),
slave_right_(nullptr) {} helper_right_(nullptr) {}
Resampler::Resampler(int inFreq, int outFreq, size_t num_channels) Resampler::Resampler(int inFreq, int outFreq, size_t num_channels)
: Resampler() { : Resampler() {
@ -61,11 +61,11 @@ Resampler::~Resampler() {
if (out_buffer_) { if (out_buffer_) {
free(out_buffer_); free(out_buffer_);
} }
if (slave_left_) { if (helper_left_) {
delete slave_left_; delete helper_left_;
} }
if (slave_right_) { if (helper_right_) {
delete slave_right_; delete helper_right_;
} }
} }
@ -120,13 +120,13 @@ int Resampler::Reset(int inFreq, int outFreq, size_t num_channels) {
free(out_buffer_); free(out_buffer_);
out_buffer_ = nullptr; out_buffer_ = nullptr;
} }
if (slave_left_) { if (helper_left_) {
delete slave_left_; delete helper_left_;
slave_left_ = nullptr; helper_left_ = nullptr;
} }
if (slave_right_) { if (helper_right_) {
delete slave_right_; delete helper_right_;
slave_right_ = nullptr; helper_right_ = nullptr;
} }
in_buffer_size_ = 0; in_buffer_size_ = 0;
@ -140,8 +140,8 @@ int Resampler::Reset(int inFreq, int outFreq, size_t num_channels) {
if (num_channels_ == 2) { if (num_channels_ == 2) {
// Create two mono resamplers. // Create two mono resamplers.
slave_left_ = new Resampler(inFreq, outFreq, 1); helper_left_ = new Resampler(inFreq, outFreq, 1);
slave_right_ = new Resampler(inFreq, outFreq, 1); helper_right_ = new Resampler(inFreq, outFreq, 1);
} }
// Now create the states we need. // Now create the states we need.
@ -401,7 +401,7 @@ int Resampler::Push(const int16_t* samplesIn,
size_t maxLen, size_t maxLen,
size_t& outLen) { size_t& outLen) {
if (num_channels_ == 2) { 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 = int16_t* left =
static_cast<int16_t*>(malloc(lengthIn * sizeof(int16_t) / 2)); static_cast<int16_t*>(malloc(lengthIn * sizeof(int16_t) / 2));
int16_t* right = int16_t* right =
@ -422,9 +422,9 @@ int Resampler::Push(const int16_t* samplesIn,
size_t actualOutLen_left = 0; size_t actualOutLen_left = 0;
size_t actualOutLen_right = 0; size_t actualOutLen_right = 0;
// Do resampling for right channel // Do resampling for right channel
res |= slave_left_->Push(left, lengthIn, out_left, maxLen / 2, res |= helper_left_->Push(left, lengthIn, out_left, maxLen / 2,
actualOutLen_left); actualOutLen_left);
res |= slave_right_->Push(right, lengthIn, out_right, maxLen / 2, res |= helper_right_->Push(right, lengthIn, out_right, maxLen / 2,
actualOutLen_right); actualOutLen_right);
if (res || (actualOutLen_left != actualOutLen_right)) { if (res || (actualOutLen_left != actualOutLen_right)) {
free(left); free(left);

View File

@ -80,7 +80,7 @@ size_t Merge::Process(int16_t* input,
if (channel == 0) { if (channel == 0) {
// Downsample, correlate, and find strongest correlation period for the // 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 to 4kHz sample rate.
Downsample(input_channel.get(), input_length_per_channel, Downsample(input_channel.get(), input_length_per_channel,
expanded_channel.get(), expanded_length); expanded_channel.get(), expanded_length);

View File

@ -43,7 +43,7 @@ TimeStretch::ReturnCodes TimeStretch::Process(const int16_t* input,
signal_len = input_len / num_channels_; signal_len = input_len / num_channels_;
signal_array.reset(new int16_t[signal_len]); signal_array.reset(new int16_t[signal_len]);
signal = signal_array.get(); signal = signal_array.get();
size_t j = master_channel_; size_t j = kRefChannel;
for (size_t i = 0; i < signal_len; ++i) { for (size_t i = 0; i < signal_len; ++i) {
signal_array[i] = input[j]; signal_array[i] = input[j];
j += num_channels_; j += num_channels_;
@ -187,7 +187,7 @@ bool TimeStretch::SpeechDetection(int32_t vec1_energy,
(static_cast<int64_t>(vec1_energy) + vec2_energy) / 16); (static_cast<int64_t>(vec1_energy) + vec2_energy) / 16);
int32_t right_side; int32_t right_side;
if (background_noise_.initialized()) { if (background_noise_.initialized()) {
right_side = background_noise_.Energy(master_channel_); right_side = background_noise_.Energy(kRefChannel);
} else { } else {
// If noise parameters have not been estimated, use a fixed threshold. // If noise parameters have not been estimated, use a fixed threshold.
right_side = 75000; right_side = 75000;

View File

@ -40,13 +40,11 @@ class TimeStretch {
: sample_rate_hz_(sample_rate_hz), : sample_rate_hz_(sample_rate_hz),
fs_mult_(sample_rate_hz / 8000), fs_mult_(sample_rate_hz / 8000),
num_channels_(num_channels), num_channels_(num_channels),
master_channel_(0), // First channel is master.
background_noise_(background_noise), background_noise_(background_noise),
max_input_value_(0) { max_input_value_(0) {
assert(sample_rate_hz_ == 8000 || sample_rate_hz_ == 16000 || assert(sample_rate_hz_ == 8000 || sample_rate_hz_ == 16000 ||
sample_rate_hz_ == 32000 || sample_rate_hz_ == 48000); sample_rate_hz_ == 32000 || sample_rate_hz_ == 48000);
assert(num_channels_ > 0); assert(num_channels_ > 0);
assert(master_channel_ < num_channels_);
memset(auto_correlation_, 0, sizeof(auto_correlation_)); memset(auto_correlation_, 0, sizeof(auto_correlation_));
} }
@ -86,11 +84,11 @@ class TimeStretch {
static const size_t kMaxLag = 60; static const size_t kMaxLag = 60;
static const size_t kDownsampledLen = kCorrelationLen + kMaxLag; static const size_t kDownsampledLen = kCorrelationLen + kMaxLag;
static const int kCorrelationThreshold = 14746; // 0.9 in Q14. 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 sample_rate_hz_;
const int fs_mult_; // Sample rate multiplier = sample_rate_hz_ / 8000. const int fs_mult_; // Sample rate multiplier = sample_rate_hz_ / 8000.
const size_t num_channels_; const size_t num_channels_;
const size_t master_channel_;
const BackgroundNoise& background_noise_; const BackgroundNoise& background_noise_;
int16_t max_input_value_; int16_t max_input_value_;
int16_t downsampled_input_[kDownsampledLen]; int16_t downsampled_input_[kDownsampledLen];