Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(712)

Unified Diff: webrtc/modules/audio_processing/beamformer/array_util_unittest.cc

Issue 1394103003: Make the nonlinear beamformer steerable (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@highfreq
Patch Set: Formatting Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/beamformer/array_util_unittest.cc
diff --git a/webrtc/modules/audio_processing/beamformer/array_util_unittest.cc b/webrtc/modules/audio_processing/beamformer/array_util_unittest.cc
index 57f17082252eedc82584eed7c593103ad9cd7bcd..ee57b45d384d9c3ac6eb8a3ad850fa75df2177c3 100644
--- a/webrtc/modules/audio_processing/beamformer/array_util_unittest.cc
+++ b/webrtc/modules/audio_processing/beamformer/array_util_unittest.cc
@@ -15,6 +15,70 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace webrtc {
+namespace {
+
+void ExpectPointsEq(const Point& a, const Point& b) {
Andrew MacDonald 2015/10/28 01:57:57 You should be able to overload operator== for Poin
aluebs-webrtc 2015/10/29 00:34:21 I Added the operator here, since the one in Chromi
Andrew MacDonald 2015/10/29 01:52:32 Acknowledged.
+ EXPECT_FLOAT_EQ(a.x(), b.x());
+ EXPECT_FLOAT_EQ(a.y(), b.y());
+ EXPECT_FLOAT_EQ(a.z(), b.z());
+}
+
+} // namespace
+
+TEST(ArrayUtilTest, PairDirection) {
+ ExpectPointsEq(Point(1.f, 2.f, 3.f),
+ PairDirection(Point(0.f, 0.f, 0.f), Point(1.f, 2.f, 3.f)));
+ ExpectPointsEq(Point(-1.f, -2.f, -3.f),
+ PairDirection(Point(1.f, 2.f, 3.f), Point(0.f, 0.f, 0.f)));
+ ExpectPointsEq(Point(0.f, 0.f, 0.f),
+ PairDirection(Point(1.f, 0.f, 0.f), Point(1.f, 0.f, 0.f)));
+ ExpectPointsEq(Point(-1.f, 2.f, 0.f),
+ PairDirection(Point(1.f, 0.f, 0.f), Point(0.f, 2.f, 0.f)));
+ ExpectPointsEq(Point(-4.f, 4.f, -4.f),
+ PairDirection(Point(1.f, -2.f, 3.f), Point(-3.f, 2.f, -1.f)));
+}
+
+TEST(ArrayUtilTest, DotProduct) {
+ EXPECT_FLOAT_EQ(0.f, DotProduct(Point(0.f, 0.f, 0.f), Point(1.f, 2.f, 3.f)));
+ EXPECT_FLOAT_EQ(0.f, DotProduct(Point(1.f, 0.f, 2.f), Point(0.f, 3.f, 0.f)));
+ EXPECT_FLOAT_EQ(0.f, DotProduct(Point(1.f, 1.f, 0.f), Point(1.f, -1.f, 0.f)));
+ EXPECT_FLOAT_EQ(2.f, DotProduct(Point(1.f, 0.f, 0.f), Point(2.f, 0.f, 0.f)));
+ EXPECT_FLOAT_EQ(-6.f,
+ DotProduct(Point(-2.f, 0.f, 0.f), Point(3.f, 0.f, 0.f)));
+ EXPECT_FLOAT_EQ(-10.f,
+ DotProduct(Point(1.f, -2.f, 3.f), Point(-3.f, 2.f, -1.f)));
+}
+
+TEST(ArrayUtilTest, CrossProduct) {
+ ExpectPointsEq(Point(0.f, 0.f, 0.f),
+ CrossProduct(Point(0.f, 0.f, 0.f), Point(1.f, 2.f, 3.f)));
+ ExpectPointsEq(Point(0.f, 0.f, 1.f),
+ CrossProduct(Point(1.f, 0.f, 0.f), Point(0.f, 1.f, 0.f)));
+ ExpectPointsEq(Point(1.f, 0.f, 0.f),
+ CrossProduct(Point(0.f, 1.f, 0.f), Point(0.f, 0.f, 1.f)));
+ ExpectPointsEq(Point(0.f, -1.f, 0.f),
+ CrossProduct(Point(1.f, 0.f, 0.f), Point(0.f, 0.f, 1.f)));
+ ExpectPointsEq(Point(-4.f, -8.f, -4.f),
+ CrossProduct(Point(1.f, -2.f, 3.f), Point(-3.f, 2.f, -1.f)));
+}
+
+TEST(ArrayUtilTest, AreParallel) {
+ EXPECT_TRUE(AreParallel(Point(0.f, 0.f, 0.f), Point(1.f, 2.f, 3.f)));
+ EXPECT_FALSE(AreParallel(Point(1.f, 0.f, 2.f), Point(0.f, 3.f, 0.f)));
+ EXPECT_FALSE(AreParallel(Point(1.f, 2.f, 0.f), Point(1.f, -0.5f, 0.f)));
+ EXPECT_FALSE(AreParallel(Point(1.f, -2.f, 3.f), Point(-3.f, 2.f, -1.f)));
+ EXPECT_TRUE(AreParallel(Point(1.f, 0.f, 0.f), Point(2.f, 0.f, 0.f)));
+ EXPECT_TRUE(AreParallel(Point(1.f, 2.f, 3.f), Point(-2.f, -4.f, -6.f)));
+}
+
+TEST(ArrayUtilTest, ArePerpendicular) {
+ EXPECT_TRUE(ArePerpendicular(Point(0.f, 0.f, 0.f), Point(1.f, 2.f, 3.f)));
+ EXPECT_TRUE(ArePerpendicular(Point(1.f, 0.f, 2.f), Point(0.f, 3.f, 0.f)));
+ EXPECT_TRUE(ArePerpendicular(Point(1.f, 2.f, 0.f), Point(1.f, -0.5f, 0.f)));
+ EXPECT_FALSE(ArePerpendicular(Point(1.f, -2.f, 3.f), Point(-3.f, 2.f, -1.f)));
+ EXPECT_FALSE(ArePerpendicular(Point(1.f, 0.f, 0.f), Point(2.f, 0.f, 0.f)));
+ EXPECT_FALSE(ArePerpendicular(Point(1.f, 2.f, 3.f), Point(-2.f, -4.f, -6.f)));
+}
TEST(ArrayUtilTest, GetMinimumSpacing) {
std::vector<Point> array_geometry;
@@ -29,4 +93,93 @@ TEST(ArrayUtilTest, GetMinimumSpacing) {
EXPECT_FLOAT_EQ(0.005f, GetMinimumSpacing(array_geometry));
}
+TEST(ArrayUtilTest, IsGeometryLinear) {
+ std::vector<Point> array_geometry;
Andrew MacDonald 2015/10/28 01:57:57 Just geometry or points is fine to save some chara
aluebs-webrtc 2015/10/29 00:34:21 Done.
+ array_geometry.push_back(Point(0.f, 0.f, 0.f));
+ array_geometry.push_back(Point(0.1f, 0.f, 0.f));
+ EXPECT_TRUE(
+ AreParallel(Point(1.f, 0.f, 0.f), IsGeometryLinear(array_geometry)));
+ array_geometry.push_back(Point(0.15f, 0.f, 0.f));
+ EXPECT_TRUE(
+ AreParallel(Point(1.f, 0.f, 0.f), IsGeometryLinear(array_geometry)));
+ array_geometry.push_back(Point(-0.2f, 0.f, 0.f));
+ EXPECT_TRUE(
+ AreParallel(Point(1.f, 0.f, 0.f), IsGeometryLinear(array_geometry)));
+ array_geometry.push_back(Point(0.05f, 0.f, 0.f));
+ EXPECT_TRUE(
+ AreParallel(Point(1.f, 0.f, 0.f), IsGeometryLinear(array_geometry)));
+ array_geometry.push_back(Point(0.1f, 0.1f, 0.f));
+ ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryLinear(array_geometry));
+ array_geometry.push_back(Point(0.f, 0.f, -0.2f));
+ ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryLinear(array_geometry));
+}
+
+TEST(ArrayUtilTest, IsGeometryPlanar) {
+ std::vector<Point> array_geometry;
+ array_geometry.push_back(Point(0.f, 0.f, 0.f));
+ array_geometry.push_back(Point(0.1f, 0.f, 0.f));
+ ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryPlanar(array_geometry));
+ array_geometry.push_back(Point(0.15f, 0.f, 0.f));
+ ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryPlanar(array_geometry));
+ array_geometry.push_back(Point(0.1f, 0.2f, 0.f));
+ EXPECT_TRUE(
+ AreParallel(Point(0.f, 0.f, 1.f), IsGeometryPlanar(array_geometry)));
+ array_geometry.push_back(Point(0.f, -0.15f, 0.f));
+ EXPECT_TRUE(
+ AreParallel(Point(0.f, 0.f, 1.f), IsGeometryPlanar(array_geometry)));
+ array_geometry.push_back(Point(0.f, 0.1f, 0.2f));
+ ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryPlanar(array_geometry));
+ array_geometry.push_back(Point(0.f, 0.f, -0.15f));
+ ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryPlanar(array_geometry));
+ array_geometry.push_back(Point(0.1f, 0.2f, 0.f));
+ ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryPlanar(array_geometry));
+}
+
+TEST(ArrayUtilTest, GetArrayNormal) {
+ std::vector<Point> array_geometry;
+ array_geometry.push_back(Point(0.f, 0.f, 0.f));
+ array_geometry.push_back(Point(0.1f, 0.f, 0.f));
+ EXPECT_TRUE(
+ AreParallel(Point(0.f, 1.f, 0.f), GetArrayNormal(array_geometry)));
+ array_geometry.push_back(Point(0.15f, 0.f, 0.f));
+ EXPECT_TRUE(
+ AreParallel(Point(0.f, 1.f, 0.f), GetArrayNormal(array_geometry)));
+ array_geometry.push_back(Point(0.1f, 0.f, 0.2f));
+ EXPECT_TRUE(
+ AreParallel(Point(0.f, 1.f, 0.f), GetArrayNormal(array_geometry)));
+ array_geometry.push_back(Point(0.f, 0.f, -0.1f));
+ EXPECT_TRUE(
+ AreParallel(Point(0.f, 1.f, 0.f), GetArrayNormal(array_geometry)));
+ array_geometry.push_back(Point(0.1f, 0.2f, 0.3f));
+ ExpectPointsEq(Point(0.f, 0.f, 0.f), GetArrayNormal(array_geometry));
+ array_geometry.push_back(Point(0.f, -0.1f, 0.f));
+ ExpectPointsEq(Point(0.f, 0.f, 0.f), GetArrayNormal(array_geometry));
+ array_geometry.push_back(Point(1.f, 0.f, -0.2f));
+ ExpectPointsEq(Point(0.f, 0.f, 0.f), GetArrayNormal(array_geometry));
+}
+
+TEST(ArrayUtilTest, DegreesToRadians) {
+ EXPECT_FLOAT_EQ(0.f, DegreesToRadians(0.f));
+ EXPECT_FLOAT_EQ(M_PI / 6.f, DegreesToRadians(30.f));
+ EXPECT_FLOAT_EQ(-M_PI / 4.f, DegreesToRadians(-45.f));
+ EXPECT_FLOAT_EQ(M_PI / 3.f, DegreesToRadians(60.f));
+ EXPECT_FLOAT_EQ(-M_PI / 2.f, DegreesToRadians(-90.f));
+ EXPECT_FLOAT_EQ(2.f * M_PI / 3.f, DegreesToRadians(120.f));
+ EXPECT_FLOAT_EQ(-3.f * M_PI / 4.f, DegreesToRadians(-135.f));
+ EXPECT_FLOAT_EQ(5.f * M_PI / 6.f, DegreesToRadians(150.f));
+ EXPECT_FLOAT_EQ(-M_PI, DegreesToRadians(-180.f));
+}
+
+TEST(ArrayUtilTest, RadiansToDegrees) {
+ EXPECT_FLOAT_EQ(0.f, RadiansToDegrees(0.f));
+ EXPECT_FLOAT_EQ(30.f, RadiansToDegrees(M_PI / 6.f));
+ EXPECT_FLOAT_EQ(-45.f, RadiansToDegrees(-M_PI / 4.f));
+ EXPECT_FLOAT_EQ(60.f, RadiansToDegrees(M_PI / 3.f));
+ EXPECT_FLOAT_EQ(-90.f, RadiansToDegrees(-M_PI / 2.f));
+ EXPECT_FLOAT_EQ(120.f, RadiansToDegrees(2.f * M_PI / 3.f));
+ EXPECT_FLOAT_EQ(-135.f, RadiansToDegrees(-3.f * M_PI / 4.f));
+ EXPECT_FLOAT_EQ(150.f, RadiansToDegrees(5.f * M_PI / 6.f));
+ EXPECT_FLOAT_EQ(-180.f, RadiansToDegrees(-M_PI));
+}
+
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698