Index: webrtc/modules/audio_processing/beamformer/nonlinear_beamformer_unittest.cc |
diff --git a/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer_unittest.cc b/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..aeee60ada03caa1ef68e78bb84ccab61a2c36e79 |
--- /dev/null |
+++ b/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer_unittest.cc |
@@ -0,0 +1,58 @@ |
+/* |
+ * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace webrtc { |
+namespace { |
+ |
+SphericalPointf Azimuth2Point(float azimuth_radians) { |
Andrew MacDonald
2015/10/20 03:00:08
nit: AzimuthToPoint (just because I think that's m
aluebs-webrtc
2015/10/21 01:41:40
Done.
|
+ return SphericalPointf(azimuth_radians, 0.f, 1.f); |
+} |
+ |
+void Verify(NonlinearBeamformer* bf, float target_azimuth_radians) { |
+ const float kHalfBeamWidthRadians = static_cast<float>(M_PI) * 20.f / 180.f; |
Andrew MacDonald
2015/10/20 03:00:08
If you want to use this (and I think that's fine),
aluebs-webrtc
2015/10/21 01:41:40
The problem is that in WebRTC I can't use constexp
Andrew MacDonald
2015/10/21 02:10:32
You can do it with:
.h
class NonlinearBeaformer {
Andrew MacDonald
2015/10/21 02:11:31
oops, just "const float" of course.
aluebs-webrtc
2015/10/27 18:08:15
Done.
|
+ EXPECT_TRUE(bf->IsInBeam(Azimuth2Point(target_azimuth_radians))); |
+ EXPECT_TRUE(bf->IsInBeam( |
+ Azimuth2Point(target_azimuth_radians - kHalfBeamWidthRadians + 0.001f))); |
+ EXPECT_TRUE(bf->IsInBeam( |
+ Azimuth2Point(target_azimuth_radians + kHalfBeamWidthRadians - 0.001f))); |
+ EXPECT_FALSE(bf->IsInBeam( |
+ Azimuth2Point(target_azimuth_radians - kHalfBeamWidthRadians - 0.001f))); |
+ EXPECT_FALSE(bf->IsInBeam( |
+ Azimuth2Point(target_azimuth_radians + kHalfBeamWidthRadians + 0.001f))); |
+} |
+ |
+void AimAndVerify(NonlinearBeamformer* bf, float target_azimuth_radians) { |
+ bf->AimAt(Azimuth2Point(target_azimuth_radians)); |
+ Verify(bf, target_azimuth_radians); |
+} |
+ |
+} // namespace |
+ |
+TEST(NonlinearBeamformerTest, AimingModifiesBeam) { |
+ const int kChunkSizeMs = 10; |
+ const int kSampleRateHz = 16000; |
+ std::vector<Point> array_geometry; |
+ array_geometry.push_back(Point(-0.025f, 0.f, 0.f)); |
+ array_geometry.push_back(Point(0.025f, 0.f, 0.f)); |
+ NonlinearBeamformer bf(array_geometry); |
+ bf.Initialize(kChunkSizeMs, kSampleRateHz); |
+ // The default constructor parameter sets the target angle to PI / 2. |
+ Verify(&bf, M_PI / 2.f); |
+ AimAndVerify(&bf, M_PI / 3.f); |
+ AimAndVerify(&bf, 3.f * M_PI / 4.f); |
+ AimAndVerify(&bf, M_PI / 6.f); |
+ AimAndVerify(&bf, M_PI); |
+} |
+ |
+} // namespace webrtc |