Object.cpp

Go to the documentation of this file.
00001 /*
00002         This file is part of ALIZE which is an open-source tool for 
00003         speaker recognition.
00004 
00005     ALIZE is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU Lesser General Public License as 
00007     published by the Free Software Foundation, either version 3 of 
00008     the License, or any later version.
00009 
00010     ALIZE is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public 
00016     License along with ALIZE.
00017     If not, see <http://www.gnu.org/licenses/>.
00018         
00019         ALIZE is a development project initiated by the ELISA consortium
00020         [alize.univ-avignon.fr/] and funded by the French Research 
00021         Ministry in the framework of the TECHNOLANGUE program 
00022         [www.technolangue.net]
00023 
00024         The ALIZE project team wants to highlight the limits of voice
00025         authentication in a forensic context.
00026         The "Person  Authentification by Voice: A Need of Caution" paper 
00027         proposes a good overview of this point (cf. "Person  
00028         Authentification by Voice: A Need of Caution", Bonastre J.F., 
00029         Bimbot F., Boe L.J., Campbell J.P., Douglas D.A., Magrin-
00030         chagnolleau I., Eurospeech 2003, Genova].
00031         The conclusion of the paper of the paper is proposed bellow:
00032         [Currently, it is not possible to completely determine whether the 
00033         similarity between two recordings is due to the speaker or to other 
00034         factors, especially when: (a) the speaker does not cooperate, (b) there 
00035         is no control over recording equipment, (c) recording conditions are not 
00036         known, (d) one does not know whether the voice was disguised and, to a 
00037         lesser extent, (e) the linguistic content of the message is not 
00038         controlled. Caution and judgment must be exercised when applying speaker 
00039         recognition techniques, whether human or automatic, to account for these 
00040         uncontrolled factors. Under more constrained or calibrated situations, 
00041         or as an aid for investigative purposes, judicious application of these 
00042         techniques may be suitable, provided they are not considered as infallible.
00043         At the present time, there is no scientific process that enables one to 
00044         uniquely characterize a person=92s voice or to identify with absolute 
00045         certainty an individual from his or her voice.]
00046         Contact Jean-Francois Bonastre for more information about the licence or
00047         the use of ALIZE
00048 
00049         Copyright (C) 2003-2010
00050         Laboratoire d'informatique d'Avignon [lia.univ-avignon.fr]
00051         ALIZE admin [alize@univ-avignon.fr]
00052         Jean-Francois Bonastre [jean-francois.bonastre@univ-avignon.fr]
00053 */
00054 
00055 #if !defined(ALIZE_Object_cpp)
00056 #define ALIZE_Object_cpp
00057 
00058 #if defined(_WIN32)
00059 #define _CRT_SECURE_NO_WARNINGS
00060 #endif
00061 
00062 #include <cstdlib> // for exit()
00063 #include <cstdio>
00064 #include "Object.h"
00065 #include "alizeString.h"
00066 #include "Exception.h"
00067 
00068 using namespace alize;
00069 
00070 #if !defined(NDEBUG)
00071 unsigned long Object::_creationCounter = 0;
00072 unsigned long Object::_destructionCounter = 0;
00073 unsigned long Object::_max = 0;
00074 #endif
00075 
00076 bool Object::_initialized = false;
00077 const real_t Object::MIN_COV = 1e-200;
00078 const real_t Object::EPS_LK = 1e-200;
00079 const real_t Object::PI = 3.14159265358979323846;
00080 const real_t Object::PI2 = 3.14159265358979323846*2;
00081 
00082 const K K::k;
00083 namespace alize
00084 {
00085   ALIZE_API const TopDistribsAction DETERMINE_TOP_DISTRIBS;
00086   ALIZE_API const TopDistribsAction USE_TOP_DISTRIBS;
00087   ALIZE_API const TopDistribsAction TOP_DISTRIBS_NO_ACTION;
00088 }
00089 //-------------------------------------------------------------------------
00090 Object::Object()
00091 {
00092   if (!_initialized)
00093   {
00094     if (sizeof(char)      != 1 ||
00095       sizeof(short)     != 2 ||
00096       sizeof(int)       != 4 ||
00097       sizeof(unsigned int)  != 4 ||
00098       //sizeof(long)      != 4 || // == 8 sur IA64
00099       //sizeof(unsigned long) != 4 ||
00100       sizeof(float)     != 4 ||
00101       sizeof(double)    != 8 )
00102       exit(-1); // TODO : yes, but what to do ?
00103 
00104     const_cast<TopDistribsAction&>(DETERMINE_TOP_DISTRIBS)._i = 0;
00105     const_cast<TopDistribsAction&>(USE_TOP_DISTRIBS)._i = 1;
00106     const_cast<TopDistribsAction&>(TOP_DISTRIBS_NO_ACTION)._i = 2;
00107     _initialized = true;
00108   }
00109 
00110 #if !defined NDEBUG
00111   _creationCounter++;
00112   unsigned long diff = _creationCounter-_destructionCounter;
00113   if (diff > _max)
00114     _max = diff;
00115 #endif
00116 }
00117 //-------------------------------------------------------------------------
00118 String Object::toString() const
00119 { return "[ " + getClassName() + " " + getAddress() + " ]"; }
00120 //-------------------------------------------------------------------------
00121 String Object::getAddress() const
00122 {
00123   char str[50];
00124   ::sprintf(str, "%p", (void*)this);
00125   return str;
00126 }
00127 //-------------------------------------------------------------------------
00128 bool Object::isSameObject(const Object& o) const
00129 { return this == &o; }
00130 //-------------------------------------------------------------------------
00131 #if !defined NDEBUG
00132 unsigned long Object::getCreationCounter() // static method
00133 { return _creationCounter; }
00134 //-------------------------------------------------------------------------
00135 unsigned long Object::getDestructionCounter() // static method
00136 { return _destructionCounter; throw Exception("", "", 1);}
00137 //-------------------------------------------------------------------------
00138 unsigned long Object::getMax() // static method
00139 { return _max; }
00140 #endif
00141 //-------------------------------------------------------------------------
00142 void Object::assertIsInBounds(const char* fileName, int line, 
00143                               unsigned long i, unsigned long size)
00144 {
00145   if (i >= size)
00146     throw IndexOutOfBoundsException("", __FILE__, __LINE__, i, size);
00147 }
00148 //-------------------------------------------------------------------------
00149 void Object::assertMemoryIsAllocated(const void* p, const char* f, int l)
00150 {
00151   if (p == NULL)
00152     throw OutOfMemoryException("", f, l);
00153 }
00154 //-------------------------------------------------------------------------
00155 unsigned long Object::max(unsigned long a, unsigned long b)
00156 { return (a>=b?a:b); }
00157 //-------------------------------------------------------------------------
00158 String Object::getParamTypeName(ParamType t)
00159 {
00160   if (t == PARAMTYPE_INTEGER)
00161     return "INTEGER";
00162   if (t == PARAMTYPE_FLOAT)
00163     return "FLOAT";
00164   if (t == PARAMTYPE_BOOLEAN)
00165     return "BOOLEAN";
00166   if (t == PARAMTYPE_STRING)
00167     return "STRING";
00168   if (t == PARAMTYPE_UNDEFINED)
00169     return "";
00170   throw Exception("", __FILE__, __LINE__);
00171 }
00172 //-------------------------------------------------------------------------
00173 ParamType Object::getParamType(const String& s)
00174 {
00175   if (s == "INTEGER")
00176    return PARAMTYPE_INTEGER;
00177   if (s == "FLOAT")
00178     return PARAMTYPE_FLOAT;
00179   if (s == "BOOLEAN")
00180     return PARAMTYPE_BOOLEAN;
00181   if (s == "STRING")
00182     return PARAMTYPE_STRING;
00183   if (s == "")
00184     return PARAMTYPE_UNDEFINED;
00185   throw Exception("", __FILE__, __LINE__);
00186 }
00187 //-------------------------------------------------------------------------
00188 MixtureServerFileWriterFormat Object::getMixtureServerFileWriterFormat(const String& name)
00189 {
00190   if (name == "XML")
00191     return MixtureServerFileWriterFormat_XML;
00192   if (name == "RAW")
00193     return MixtureServerFileWriterFormat_RAW;
00194   throw Exception("Unavailable mixture file format name '" + name + "'",
00195                             __FILE__, __LINE__);
00196   return MixtureServerFileWriterFormat_RAW; // never called
00197 }
00198 //-------------------------------------------------------------------------
00199 String Object::getDistribTypeName(DistribType t)
00200 {
00201   if (t == DistribType_GD)
00202     return "GD";
00203   return "GF";
00204 }
00205 //-------------------------------------------------------------------------
00206 DistribType Object::getDistribType(const String& name)
00207 {
00208   if (name == "GD")
00209     return DistribType_GD;
00210   if (name == "GF")
00211     return DistribType_GF;
00212   throw Exception("Unavailable distrib type name '" + name + "'",
00213                             __FILE__, __LINE__);
00214   return DistribType_GD; // never called
00215 }
00216 //-------------------------------------------------------------------------
00217 FeatureFileReaderFormat Object::getFeatureFileReaderFormat(const String& name)
00218 {
00219   if (name == "SPRO3")
00220     return FeatureFileReaderFormat_SPRO3;
00221   if (name == "SPRO4")
00222     return FeatureFileReaderFormat_SPRO4;
00223   if (name == "RAW")
00224     return FeatureFileReaderFormat_RAW;
00225   if (name == "HTK")
00226     return FeatureFileReaderFormat_HTK;
00227   throw Exception("Unavailable feature file format name '" + name + "'",
00228                             __FILE__, __LINE__);
00229   return FeatureFileReaderFormat_RAW; // never called
00230 }
00231 //-------------------------------------------------------------------------
00232 SPRO3DataKind Object::getSPro3DataKind(const String& name)
00233 {
00234   if (name == "OTHER") // Anything else I didn't think about
00235     return SPRO3DataKind_OTHER;
00236   if (name == "FBANK") // Filter bank output
00237     return SPRO3DataKind_FBANK;
00238   if (name == "FBCEPSTRA") // Cepstra from filter bank analysis
00239     return SPRO3DataKind_FBCEPSTRA;
00240   if (name == "LPCEPSTRA") // Cepstra from LPC analysis
00241     return SPRO3DataKind_LPCEPSTRA;
00242   if (name == "LPCOEFF") // Linear prediction coefficients
00243     return SPRO3DataKind_LPCOEFF;
00244   if (name == "PARCOR") // Partial correlation coefficients
00245     return SPRO3DataKind_PARCOR;
00246   if (name == "LAR")// Log area ratios
00247     return SPRO3DataKind_LAR;
00248   throw Exception("Unavailable data kind name '" + name + "'",
00249                             __FILE__, __LINE__);
00250   return SPRO3DataKind_OTHER; // never called
00251 }
00252 //-------------------------------------------------------------------------
00253 SegServerFileReaderFormat Object::getSegServerFileReaderFormat(const String& name)
00254 {
00255   if (name == "XML")
00256     return SegServerFileReaderFormat_XML;
00257   if (name == ".seg")
00258     return SegServerFileReaderFormat_LIUM;
00259   if (name == "RAW")
00260     return SegServerFileReaderFormat_RAW;
00261   throw Exception("Unavailable segServer file format name '" + name + "'",
00262                             __FILE__, __LINE__);
00263   return SegServerFileReaderFormat_LIUM; // never called
00264 }
00265 //-------------------------------------------------------------------------
00266 SegServerFileWriterFormat Object::getSegServerFileWriterFormat(const String& n)
00267 {
00268   if (n == "XML")
00269     return SegServerFileWriterFormat_XML;
00270   if (n == ".seg")
00271     return SegServerFileWriterFormat_LIUM;
00272   if (n == "RAW")
00273     return SegServerFileWriterFormat_RAW;
00274   if (n == "TRS")
00275     return SegServerFileWriterFormat_TRS;
00276   throw Exception("Unavailable segServer file format name '" + n + "'",
00277                         __FILE__, __LINE__);
00278   return SegServerFileWriterFormat_XML; // never called
00279 }
00280 //-------------------------------------------------------------------------
00281 MixtureFileWriterFormat Object::getMixtureFileWriterFormat(const String& name)
00282 {
00283   if (name == "XML")
00284     return MixtureFileWriterFormat_XML;
00285   if (name == "RAW")
00286     return MixtureFileWriterFormat_RAW;
00287   if (name == "ETAT")
00288     return MixtureFileWriterFormat_ETAT;
00289   throw Exception("Unavailable mixture file format name '" + name + "'",
00290                             __FILE__, __LINE__);
00291   return MixtureFileWriterFormat_RAW; // never called
00292 }
00293 //-------------------------------------------------------------------------
00294 FeatureFileWriterFormat Object::getFeatureFileWriterFormat(const String& name)
00295 {
00296   if (name == "SPRO3")
00297     return FeatureFileWriterFormat_SPRO3;
00298   if (name == "SPRO4")
00299     return FeatureFileWriterFormat_SPRO4;
00300   if (name == "RAW")
00301     return FeatureFileWriterFormat_RAW;
00302   throw Exception("Unavailable feature file format name '" + name + "'",
00303                             __FILE__, __LINE__);
00304   return FeatureFileWriterFormat_RAW; // never called
00305 }
00306 //-------------------------------------------------------------------------
00307 MixtureFileReaderFormat Object::getMixtureFileReaderFormat(const String& name)
00308 {
00309   if (name == "AMIRAL")
00310     return MixtureFileReaderFormat_AMIRAL;
00311   if (name == "XML")
00312     return MixtureFileReaderFormat_XML;
00313   if (name == "RAW")
00314     return MixtureFileReaderFormat_RAW;
00315   throw Exception("Unavailable mixture file format name '" + name + "'",
00316                             __FILE__, __LINE__);
00317   return MixtureFileReaderFormat_RAW; // never called
00318 }
00319 //-------------------------------------------------------------------------
00320 Object::~Object()
00321 {
00322 #if !defined NDEBUG
00323   _destructionCounter++;
00324   unsigned long diff = _creationCounter-_destructionCounter;
00325   if (diff > _max)
00326     _max = diff;
00327 #endif
00328 }
00329 //-------------------------------------------------------------------------
00330 
00331 
00332 #endif // !defined(ALIZE_Object_cpp)
00333