FeatureFlags.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_FeatureFlags_cpp)
00056 #define ALIZE_FeatureFlags_cpp
00057 
00058 #include "FeatureFlags.h"
00059 #include "Exception.h"
00060 #include "alizeString.h"
00061 
00062 using namespace alize;
00063 
00064 //-------------------------------------------------------------------------
00065 FeatureFlags::FeatureFlags(const String& flags)
00066 :Object() { set(flags); }
00067 //-------------------------------------------------------------------------
00068 FeatureFlags::FeatureFlags()
00069 :Object() { set("000000"); }
00070 //-------------------------------------------------------------------------
00071 FeatureFlags::FeatureFlags(const FeatureFlags& flag)
00072 :Object(), useS(flag.useS), useE(flag.useE), useD(flag.useD),
00073 useDE(flag.useDE), useDD(flag.useDD), useDDE(flag.useDDE) {}
00074 //-------------------------------------------------------------------------
00075 bool FeatureFlags::operator==(const FeatureFlags& flags) const
00076 {
00077   return ( useS   == flags.useS   &&
00078        useE   == flags.useE   &&
00079        useD   == flags.useD   &&
00080        useDE  == flags.useDE  &&
00081        useDD  == flags.useDD  &&
00082        useDDE == flags.useDDE );
00083 }  
00084 //-------------------------------------------------------------------------
00085 bool FeatureFlags::operator!=(const FeatureFlags& flags) const
00086 { return !(*this==flags); }
00087 //-------------------------------------------------------------------------
00088 void FeatureFlags::set(const String& s)
00089 {
00090   char f = s[0].c_str()[0];
00091   if (f == '0')
00092     useS = false;
00093   else if (f == '1')
00094     useS = true;
00095   else if (f != '-')
00096     throw Exception("Wrong parameter : '" + s + "'",
00097                __FILE__, __LINE__);
00098   f = s[1].c_str()[0];
00099   if (f == '0')
00100     useE = false;
00101   else if (f == '1')
00102     useE = true;
00103   else if (f != '-')
00104     throw Exception("Wrong parameter : '" + s + "'",
00105                __FILE__, __LINE__);
00106   f = s[2].c_str()[0];
00107   if (f == '0')
00108     useD = false;
00109   else if (f == '1')
00110     useD = true;
00111   else if (f != '-')
00112     throw Exception("Wrong parameter : '" + s + "'",
00113                __FILE__, __LINE__);
00114   f = s[3].c_str()[0];
00115   if (f == '0')
00116     useDE = false;
00117   else if (f == '1')
00118     useDE = true;
00119   else if (f != '-')
00120     throw Exception("Wrong parameter : '" + s + "'",
00121                __FILE__, __LINE__);
00122   f = s[4].c_str()[0];
00123   if (f == '0')
00124     useDD = false;
00125   else if (f == '1')
00126     useDD = true;
00127   else if (f != '-')
00128     throw Exception("Wrong parameter : '" + s + "'",
00129                __FILE__, __LINE__);
00130   f = s[5].c_str()[0];
00131   if (f == '0')
00132     useDDE = false;
00133   else if (f == '1')
00134     useDDE = true;
00135   else if (f != '-')
00136     throw Exception("Wrong parameter : '" + s + "'",
00137                __FILE__, __LINE__);
00138 }
00139 //-------------------------------------------------------------------------
00140 unsigned int FeatureFlags::toSPro3() const
00141 {
00142   const unsigned int WITHE = 0x01; /* Data is with log energy        */
00143   //const unsigned int WITHZ = 0x02; /* Data as mean suppressed (const only )*/
00144   //const unsigned int WITHN = 0x04; /* Absolute log energy suppressed     */
00145   const unsigned int WITHD = 0x08; /* Data as delta coefficients       */
00146   const unsigned int WITHA = 0xa0; /* Data contains delta-delta coeffs   */
00147   const unsigned int WITHNODE = 0x10; /* */
00148 
00149   unsigned int flags = 0;
00150   if (useD)
00151     flags |= WITHD;
00152   if (useDD)
00153     flags |= WITHA;
00154   if (useE)
00155     flags |= WITHE;
00156   if (!useDE)
00157     flags |= WITHNODE;
00158   return flags;
00159   // TODO : lancer une exception pour les cas interdits
00160 }
00161 //-------------------------------------------------------------------------
00162 unsigned long FeatureFlags::toSPro4() const
00163 {
00164   const unsigned long WITHE = 0x01; /* Data is with log energy        */
00165   //const unsigned long WITHZ = 0x02; /* Data as mean suppressed (const only )*/
00166   //const unsigned long WITHN = 0x04; /* Absolute log energy suppressed     */
00167   const unsigned long WITHD = 0x08; /* Data as delta coefficients       */
00168   const unsigned long WITHA = 0xa0; /* Data contains delta-delta coeffs   */
00169   const unsigned long WITHNODE = 0x10; /* */
00170 
00171   unsigned long flags = 0;
00172   if (useD)
00173     flags |= WITHD;
00174   if (useDD)
00175     flags |= WITHA;
00176   if (useE)
00177     flags |= WITHE;
00178   if (!useDE)
00179     flags |= WITHNODE;
00180   return flags;
00181   // TODO : lancer une exception pour les cas interdits
00182 }
00183 //-------------------------------------------------------------------------
00184 String FeatureFlags::getString() const
00185 {
00186   char flags[] = "000000";
00187   if (useS)   flags[0] = '1';
00188   if (useE)   flags[1] = '1';
00189   if (useD)   flags[2] = '1';
00190   if (useDE)  flags[3] = '1';
00191   if (useDD)  flags[4] = '1';
00192   if (useDDE) flags[5] = '1';
00193 
00194   return flags;
00195 }
00196 //-------------------------------------------------------------------------
00197 String FeatureFlags::getClassName() const { return "FeatureFlags"; }
00198 //-------------------------------------------------------------------------
00199 String FeatureFlags::toString() const
00200 {
00201   return Object::toString()
00202     + "\n  S   = " + String::valueOf(useS)
00203     + "\n  E   = " + String::valueOf(useE)
00204     + "\n  D   = " + String::valueOf(useD)
00205     + "\n  DE  = " + String::valueOf(useDE)
00206     + "\n  DD  = " + String::valueOf(useDD)
00207     + "\n  DDE = " + String::valueOf(useDDE);
00208 }
00209 //-------------------------------------------------------------------------
00210 FeatureFlags::~FeatureFlags() {}
00211 //-------------------------------------------------------------------------
00212 
00213 #endif // !defined(ALIZE_FeatureFlags_cpp)
00214