From 024d0157ab05602dd606f22b36d3a47b97e95f40 Mon Sep 17 00:00:00 2001 From: Alessio Bazzica Date: Wed, 21 Oct 2020 13:32:02 +0200 Subject: [PATCH] RNN VAD: LP residual optimized (part 2) The cross-correlation function in the anonimous namespace of lp_residual.cc is used once as to compute auto-correlation coefficients. Hence, it can be simplified (and renamed). Note that the `RnnVadTest.LpResidualPipelineBitExactness` unit test is still passing. Bug: webrtc:10480 Change-Id: Ie769e42907c15572172a8ad1a34e82ce60c4a386 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/189962 Commit-Queue: Alessio Bazzica Reviewed-by: Sam Zackrisson Cr-Commit-Position: refs/heads/master@{#32464} --- .../agc2/rnn_vad/lp_residual.cc | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/modules/audio_processing/agc2/rnn_vad/lp_residual.cc b/modules/audio_processing/agc2/rnn_vad/lp_residual.cc index dabe507202..dd9212f838 100644 --- a/modules/audio_processing/agc2/rnn_vad/lp_residual.cc +++ b/modules/audio_processing/agc2/rnn_vad/lp_residual.cc @@ -21,22 +21,17 @@ namespace webrtc { namespace rnn_vad { namespace { -// Computes cross-correlation coefficients between |x| and |y| and writes them -// in |x_corr|. The lag values are in {0, ..., max_lag - 1}, where max_lag -// equals the size of |x_corr|. -// The |x| and |y| sub-arrays used to compute a cross-correlation coefficients -// for a lag l have both size "size of |x| - l" - i.e., the longest sub-array is -// used. |x| and |y| must have the same size. -void ComputeCrossCorrelation( +// Computes auto-correlation coefficients for |x| and writes them in +// |auto_corr|. The lag values are in {0, ..., max_lag - 1}, where max_lag +// equals the size of |auto_corr|. +void ComputeAutoCorrelation( rtc::ArrayView x, - rtc::ArrayView y, - rtc::ArrayView x_corr) { - constexpr size_t max_lag = x_corr.size(); - RTC_DCHECK_EQ(x.size(), y.size()); + rtc::ArrayView auto_corr) { + constexpr size_t max_lag = auto_corr.size(); RTC_DCHECK_LT(max_lag, x.size()); for (size_t lag = 0; lag < max_lag; ++lag) { - x_corr[lag] = - std::inner_product(x.begin(), x.end() - lag, y.begin() + lag, 0.f); + auto_corr[lag] = + std::inner_product(x.begin(), x.end() - lag, x.begin() + lag, 0.f); } } @@ -91,12 +86,12 @@ void ComputeAndPostProcessLpcCoefficients( rtc::ArrayView x, rtc::ArrayView lpc_coeffs) { std::array auto_corr; - ComputeCrossCorrelation(x, x, {auto_corr.data(), auto_corr.size()}); + ComputeAutoCorrelation(x, auto_corr); if (auto_corr[0] == 0.f) { // Empty frame. std::fill(lpc_coeffs.begin(), lpc_coeffs.end(), 0); return; } - DenoiseAutoCorrelation({auto_corr.data(), auto_corr.size()}); + DenoiseAutoCorrelation(auto_corr); std::array lpc_coeffs_pre{}; ComputeInitialInverseFilterCoefficients(auto_corr, lpc_coeffs_pre); // LPC coefficients post-processing.