Fix variable shadowing in the Audio Processing Module

Bug: webrtc:42223409
Change-Id: I7ba3678ae4ff30e5637fca8894da2928b7e25f12
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/382741
Reviewed-by: Per Ã…hgren <peah@webrtc.org>
Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#44231}
diff --git a/modules/audio_processing/aec3/matched_filter.cc b/modules/audio_processing/aec3/matched_filter.cc
index 7f9e113..b5ed883 100644
--- a/modules/audio_processing/aec3/matched_filter.cc
+++ b/modules/audio_processing/aec3/matched_filter.cc
@@ -9,6 +9,9 @@
  */
 #include "modules/audio_processing/aec3/matched_filter.h"
 
+#include <string>
+#include <vector>
+
 // Defines WEBRTC_ARCH_X86_FAMILY, used below.
 #include "rtc_base/system/arch.h"
 
@@ -21,11 +24,10 @@
 #include <algorithm>
 #include <cstddef>
 #include <initializer_list>
-#include <iterator>
-#include <numeric>
 #include <optional>
 
 #include "api/array_view.h"
+#include "modules/audio_processing/aec3/aec3_common.h"
 #include "modules/audio_processing/aec3/downsampled_render_buffer.h"
 #include "modules/audio_processing/logging/apm_data_dumper.h"
 #include "rtc_base/checks.h"
@@ -361,20 +363,20 @@
       const float alpha = smoothing * e / x2_sum;
       const __m128 alpha_128 = _mm_set1_ps(alpha);
       // filter = filter + smoothing * (y - filter * x) * x / x * x.
-      float* h_p = &h[0];
-      const float* x_p =
+      float* h_p2 = &h[0];
+      const float* x_p2 =
           chunk1 != h_size ? scratch_memory.data() : &x[x_start_index];
       // Perform 128 bit vector operations.
       const int limit_by_4 = h_size >> 2;
-      for (int k = limit_by_4; k > 0; --k, h_p += 4, x_p += 4) {
+      for (int k = limit_by_4; k > 0; --k, h_p2 += 4, x_p2 += 4) {
         // Load the data into 128 bit vectors.
-        __m128 h_k = _mm_loadu_ps(h_p);
-        const __m128 x_k = _mm_loadu_ps(x_p);
+        __m128 h_k = _mm_loadu_ps(h_p2);
+        const __m128 x_k = _mm_loadu_ps(x_p2);
         // Compute h = h + alpha * x.
         const __m128 alpha_x = _mm_mul_ps(alpha_128, x_k);
         h_k = _mm_add_ps(h_k, alpha_x);
         // Store the result.
-        _mm_storeu_ps(h_p, h_k);
+        _mm_storeu_ps(h_p2, h_k);
       }
       *filters_updated = true;
     }
@@ -464,26 +466,26 @@
       const float alpha = smoothing * e / x2_sum;
       const __m128 alpha_128 = _mm_set1_ps(alpha);
       // filter = filter + smoothing * (y - filter * x) * x / x * x.
-      float* h_p = &h[0];
+      float* h_p2 = &h[0];
       x_p = &x[x_start_index];
       // Perform the loop in two chunks.
       for (int limit : {chunk1, chunk2}) {
         // Perform 128 bit vector operations.
         const int limit_by_4 = limit >> 2;
-        for (int k = limit_by_4; k > 0; --k, h_p += 4, x_p += 4) {
+        for (int k = limit_by_4; k > 0; --k, h_p2 += 4, x_p += 4) {
           // Load the data into 128 bit vectors.
-          __m128 h_k = _mm_loadu_ps(h_p);
+          __m128 h_k = _mm_loadu_ps(h_p2);
           const __m128 x_k = _mm_loadu_ps(x_p);
 
           // Compute h = h + alpha * x.
           const __m128 alpha_x = _mm_mul_ps(alpha_128, x_k);
           h_k = _mm_add_ps(h_k, alpha_x);
           // Store the result.
-          _mm_storeu_ps(h_p, h_k);
+          _mm_storeu_ps(h_p2, h_k);
         }
         // Perform non-vector operations for any remaining items.
-        for (int k = limit - limit_by_4 * 4; k > 0; --k, ++h_p, ++x_p) {
-          *h_p += alpha * *x_p;
+        for (int k = limit - limit_by_4 * 4; k > 0; --k, ++h_p2, ++x_p) {
+          *h_p2 += alpha * *x_p;
         }
         x_p = &x[0];
       }
@@ -543,10 +545,10 @@
       const float alpha = smoothing * e / x2_sum;
 
       // filter = filter + smoothing * (y - filter * x) * x / x * x.
-      size_t x_index = x_start_index;
+      size_t x_index2 = x_start_index;
       for (size_t k = 0; k < h.size(); ++k) {
-        h[k] += alpha * x[x_index];
-        x_index = x_index < (x.size() - 1) ? x_index + 1 : 0;
+        h[k] += alpha * x[x_index2];
+        x_index2 = x_index2 < (x.size() - 1) ? x_index2 + 1 : 0;
       }
       *filters_updated = true;
     }
diff --git a/modules/audio_processing/aec3/matched_filter_avx2.cc b/modules/audio_processing/aec3/matched_filter_avx2.cc
index 8c2ffcb..6babff8 100644
--- a/modules/audio_processing/aec3/matched_filter_avx2.cc
+++ b/modules/audio_processing/aec3/matched_filter_avx2.cc
@@ -10,6 +10,10 @@
 
 #include <immintrin.h>
 
+#include <algorithm>
+#include <cstddef>
+
+#include "api/array_view.h"
 #include "modules/audio_processing/aec3/matched_filter.h"
 #include "rtc_base/checks.h"
 
@@ -90,9 +94,9 @@
       s_acum += s_inst_hadd_256[5];
       e_128[3] = s_acum - y[i];
 
-      __m128 accumulated_error = _mm_load_ps(a_p);
-      accumulated_error = _mm_fmadd_ps(e_128, e_128, accumulated_error);
-      _mm_storeu_ps(a_p, accumulated_error);
+      __m128 acum_error = _mm_load_ps(a_p);
+      acum_error = _mm_fmadd_ps(e_128, e_128, acum_error);
+      _mm_storeu_ps(a_p, acum_error);
     }
     // Sum components together.
     x2_sum_256 = _mm256_add_ps(x2_sum_256, x2_sum_256_8);
@@ -114,20 +118,20 @@
       const __m256 alpha_256 = _mm256_set1_ps(alpha);
 
       // filter = filter + smoothing * (y - filter * x) * x / x * x.
-      float* h_p = &h[0];
-      const float* x_p =
+      float* h_p2 = &h[0];
+      const float* x_p2 =
           chunk1 != h_size ? scratch_memory.data() : &x[x_start_index];
       // Perform 256 bit vector operations.
       const int limit_by_8 = h_size >> 3;
-      for (int k = limit_by_8; k > 0; --k, h_p += 8, x_p += 8) {
+      for (int k = limit_by_8; k > 0; --k, h_p2 += 8, x_p2 += 8) {
         // Load the data into 256 bit vectors.
-        __m256 h_k = _mm256_loadu_ps(h_p);
-        __m256 x_k = _mm256_loadu_ps(x_p);
+        __m256 h_k = _mm256_loadu_ps(h_p2);
+        __m256 x_k = _mm256_loadu_ps(x_p2);
         // Compute h = h + alpha * x.
         h_k = _mm256_fmadd_ps(x_k, alpha_256, h_k);
 
         // Store the result.
-        _mm256_storeu_ps(h_p, h_k);
+        _mm256_storeu_ps(h_p2, h_k);
       }
       *filters_updated = true;
     }
@@ -224,27 +228,27 @@
       const __m256 alpha_256 = _mm256_set1_ps(alpha);
 
       // filter = filter + smoothing * (y - filter * x) * x / x * x.
-      float* h_p = &h[0];
+      float* h_p2 = &h[0];
       x_p = &x[x_start_index];
 
       // Perform the loop in two chunks.
       for (int limit : {chunk1, chunk2}) {
         // Perform 256 bit vector operations.
         const int limit_by_8 = limit >> 3;
-        for (int k = limit_by_8; k > 0; --k, h_p += 8, x_p += 8) {
+        for (int k = limit_by_8; k > 0; --k, h_p2 += 8, x_p += 8) {
           // Load the data into 256 bit vectors.
-          __m256 h_k = _mm256_loadu_ps(h_p);
+          __m256 h_k = _mm256_loadu_ps(h_p2);
           __m256 x_k = _mm256_loadu_ps(x_p);
           // Compute h = h + alpha * x.
           h_k = _mm256_fmadd_ps(x_k, alpha_256, h_k);
 
           // Store the result.
-          _mm256_storeu_ps(h_p, h_k);
+          _mm256_storeu_ps(h_p2, h_k);
         }
 
         // Perform non-vector operations for any remaining items.
-        for (int k = limit - limit_by_8 * 8; k > 0; --k, ++h_p, ++x_p) {
-          *h_p += alpha * *x_p;
+        for (int k = limit - limit_by_8 * 8; k > 0; --k, ++h_p2, ++x_p) {
+          *h_p2 += alpha * *x_p;
         }
 
         x_p = &x[0];
diff --git a/modules/audio_processing/ns/noise_estimator.cc b/modules/audio_processing/ns/noise_estimator.cc
index 5367545..214db52 100644
--- a/modules/audio_processing/ns/noise_estimator.cc
+++ b/modules/audio_processing/ns/noise_estimator.cc
@@ -11,8 +11,14 @@
 #include "modules/audio_processing/ns/noise_estimator.h"
 
 #include <algorithm>
+#include <array>
+#include <cstddef>
+#include <cstdint>
 
+#include "api/array_view.h"
 #include "modules/audio_processing/ns/fast_math.h"
+#include "modules/audio_processing/ns/ns_common.h"
+#include "modules/audio_processing/ns/suppression_params.h"
 #include "rtc_base/checks.h"
 
 namespace webrtc {
@@ -129,9 +135,9 @@
       } else {
         // Use pink noise estimate.
         float use_band = i < kStartBand ? kStartBand : i;
-        float denom = PowApproximation(use_band, parametric_exp);
-        RTC_DCHECK_NE(denom, 0.f);
-        parametric_noise_spectrum_[i] = parametric_num / denom;
+        float parametric_denom = PowApproximation(use_band, parametric_exp);
+        RTC_DCHECK_NE(parametric_denom, 0.f);
+        parametric_noise_spectrum_[i] = parametric_num / parametric_denom;
       }
     }
 
diff --git a/modules/audio_processing/residual_echo_detector.cc b/modules/audio_processing/residual_echo_detector.cc
index 06ac149..0dbbc72 100644
--- a/modules/audio_processing/residual_echo_detector.cc
+++ b/modules/audio_processing/residual_echo_detector.cc
@@ -11,9 +11,13 @@
 #include "modules/audio_processing/residual_echo_detector.h"
 
 #include <algorithm>
+#include <atomic>
+#include <cstddef>
 #include <numeric>
 #include <optional>
 
+#include "api/array_view.h"
+#include "api/audio/audio_processing.h"
 #include "modules/audio_processing/logging/apm_data_dumper.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/logging.h"
@@ -135,25 +139,25 @@
   if (echo_likelihood_ > 1.1f) {
     // Make sure we don't spam the log.
     if (log_counter_ < 5 && best_delay != -1) {
-      size_t read_index = kLookbackFrames + next_insertion_index_ - best_delay;
-      if (read_index >= kLookbackFrames) {
-        read_index -= kLookbackFrames;
+      size_t read_index_high_echo =
+          kLookbackFrames + next_insertion_index_ - best_delay;
+      if (read_index_high_echo >= kLookbackFrames) {
+        read_index_high_echo -= kLookbackFrames;
       }
-      RTC_DCHECK_LT(read_index, render_power_.size());
-      RTC_LOG_F(LS_ERROR) << "Echo detector internal state: {"
-                             "Echo likelihood: "
-                          << echo_likelihood_ << ", Best Delay: " << best_delay
-                          << ", Covariance: "
-                          << covariances_[best_delay].covariance()
-                          << ", Last capture power: " << capture_power
-                          << ", Capture mean: " << capture_mean
-                          << ", Capture_standard deviation: "
-                          << capture_std_deviation << ", Last render power: "
-                          << render_power_[read_index]
-                          << ", Render mean: " << render_power_mean_[read_index]
-                          << ", Render standard deviation: "
-                          << render_power_std_dev_[read_index]
-                          << ", Reliability: " << reliability_ << "}";
+      RTC_DCHECK_LT(read_index_high_echo, render_power_.size());
+      RTC_LOG_F(LS_ERROR)
+          << "Echo detector internal state: {"
+             "Echo likelihood: "
+          << echo_likelihood_ << ", Best Delay: " << best_delay
+          << ", Covariance: " << covariances_[best_delay].covariance()
+          << ", Last capture power: " << capture_power
+          << ", Capture mean: " << capture_mean
+          << ", Capture_standard deviation: " << capture_std_deviation
+          << ", Last render power: " << render_power_[read_index_high_echo]
+          << ", Render mean: " << render_power_mean_[read_index_high_echo]
+          << ", Render standard deviation: "
+          << render_power_std_dev_[read_index_high_echo]
+          << ", Reliability: " << reliability_ << "}";
       log_counter_++;
     }
   }
diff --git a/modules/audio_processing/test/aec_dump_based_simulator.cc b/modules/audio_processing/test/aec_dump_based_simulator.cc
index 5b4bc49..d972af6 100644
--- a/modules/audio_processing/test/aec_dump_based_simulator.cc
+++ b/modules/audio_processing/test/aec_dump_based_simulator.cc
@@ -19,6 +19,7 @@
 #include <iostream>
 #include <memory>
 #include <optional>
+#include <sstream>  // no-presubmit-check TODO(webrtc:8982)
 #include <string>
 #include <utility>
 
@@ -50,7 +51,7 @@
     return false;
   } else {
     const int16_t* frame_data = frame.data.data();
-    for (int k = 0; k < frame.num_channels * frame.samples_per_channel; ++k) {
+    for (int k = 0; k < frame.num_channels_ * frame.samples_per_channel_; ++k) {
       if (msg.output_data().data()[k] != frame_data[k]) {
         return false;
       }
diff --git a/modules/audio_processing/test/audio_processing_simulator.h b/modules/audio_processing/test/audio_processing_simulator.h
index 42279dd..8b6f95c 100644
--- a/modules/audio_processing/test/audio_processing_simulator.h
+++ b/modules/audio_processing/test/audio_processing_simulator.h
@@ -40,41 +40,41 @@
 
 struct Int16Frame {
   void SetFormat(int sample_rate_hz, int num_channels) {
-    this->sample_rate_hz = sample_rate_hz;
-    samples_per_channel =
+    sample_rate_hz_ = sample_rate_hz;
+    samples_per_channel_ =
         rtc::CheckedDivExact(sample_rate_hz, kChunksPerSecond);
-    this->num_channels = num_channels;
+    num_channels_ = num_channels;
     config = StreamConfig(sample_rate_hz, num_channels);
-    data.resize(num_channels * samples_per_channel);
+    data.resize(num_channels * samples_per_channel_);
   }
 
   void CopyTo(ChannelBuffer<float>* dest) {
     RTC_DCHECK(dest);
-    RTC_CHECK_EQ(num_channels, dest->num_channels());
-    RTC_CHECK_EQ(samples_per_channel, dest->num_frames());
+    RTC_CHECK_EQ(num_channels_, dest->num_channels());
+    RTC_CHECK_EQ(samples_per_channel_, dest->num_frames());
     // Copy the data from the input buffer.
-    std::vector<float> tmp(samples_per_channel * num_channels);
+    std::vector<float> tmp(samples_per_channel_ * num_channels_);
     S16ToFloat(data.data(), tmp.size(), tmp.data());
-    Deinterleave(tmp.data(), samples_per_channel, num_channels,
+    Deinterleave(tmp.data(), samples_per_channel_, num_channels_,
                  dest->channels());
   }
 
   void CopyFrom(const ChannelBuffer<float>& src) {
-    RTC_CHECK_EQ(src.num_channels(), num_channels);
-    RTC_CHECK_EQ(src.num_frames(), samples_per_channel);
-    data.resize(num_channels * samples_per_channel);
+    RTC_CHECK_EQ(src.num_channels(), num_channels_);
+    RTC_CHECK_EQ(src.num_frames(), samples_per_channel_);
+    data.resize(num_channels_ * samples_per_channel_);
     int16_t* dest_data = data.data();
-    for (int ch = 0; ch < num_channels; ++ch) {
-      for (int sample = 0; sample < samples_per_channel; ++sample) {
-        dest_data[sample * num_channels + ch] =
+    for (int ch = 0; ch < num_channels_; ++ch) {
+      for (int sample = 0; sample < samples_per_channel_; ++sample) {
+        dest_data[sample * num_channels_ + ch] =
             src.channels()[ch][sample] * 32767;
       }
     }
   }
 
-  int sample_rate_hz;
-  int samples_per_channel;
-  int num_channels;
+  int sample_rate_hz_;
+  int samples_per_channel_;
+  int num_channels_;
 
   StreamConfig config;