Make the high frequency correction range depend on the target angle

Depends on this CL: https://codereview.webrtc.org/1388033002/

Review URL: https://codereview.webrtc.org/1395453004

Cr-Commit-Position: refs/heads/master@{#10331}
diff --git a/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.cc b/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.cc
index 20e6b55..d3f9b33 100644
--- a/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.cc
+++ b/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.cc
@@ -61,11 +61,6 @@
 const int kLowMeanStartHz = 200;
 const int kLowMeanEndHz = 400;
 
-// TODO(aluebs): Make the high frequency correction range depend on the target
-// angle.
-const int kHighMeanStartHz = 3000;
-const int kHighMeanEndHz = 5000;
-
 // Range limiter for subtractive terms in the nominator and denominator of the
 // postfilter expression. It handles the scenario mismatch between the true and
 // model sources (target and interference).
@@ -207,25 +202,7 @@
   chunk_length_ =
       static_cast<size_t>(sample_rate_hz / (1000.f / chunk_size_ms));
   sample_rate_hz_ = sample_rate_hz;
-  low_mean_start_bin_ = Round(kLowMeanStartHz * kFftSize / sample_rate_hz_);
-  low_mean_end_bin_ = Round(kLowMeanEndHz * kFftSize / sample_rate_hz_);
-  high_mean_start_bin_ = Round(kHighMeanStartHz * kFftSize / sample_rate_hz_);
-  high_mean_end_bin_ = Round(kHighMeanEndHz * kFftSize / sample_rate_hz_);
-  // These bin indexes determine the regions over which a mean is taken. This
-  // is applied as a constant value over the adjacent end "frequency correction"
-  // regions.
-  //
-  //             low_mean_start_bin_     high_mean_start_bin_
-  //                   v                         v              constant
-  // |----------------|--------|----------------|-------|----------------|
-  //   constant               ^                        ^
-  //             low_mean_end_bin_       high_mean_end_bin_
-  //
-  RTC_DCHECK_GT(low_mean_start_bin_, 0U);
-  RTC_DCHECK_LT(low_mean_start_bin_, low_mean_end_bin_);
-  RTC_DCHECK_LT(low_mean_end_bin_, high_mean_end_bin_);
-  RTC_DCHECK_LT(high_mean_start_bin_, high_mean_end_bin_);
-  RTC_DCHECK_LT(high_mean_end_bin_, kNumFreqBins - 1);
+  InitFrequencyCorrectionRanges();
 
   high_pass_postfilter_mask_ = 1.f;
   is_target_present_ = false;
@@ -261,6 +238,37 @@
   }
 }
 
+void NonlinearBeamformer::InitFrequencyCorrectionRanges() {
+  const float kAliasingFreqHz =
+      kSpeedOfSoundMeterSeconds /
+      (min_mic_spacing_ * (1.f + std::abs(std::cos(kTargetAngleRadians))));
+  const float kHighMeanStartHz = std::min(0.5f *  kAliasingFreqHz,
+                                          sample_rate_hz_ / 2.f);
+  const float kHighMeanEndHz = std::min(0.75f *  kAliasingFreqHz,
+                                        sample_rate_hz_ / 2.f);
+
+  low_mean_start_bin_ = Round(kLowMeanStartHz * kFftSize / sample_rate_hz_);
+  low_mean_end_bin_ = Round(kLowMeanEndHz * kFftSize / sample_rate_hz_);
+  high_mean_start_bin_ = Round(kHighMeanStartHz * kFftSize / sample_rate_hz_);
+  high_mean_end_bin_ = Round(kHighMeanEndHz * kFftSize / sample_rate_hz_);
+  // These bin indexes determine the regions over which a mean is taken. This
+  // is applied as a constant value over the adjacent end "frequency correction"
+  // regions.
+  //
+  //             low_mean_start_bin_     high_mean_start_bin_
+  //                   v                         v              constant
+  // |----------------|--------|----------------|-------|----------------|
+  //   constant               ^                        ^
+  //             low_mean_end_bin_       high_mean_end_bin_
+  //
+  RTC_DCHECK_GT(low_mean_start_bin_, 0U);
+  RTC_DCHECK_LT(low_mean_start_bin_, low_mean_end_bin_);
+  RTC_DCHECK_LT(low_mean_end_bin_, high_mean_end_bin_);
+  RTC_DCHECK_LT(high_mean_start_bin_, high_mean_end_bin_);
+  RTC_DCHECK_LT(high_mean_end_bin_, kNumFreqBins - 1);
+}
+
+
 void NonlinearBeamformer::InitInterfAngles() {
   const float kAwayRadians =
       std::min(static_cast<float>(M_PI),
diff --git a/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h b/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h
index d24bbb6..4c79c01 100644
--- a/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h
+++ b/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h
@@ -66,6 +66,7 @@
   typedef ComplexMatrix<float> ComplexMatrixF;
   typedef complex<float> complex_f;
 
+  void InitFrequencyCorrectionRanges();
   void InitInterfAngles();
   void InitDelaySumMasks();
   void InitTargetCovMats();