libalaudio  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
alacousticalmodel_test.cpp
Go to the documentation of this file.
1 
6 #include "gtest/gtest.h"
7 #include "alaudio/alacousticalmodel.h"
8 
9 #include <almath/alrandom.h>
10 #include <alvalue/alvalue.h>
11 using boost::shared_ptr;
12 
13 TEST(forwardITD, Init) {
14 
18  boost::shared_ptr<ALAcousticalModel> model = ALAcousticalModel::getInstance();
19 
21  std::vector<int> pITDValues;
22  std::vector<float> tmp;
23  float titi;
24 
25  pITDValues.push_back(0); pITDValues.push_back(0);
26  pITDValues.push_back(0); pITDValues.push_back(0);
27  pITDValues.push_back(0); pITDValues.push_back(0);
28  tmp = model->forwardITD(pITDValues,titi);
29  if( (tmp[0]-0.0f) > 0.001f
30  || (tmp[1]-0.0f) > 0.001f
31  || (titi-0.0f) > 0.001f) {
32  std::cout << " test 1 " << std::endl;
33  EXPECT_EQ(0, 4);
34  }
35 
36  tmp.clear();
37  pITDValues[0] = 1; pITDValues[3] = 0;
38  pITDValues[1] = 0; pITDValues[4] = 0;
39  pITDValues[2] = 0; pITDValues[5] = 1;
40  tmp = model->forwardITD(pITDValues,titi);
41  if( (tmp[0]-0.0f) > 0.001f
42  || (tmp[1]-0.0f) > 0.001f
43  || (titi-0.218264f) > 0.001f) {
44  std::cout << " test 2 : failed" << std::endl;
45  EXPECT_EQ(1, 4);
46  }
47 
48  pITDValues[0] = -6; pITDValues[3] = 0;
49  pITDValues[1] = -6; pITDValues[4] = 2;
50  pITDValues[2] = -2; pITDValues[5] = 5;
51  tmp = model->forwardITD(pITDValues,titi);
52  if( (tmp[0]-(-0.354632f)) > 0.001f
53  || (tmp[1]-0.444303f) > 0.001f
54  || (titi - 0.813129f) > 0.001f) {
55  std::cout << " test 3 : failed" << std::endl;
56  EXPECT_EQ(2, 4);
57  }
58 
59  pITDValues[0] = 10; pITDValues[3] = 11;
60  pITDValues[1] = -7; pITDValues[4] = 14;
61  pITDValues[2] = 8; pITDValues[5] = 12;
62  tmp = model->forwardITD(pITDValues,titi);
63 
64  if( (tmp[0]-0.068907f) > 0.001f
65  || (tmp[1]-0.971899f) > 0.001f
66  || (titi-0.344555f) > 0.001f) {
67  std::cout << " test 4 : failed" << std::endl;
68  EXPECT_EQ(3, 4);
69  }
70  EXPECT_EQ(4, 4);
71 }
72 
73 TEST(getITDtest, Init) {
74  boost::shared_ptr<ALAcousticalModel> model = ALAcousticalModel::getInstance();
75  int a = 0;
76  model->getITDmaxLR(a);
77  EXPECT_EQ(a, 21) << "error : getITDmaxLR";
78 
79  int b = 0;
80  model->getITDmaxFR(b);
81  EXPECT_EQ(b, 14)<< "error : getITDmaxFR";
82 
83  std::vector<int> to;
84  model->getITDmaxV6(to);
85  EXPECT_EQ(to[0], 25 ) << "error : getITDmaxV6 [0]";
86  EXPECT_EQ(to[1], 20 ) << "error : getITDmaxV6 [1]";
87  EXPECT_EQ(to[2], 20 ) << "error : getITDmaxV6 [2]";
88  EXPECT_EQ(to[3], 20 ) << "error : getITDmaxV6 [3]";
89  EXPECT_EQ(to[4], 20 ) << "error : getITDmaxV6 [4]";
90  EXPECT_EQ(to[5], 25 ) << "error : getITDmaxV6 [5]";
91  EXPECT_EQ(4, 4);
92 }
93 
94 TEST(computeAngleTest, Init) {
95  boost::shared_ptr<ALAcousticalModel> model = ALAcousticalModel::getInstance();
96  std::vector<float> to;
97  std::vector<int> itd;
98  itd.push_back(10);
99  to = model->computeAngle(itd, "az");
100  if(( to[0] - 0.577957) > 0.00001 )
101  EXPECT_EQ(to[0], 10.0f ) << "error : computeAngle";
102 }
103 
104 TEST(getValues, Init) {
105  boost::shared_ptr<ALAcousticalModel> model = ALAcousticalModel::getInstance();
106  float to = 0.0f;
107 
108  model->getSampleRate(to);
109  EXPECT_EQ(to, 48000.0f ) << "error : getSampleRate";
110 
111  model->getSoundSpeed(to);
112  EXPECT_EQ(to, 342.0f ) << "error : getSoundSpeed";
113 
114  std::vector<AL::Math::Position3D> micpos;
115  model->getMicrosPosition(micpos);
116  if( fabsf( micpos[0].x - (-0.005575f) ) > 0.0001f ) EXPECT_EQ(micpos[0].x, -0.005575f) << "error : getMicrosPosition 0 x";
117  if( fabsf( micpos[0].y - (-0.0606f) ) > 0.0001f ) EXPECT_EQ(micpos[0].y, -0.0606f ) << "error : getMicrosPosition 0 y";
118  if( fabsf( micpos[0].z - (-0.02365f) ) > 0.0001f ) EXPECT_EQ(micpos[0].z, -0.0606f ) << "error : getMicrosPosition 0 z";
119 
120  if( fabsf( micpos[1].x - (-0.005575f) ) > 0.0001f ) EXPECT_EQ(micpos[1].x, -0.005575f) << "error : getMicrosPosition 1 x";
121  if( fabsf( micpos[1].y - ( 0.0606f) ) > 0.0001f ) EXPECT_EQ(micpos[1].y, 0.0606f ) << "error : getMicrosPosition 1 y";
122  if( fabsf( micpos[1].z - (-0.02365f) ) > 0.0001f ) EXPECT_EQ(micpos[1].z, 0.0606f ) << "error : getMicrosPosition 1 z";
123 
124  if( fabsf( micpos[2].x - ( 0.054925f) ) > 0.0001f ) EXPECT_EQ(micpos[2].x, 0.054925f) << "error : getMicrosPosition 2 x";
125  if( fabsf( micpos[2].y - ( 0.0f) ) > 0.0001f ) EXPECT_EQ(micpos[2].y, 0.0f ) << "error : getMicrosPosition 2 y";
126  if( fabsf( micpos[2].z - ( 0.03475f) ) > 0.0001f ) EXPECT_EQ(micpos[2].z, 0.0f ) << "error : getMicrosPosition 2 z";
127 
128  if( fabsf( micpos[3].x - (-0.043775f) ) > 0.0001f ) EXPECT_EQ(micpos[3].x, -0.043775f) << "error : getMicrosPosition 3 x";
129  if( fabsf( micpos[3].y - ( 0.0f) ) > 0.0001f ) EXPECT_EQ(micpos[3].y, 0.0f ) << "error : getMicrosPosition 3 y";
130  if( fabsf( micpos[3].z - ( 0.01255f) ) > 0.0001f ) EXPECT_EQ(micpos[3].z, 0.0f ) << "error : getMicrosPosition 3 z";
131 }
132 
133 TEST(forwardUpdate, Init) {
134  boost::shared_ptr<ALAcousticalModel> model = ALAcousticalModel::getInstance();
135  std::vector<float> ITDValues;
136  std::vector<float> pITDValues;
137  pITDValues.push_back(10.0f); pITDValues.push_back(-7.0f);
138  pITDValues.push_back(8.0f); pITDValues.push_back(11.0f);
139  pITDValues.push_back(14.0f); pITDValues.push_back(12.0f);
140 
141  float toto;
142  toto = model->forwardITDUpdateValues(pITDValues, ITDValues);
143  if( fabsf( toto - (0.253429f)) > 0.0001f ) EXPECT_EQ(toto , (0.253429f)) << "error : return forwardITDUpdateValues";
144  if( fabsf( ITDValues[0] - (-4.66667f)) > 0.0001f ) EXPECT_EQ(ITDValues[0] , (-4.66667f)) << "error : forwardITDUpdateValues 0";
145  if( fabsf( ITDValues[1] - (-6.0f) ) > 0.0001f ) EXPECT_EQ(ITDValues[1] , (-6.0f) ) << "error : forwardITDUpdateValues 1";
146  if( fabsf( ITDValues[2] - ( 7.0f) ) > 0.0001f ) EXPECT_EQ(ITDValues[2] , ( 7.0f) ) << "error : forwardITDUpdateValues 2";
147  if( fabsf( ITDValues[3] - (-1.33333f)) > 0.0001f ) EXPECT_EQ(ITDValues[3] , (-1.33333f)) << "error : forwardITDUpdateValues 3";
148  if( fabsf( ITDValues[4] - (11.6667f)) > 0.0001f ) EXPECT_EQ(ITDValues[4] , (11.6667f) ) << "error : forwardITDUpdateValues 4";
149  if( fabsf( ITDValues[5] - (13.0f) ) > 0.0001f ) EXPECT_EQ(ITDValues[5] , (13.0f) ) << "error : forwardITDUpdateValues 5";
150 }
TEST(forwardITD, Init)