libalaudio  2.0.6.8
/home/opennao/work/master/sdk/libnaoqi/libalaudio/tests/alacousticalmodel_test.cpp
Go to the documentation of this file.
00001 
00006 #include "gtest/gtest.h"
00007 #include "alaudio/alacousticalmodel.h"
00008 
00009 #include <almath/alrandom.h>
00010 #include <alvalue/alvalue.h>
00011 using boost::shared_ptr;
00012 
00013 TEST(forwardITD, Init) {
00014 
00018   boost::shared_ptr<ALAcousticalModel> model = ALAcousticalModel::getInstance();
00019 
00021   std::vector<int> pITDValues;
00022   std::vector<float> tmp;
00023   float titi;
00024 
00025   pITDValues.push_back(0);  pITDValues.push_back(0);
00026   pITDValues.push_back(0);  pITDValues.push_back(0);
00027   pITDValues.push_back(0);  pITDValues.push_back(0);
00028   tmp = model->forwardITD(pITDValues,titi);
00029   if(  (tmp[0]-0.0f)  > 0.001f
00030     || (tmp[1]-0.0f)  > 0.001f
00031     || (titi-0.0f)    > 0.001f) {
00032     std::cout << " test 1 " << std::endl;
00033     EXPECT_EQ(0, 4);
00034   }
00035 
00036   tmp.clear();
00037   pITDValues[0] = 1;  pITDValues[3] = 0;
00038   pITDValues[1] = 0;  pITDValues[4] = 0;
00039   pITDValues[2] = 0;  pITDValues[5] = 1;
00040   tmp = model->forwardITD(pITDValues,titi);
00041   if(  (tmp[0]-0.0f)    > 0.001f
00042     || (tmp[1]-0.0f)    > 0.001f
00043     || (titi-0.218264f) > 0.001f) {
00044     std::cout << " test 2 : failed" << std::endl;
00045     EXPECT_EQ(1, 4);
00046   }
00047 
00048   pITDValues[0] = -6;  pITDValues[3] = 0;
00049   pITDValues[1] = -6;  pITDValues[4] = 2;
00050   pITDValues[2] = -2;  pITDValues[5] = 5;
00051   tmp = model->forwardITD(pITDValues,titi);
00052   if(  (tmp[0]-(-0.354632f)) > 0.001f
00053     || (tmp[1]-0.444303f)    > 0.001f
00054     || (titi - 0.813129f)    > 0.001f) {
00055     std::cout << " test 3 : failed" << std::endl;
00056     EXPECT_EQ(2, 4);
00057   }
00058 
00059   pITDValues[0] = 10;  pITDValues[3] = 11;
00060   pITDValues[1] = -7;  pITDValues[4] = 14;
00061   pITDValues[2] = 8;  pITDValues[5] = 12;
00062   tmp = model->forwardITD(pITDValues,titi);
00063 
00064   if(  (tmp[0]-0.068907f) > 0.001f
00065     || (tmp[1]-0.971899f) > 0.001f
00066     || (titi-0.344555f)   > 0.001f) {
00067     std::cout << " test 4 : failed" << std::endl;
00068     EXPECT_EQ(3, 4);
00069   }
00070   EXPECT_EQ(4, 4);
00071 }
00072 
00073 TEST(getITDtest, Init) {
00074   boost::shared_ptr<ALAcousticalModel> model = ALAcousticalModel::getInstance();
00075   int a = 0;
00076   model->getITDmaxLR(a);
00077   EXPECT_EQ(a, 21) << "error : getITDmaxLR";
00078 
00079   int b = 0;
00080   model->getITDmaxFR(b);
00081   EXPECT_EQ(b, 14)<< "error : getITDmaxFR";
00082 
00083   std::vector<int> to;
00084   model->getITDmaxV6(to);
00085   EXPECT_EQ(to[0], 25 ) << "error : getITDmaxV6 [0]";
00086   EXPECT_EQ(to[1], 20 ) << "error : getITDmaxV6 [1]";
00087   EXPECT_EQ(to[2], 20 ) << "error : getITDmaxV6 [2]";
00088   EXPECT_EQ(to[3], 20 ) << "error : getITDmaxV6 [3]";
00089   EXPECT_EQ(to[4], 20 ) << "error : getITDmaxV6 [4]";
00090   EXPECT_EQ(to[5], 25 ) << "error : getITDmaxV6 [5]";
00091   EXPECT_EQ(4, 4);
00092 }
00093 
00094 TEST(computeAngleTest, Init) {
00095   boost::shared_ptr<ALAcousticalModel> model = ALAcousticalModel::getInstance();
00096   std::vector<float> to;
00097   std::vector<int> itd;
00098   itd.push_back(10);
00099   to = model->computeAngle(itd, "az");
00100   if(( to[0] - 0.577957) > 0.00001 )
00101     EXPECT_EQ(to[0], 10.0f ) << "error : computeAngle";
00102 }
00103 
00104 TEST(getValues, Init) {
00105   boost::shared_ptr<ALAcousticalModel> model = ALAcousticalModel::getInstance();
00106   float to = 0.0f;
00107 
00108   model->getSampleRate(to);
00109   EXPECT_EQ(to, 48000.0f ) << "error : getSampleRate";
00110 
00111   model->getSoundSpeed(to);
00112   EXPECT_EQ(to, 342.0f ) << "error : getSoundSpeed";
00113 
00114   std::vector<AL::Math::Position3D> micpos;
00115   model->getMicrosPosition(micpos);
00116   if( fabsf( micpos[0].x - (-0.005575f) ) > 0.0001f ) EXPECT_EQ(micpos[0].x, -0.005575f) << "error : getMicrosPosition 0 x";
00117   if( fabsf( micpos[0].y - (-0.0606f)   ) > 0.0001f ) EXPECT_EQ(micpos[0].y, -0.0606f  ) << "error : getMicrosPosition 0 y";
00118   if( fabsf( micpos[0].z - (-0.02365f)  ) > 0.0001f ) EXPECT_EQ(micpos[0].z, -0.0606f  ) << "error : getMicrosPosition 0 z";
00119 
00120   if( fabsf( micpos[1].x - (-0.005575f) ) > 0.0001f ) EXPECT_EQ(micpos[1].x, -0.005575f) << "error : getMicrosPosition 1 x";
00121   if( fabsf( micpos[1].y - ( 0.0606f)   ) > 0.0001f ) EXPECT_EQ(micpos[1].y,  0.0606f  ) << "error : getMicrosPosition 1 y";
00122   if( fabsf( micpos[1].z - (-0.02365f)  ) > 0.0001f ) EXPECT_EQ(micpos[1].z,  0.0606f  ) << "error : getMicrosPosition 1 z";
00123 
00124   if( fabsf( micpos[2].x - ( 0.054925f) ) > 0.0001f ) EXPECT_EQ(micpos[2].x,  0.054925f) << "error : getMicrosPosition 2 x";
00125   if( fabsf( micpos[2].y - ( 0.0f)      ) > 0.0001f ) EXPECT_EQ(micpos[2].y,  0.0f   )   << "error : getMicrosPosition 2 y";
00126   if( fabsf( micpos[2].z - ( 0.03475f)  ) > 0.0001f ) EXPECT_EQ(micpos[2].z,  0.0f   )   << "error : getMicrosPosition 2 z";
00127 
00128   if( fabsf( micpos[3].x - (-0.043775f) ) > 0.0001f ) EXPECT_EQ(micpos[3].x, -0.043775f) << "error : getMicrosPosition 3 x";
00129   if( fabsf( micpos[3].y - ( 0.0f)      ) > 0.0001f ) EXPECT_EQ(micpos[3].y,  0.0f   )   << "error : getMicrosPosition 3 y";
00130   if( fabsf( micpos[3].z - ( 0.01255f)  ) > 0.0001f ) EXPECT_EQ(micpos[3].z,  0.0f   )   << "error : getMicrosPosition 3 z";
00131 }
00132 
00133 TEST(forwardUpdate, Init) {
00134   boost::shared_ptr<ALAcousticalModel> model = ALAcousticalModel::getInstance();
00135   std::vector<float> ITDValues;
00136   std::vector<float> pITDValues;
00137   pITDValues.push_back(10.0f);  pITDValues.push_back(-7.0f);
00138   pITDValues.push_back(8.0f);   pITDValues.push_back(11.0f);
00139   pITDValues.push_back(14.0f);  pITDValues.push_back(12.0f);
00140 
00141   float toto;
00142   toto = model->forwardITDUpdateValues(pITDValues, ITDValues);
00143   if( fabsf( toto - (0.253429f))         > 0.0001f ) EXPECT_EQ(toto         , (0.253429f))  << "error : return forwardITDUpdateValues";
00144   if( fabsf( ITDValues[0] - (-4.66667f)) > 0.0001f ) EXPECT_EQ(ITDValues[0] , (-4.66667f))  << "error : forwardITDUpdateValues 0";
00145   if( fabsf( ITDValues[1] - (-6.0f)    ) > 0.0001f ) EXPECT_EQ(ITDValues[1] , (-6.0f)    )  << "error : forwardITDUpdateValues 1";
00146   if( fabsf( ITDValues[2] - ( 7.0f)  )   > 0.0001f ) EXPECT_EQ(ITDValues[2] , ( 7.0f)    )  << "error : forwardITDUpdateValues 2";
00147   if( fabsf( ITDValues[3] - (-1.33333f)) > 0.0001f ) EXPECT_EQ(ITDValues[3] , (-1.33333f))  << "error : forwardITDUpdateValues 3";
00148   if( fabsf( ITDValues[4] - (11.6667f))  > 0.0001f ) EXPECT_EQ(ITDValues[4] , (11.6667f) )  << "error : forwardITDUpdateValues 4";
00149   if( fabsf( ITDValues[5] - (13.0f)  )   > 0.0001f ) EXPECT_EQ(ITDValues[5] , (13.0f)    )  << "error : forwardITDUpdateValues 5";
00150 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines