Optimize suppression_filter.
Reducing pointer following. This will allow the compiler to optimize more efficiently with the "-fno-strict-aliasing" flag.
Bug: None
Change-Id: I7cde835161e2d3e85fc7c919556fa9a9e87ef6df
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/238169
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Reviewed-by: Per Ã…hgren <peah@webrtc.org>
Commit-Queue: Christian Schuldt <cschuldt@google.com>
Cr-Commit-Position: refs/heads/main@{#35393}
diff --git a/modules/audio_processing/aec3/suppression_filter.cc b/modules/audio_processing/aec3/suppression_filter.cc
index 8a813d9..1312fa8 100644
--- a/modules/audio_processing/aec3/suppression_filter.cc
+++ b/modules/audio_processing/aec3/suppression_filter.cc
@@ -108,12 +108,12 @@
for (size_t i = 0; i < kFftLengthBy2Plus1; ++i) {
// Apply suppression gains.
- E.re[i] *= suppression_gain[i];
- E.im[i] *= suppression_gain[i];
+ float E_real = E.re[i] * suppression_gain[i];
+ float E_imag = E.im[i] * suppression_gain[i];
// Scale and add the comfort noise.
- E.re[i] += noise_gain[i] * comfort_noise[ch].re[i];
- E.im[i] += noise_gain[i] * comfort_noise[ch].im[i];
+ E.re[i] = E_real + noise_gain[i] * comfort_noise[ch].re[i];
+ E.im[i] = E_imag + noise_gain[i] * comfort_noise[ch].im[i];
}
// Synthesis filterbank.
@@ -121,24 +121,25 @@
constexpr float kIfftNormalization = 2.f / kFftLength;
fft_.Ifft(E, &e_extended);
- auto& e0 = (*e)[0][ch];
- auto& e0_old = e_output_old_[0][ch];
+ float* e0 = (*e)[0][ch].data();
+ float* e0_old = e_output_old_[0][ch].data();
// Window and add the first half of e_extended with the second half of
// e_extended from the previous block.
for (size_t i = 0; i < kFftLengthBy2; ++i) {
- e0[i] = e0_old[i] * kSqrtHanning[kFftLengthBy2 + i];
- e0[i] += e_extended[i] * kSqrtHanning[i];
- e0[i] *= kIfftNormalization;
+ float e0_i = e0_old[i] * kSqrtHanning[kFftLengthBy2 + i];
+ e0_i += e_extended[i] * kSqrtHanning[i];
+ e0[i] = e0_i * kIfftNormalization;
}
// The second half of e_extended is stored for the succeeding frame.
std::copy(e_extended.begin() + kFftLengthBy2,
- e_extended.begin() + kFftLength, std::begin(e0_old));
+ e_extended.begin() + kFftLength,
+ std::begin(e_output_old_[0][ch]));
// Apply suppression gain to upper bands.
for (size_t b = 1; b < e->size(); ++b) {
- auto& e_band = (*e)[b][ch];
+ float* e_band = (*e)[b][ch].data();
for (size_t i = 0; i < kFftLengthBy2; ++i) {
e_band[i] *= high_bands_gain;
}
@@ -150,7 +151,7 @@
std::array<float, kFftLength> time_domain_high_band_noise;
fft_.Ifft(E, &time_domain_high_band_noise);
- auto& e1 = (*e)[1][ch];
+ float* e1 = (*e)[1][ch].data();
const float gain = high_bands_noise_scaling * kIfftNormalization;
for (size_t i = 0; i < kFftLengthBy2; ++i) {
e1[i] += time_domain_high_band_noise[i] * gain;
@@ -159,8 +160,8 @@
// Delay upper bands to match the delay of the filter bank.
for (size_t b = 1; b < e->size(); ++b) {
- auto& e_band = (*e)[b][ch];
- auto& e_band_old = e_output_old_[b][ch];
+ float* e_band = (*e)[b][ch].data();
+ float* e_band_old = e_output_old_[b][ch].data();
for (size_t i = 0; i < kFftLengthBy2; ++i) {
std::swap(e_band[i], e_band_old[i]);
}
@@ -168,7 +169,7 @@
// Clamp output of all bands.
for (size_t b = 0; b < e->size(); ++b) {
- auto& e_band = (*e)[b][ch];
+ float* e_band = (*e)[b][ch].data();
for (size_t i = 0; i < kFftLengthBy2; ++i) {
e_band[i] = rtc::SafeClamp(e_band[i], -32768.f, 32767.f);
}