NetEQ: BackgroundNoise::Update returns true when the filter is updated

Bug: webrtc:10690
Change-Id: I17ff7dc1cffc8c46987d0a9ff8c6633ce9dcc8d3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/144040
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28411}
This commit is contained in:
Alessio Bazzica
2019-06-28 10:49:39 +02:00
committed by Commit Bot
parent 825aad13dc
commit 60bfb3d4e3
2 changed files with 27 additions and 23 deletions

View File

@ -45,12 +45,13 @@ void BackgroundNoise::Reset() {
} }
} }
void BackgroundNoise::Update(const AudioMultiVector& input, bool BackgroundNoise::Update(const AudioMultiVector& input,
const PostDecodeVad& vad) { const PostDecodeVad& vad) {
bool filter_params_saved = false;
if (vad.running() && vad.active_speech()) { if (vad.running() && vad.active_speech()) {
// Do not update the background noise parameters if we know that the signal // Do not update the background noise parameters if we know that the signal
// is active speech. // is active speech.
return; return filter_params_saved;
} }
int32_t auto_correlation[kMaxLpcOrder + 1]; int32_t auto_correlation[kMaxLpcOrder + 1];
@ -62,6 +63,7 @@ void BackgroundNoise::Update(const AudioMultiVector& input,
ChannelParameters& parameters = channel_parameters_[channel_ix]; ChannelParameters& parameters = channel_parameters_[channel_ix];
int16_t temp_signal_array[kVecLen + kMaxLpcOrder] = {0}; int16_t temp_signal_array[kVecLen + kMaxLpcOrder] = {0};
int16_t* temp_signal = &temp_signal_array[kMaxLpcOrder]; int16_t* temp_signal = &temp_signal_array[kMaxLpcOrder];
RTC_DCHECK_GE(input.Size(), kVecLen);
input[channel_ix].CopyTo(kVecLen, input.Size() - kVecLen, temp_signal); input[channel_ix].CopyTo(kVecLen, input.Size() - kVecLen, temp_signal);
int32_t sample_energy = int32_t sample_energy =
CalculateAutoCorrelation(temp_signal, kVecLen, auto_correlation); CalculateAutoCorrelation(temp_signal, kVecLen, auto_correlation);
@ -70,7 +72,11 @@ void BackgroundNoise::Update(const AudioMultiVector& input,
sample_energy < parameters.energy_update_threshold) || sample_energy < parameters.energy_update_threshold) ||
(vad.running() && !vad.active_speech())) { (vad.running() && !vad.active_speech())) {
// Generate LPC coefficients. // Generate LPC coefficients.
if (auto_correlation[0] > 0) { if (auto_correlation[0] <= 0) {
// Center value in auto-correlation is not positive. Do not update.
return filter_params_saved;
}
// Regardless of whether the filter is actually updated or not, // Regardless of whether the filter is actually updated or not,
// update energy threshold levels, since we have in fact observed // update energy threshold levels, since we have in fact observed
// a low energy signal. // a low energy signal.
@ -85,11 +91,7 @@ void BackgroundNoise::Update(const AudioMultiVector& input,
if (WebRtcSpl_LevinsonDurbin(auto_correlation, lpc_coefficients, if (WebRtcSpl_LevinsonDurbin(auto_correlation, lpc_coefficients,
reflection_coefficients, reflection_coefficients,
kMaxLpcOrder) != 1) { kMaxLpcOrder) != 1) {
return; return filter_params_saved;
}
} else {
// Center value in auto-correlation is not positive. Do not update.
return;
} }
// Generate the CNG gain factor by looking at the energy of the residual. // Generate the CNG gain factor by looking at the energy of the residual.
@ -113,6 +115,7 @@ void BackgroundNoise::Update(const AudioMultiVector& input,
SaveParameters(channel_ix, lpc_coefficients, SaveParameters(channel_ix, lpc_coefficients,
temp_signal + kVecLen - kMaxLpcOrder, sample_energy, temp_signal + kVecLen - kMaxLpcOrder, sample_energy,
residual_energy); residual_energy);
filter_params_saved = true;
} }
} else { } else {
// Will only happen if post-decode VAD is disabled and |sample_energy| is // Will only happen if post-decode VAD is disabled and |sample_energy| is
@ -121,7 +124,7 @@ void BackgroundNoise::Update(const AudioMultiVector& input,
IncrementEnergyThreshold(channel_ix, sample_energy); IncrementEnergyThreshold(channel_ix, sample_energy);
} }
} }
return; return filter_params_saved;
} }
void BackgroundNoise::GenerateBackgroundNoise( void BackgroundNoise::GenerateBackgroundNoise(

View File

@ -37,7 +37,8 @@ class BackgroundNoise {
// Updates the parameter estimates based on the signal currently in the // Updates the parameter estimates based on the signal currently in the
// |sync_buffer|, and on the latest decision in |vad| if it is running. // |sync_buffer|, and on the latest decision in |vad| if it is running.
void Update(const AudioMultiVector& sync_buffer, const PostDecodeVad& vad); // Returns true if the filter parameters are updated.
bool Update(const AudioMultiVector& sync_buffer, const PostDecodeVad& vad);
// Generates background noise given a random vector and writes the output to // Generates background noise given a random vector and writes the output to
// |buffer|. // |buffer|.