diff --git a/webrtc/modules/audio_processing/aec/aec_core.c b/webrtc/modules/audio_processing/aec/aec_core.c index 26e13bc2c2..18189a0b7c 100644 --- a/webrtc/modules/audio_processing/aec/aec_core.c +++ b/webrtc/modules/audio_processing/aec/aec_core.c @@ -667,12 +667,11 @@ static void UpdateMetrics(AecCore* aec) { // A_NLP dtmp = 10 * (float)log10(aec->nearlevel.averagelevel / - (2 * aec->linoutlevel.averagelevel) + - 1e-10f); + aec->linoutlevel.averagelevel + 1e-10f); // subtract noise power - suppressedEcho = 2 * (aec->linoutlevel.averagelevel - - safety * aec->linoutlevel.minlevel); + suppressedEcho = aec->linoutlevel.averagelevel - + safety * aec->linoutlevel.minlevel; dtmp2 = 10 * (float)log10(echo / suppressedEcho + 1e-10f); @@ -903,7 +902,6 @@ static void EchoSubtraction( AecCore* aec, int num_partitions, int x_fft_buf_block_pos, - int metrics_mode, int extended_filter_enabled, float normal_mu, float normal_error_threshold, @@ -911,7 +909,6 @@ static void EchoSubtraction( float* const y, float x_pow[PART_LEN1], float h_fft_buf[2][kExtendedNumPartitions * PART_LEN1], - PowerLevel* linout_level, float echo_subtractor_output[PART_LEN]) { float s_fft[2][PART_LEN1]; float e_extended[PART_LEN2]; @@ -955,13 +952,6 @@ static void EchoSubtraction( &e_fft[0][0], sizeof(e_fft[0][0]) * PART_LEN1 * 2); - if (metrics_mode == 1) { - // Note that the first PART_LEN samples in fft (before transformation) are - // zero. Hence, the scaling by two in UpdateLevel() should not be - // performed. That scaling is taken care of in UpdateMetrics() instead. - UpdateLevel(linout_level, CalculatePower(e, PART_LEN) / 2.0f); - } - // Scale error signal inversely with far power. WebRtcAec_ScaleErrorSignal(extended_filter_enabled, normal_mu, @@ -976,7 +966,6 @@ static void EchoSubtraction( memcpy(echo_subtractor_output, e, sizeof(float) * PART_LEN); } - static void EchoSuppression(AecCore* aec, float farend[PART_LEN2], float* echo_subtractor_output, @@ -1279,6 +1268,13 @@ static void ProcessBlock(AecCore* aec) { } #endif + if (aec->metricsMode == 1) { + // Update power levels + UpdateLevel(&aec->farlevel, + CalculatePower(&farend_ptr[PART_LEN], PART_LEN)); + UpdateLevel(&aec->nearlevel, CalculatePower(nearend_ptr, PART_LEN)); + } + // Convert far-end signal to the frequency domain. memcpy(fft, farend_ptr, sizeof(float) * PART_LEN2); Fft(fft, xf); @@ -1288,12 +1284,6 @@ static void ProcessBlock(AecCore* aec) { memcpy(fft, aec->dBuf, sizeof(float) * PART_LEN2); Fft(fft, df); - if (aec->metricsMode == 1) { - // Update power levels - UpdateLevel(&aec->farlevel, CalculatePower(farend_ptr, PART_LEN2)); - UpdateLevel(&aec->nearlevel, CalculatePower(aec->dBuf, PART_LEN2)); - } - // Power smoothing for (i = 0; i < PART_LEN1; i++) { far_spectrum = (xf_ptr[i] * xf_ptr[i]) + @@ -1374,7 +1364,6 @@ static void ProcessBlock(AecCore* aec) { EchoSubtraction(aec, aec->num_partitions, aec->xfBufBlockPos, - aec->metricsMode, aec->extended_filter_enabled, aec->normal_mu, aec->normal_error_threshold, @@ -1382,11 +1371,15 @@ static void ProcessBlock(AecCore* aec) { nearend_ptr, aec->xPow, aec->wfBuf, - &aec->linoutlevel, echo_subtractor_output); RTC_AEC_DEBUG_WAV_WRITE(aec->outLinearFile, echo_subtractor_output, PART_LEN); + if (aec->metricsMode == 1) { + UpdateLevel(&aec->linoutlevel, + CalculatePower(echo_subtractor_output, PART_LEN)); + } + // Perform echo suppression. EchoSuppression(aec, farend_ptr, echo_subtractor_output, output, outputH_ptr); @@ -1713,7 +1706,6 @@ int WebRtcAec_InitAec(AecCore* aec, int sampFreq) { return 0; } - // For bit exactness with a legacy code, |farend| is supposed to contain // |PART_LEN2| samples with an overlap of |PART_LEN| samples from the last // frame. diff --git a/webrtc/modules/audio_processing/test/audio_processing_unittest.cc b/webrtc/modules/audio_processing/test/audio_processing_unittest.cc index 1b37120456..667ed2aafc 100644 --- a/webrtc/modules/audio_processing/test/audio_processing_unittest.cc +++ b/webrtc/modules/audio_processing/test/audio_processing_unittest.cc @@ -203,10 +203,10 @@ int16_t MaxAudioFrame(const AudioFrame& frame) { #if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE) void TestStats(const AudioProcessing::Statistic& test, const audioproc::Test::Statistic& reference) { - EXPECT_EQ(reference.instant(), test.instant); + EXPECT_NEAR(reference.instant(), test.instant, 1); EXPECT_EQ(reference.average(), test.average); EXPECT_EQ(reference.maximum(), test.maximum); - EXPECT_EQ(reference.minimum(), test.minimum); + EXPECT_NEAR(reference.minimum(), test.minimum, 1); } void WriteStatsMessage(const AudioProcessing::Statistic& output,