FeatureFileReader.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_FeatureFileReader_cpp)
00056 #define ALIZE_FeatureFileReader_cpp
00057 
00058 #include <new>
00059 #include "FeatureFileReader.h"
00060 #include "FeatureMultipleFileReader.h"
00061 #include "FeatureFileReaderRaw.h"
00062 #include "FeatureFileReaderSPro3.h"
00063 #include "FeatureFileReaderSPro4.h"
00064 #include "FeatureFileReaderHTK.h"
00065 #include "Feature.h"
00066 #include "Exception.h"
00067 #include "LabelServer.h"
00068 #include "Label.h"
00069 #include "FeatureFlags.h"
00070 #include "XLine.h"
00071 #include "Config.h"
00072 
00073 using namespace alize;
00074 typedef FeatureFileReader R;
00075 
00076 //-------------------------------------------------------------------------
00077 R::FeatureFileReader(const Config& c)
00078 :FeatureFileReaderAbstract(NULL, c, NULL, BUFFER_USERDEFINE, 0,
00079                            ALL_FEATURES, 0),
00080  _pFeatureReader(NULL) {}
00081 //-------------------------------------------------------------------------
00082 R::FeatureFileReader(const FileName& f, const Config& c, LabelServer* p,
00083                      BigEndian be, BufferUsage b, unsigned long bufferSize,
00084                      HistoricUsage h, unsigned long historicSize)
00085 :FeatureFileReaderAbstract(NULL, c, NULL, b, bufferSize, h, historicSize),
00086  _pFeatureReader(&createStream(f, c, p, be, b, bufferSize, h, historicSize))
00087  {}
00088 //-------------------------------------------------------------------------
00089 // static method
00090 FeatureFileReaderAbstract& R::createStream(const Config& c)
00091 { return FeatureFileReader::create(c); }
00092 //-------------------------------------------------------------------------
00093 // static method
00094 FeatureFileReaderAbstract& R::createStream(const XLine& l, const Config& c,
00095      LabelServer* p, BigEndian be, BufferUsage b, unsigned long bufferSize,
00096      HistoricUsage h, unsigned long historicSize)
00097 {
00098   return FeatureMultipleFileReader::create(l, c, p, be, b, bufferSize,
00099                                            h, historicSize);
00100 }
00101 //-------------------------------------------------------------------------
00102 // static method
00103 FeatureFileReaderAbstract& R::createStream(const FileName& f,
00104              const Config& c, LabelServer* p, BigEndian be, BufferUsage b,
00105              unsigned long bufferSize, HistoricUsage h,
00106              unsigned long historicSize)
00107 {
00108   if (f.endsWith(".lst"))
00109     return FeatureMultipleFileReader::create(
00110                  XList(f, c).getAllElements(), c, p, be, b, bufferSize, h, historicSize);
00111   if (c.existsParam_loadFeatureFileFormat)
00112     switch (c.getParam_loadFeatureFileFormat())
00113     {
00114     case FeatureFileReaderFormat_SPRO3:
00115         return FeatureFileReaderSPro3::create(f, c, p, b, bufferSize, h, historicSize);
00116     case FeatureFileReaderFormat_SPRO4:
00117         return FeatureFileReaderSPro4::create(f, c, p, be, b, bufferSize, h, historicSize);
00118     case FeatureFileReaderFormat_HTK:
00119         return FeatureFileReaderHTK::create(f, c, p, be, b, bufferSize, h, historicSize);
00120     case FeatureFileReaderFormat_RAW:
00121         return FeatureFileReaderRaw::create(f, c, p, be, b, bufferSize, h, historicSize);
00122     }
00123   throw Exception("Param 'loadFeatureFileFormat' expected in the config",
00124                   __FILE__, __LINE__);
00125 }
00126 //-------------------------------------------------------------------------
00127 R::FeatureFileReader(const XLine& l, const Config& c, LabelServer* p,
00128                      BigEndian be, BufferUsage b, unsigned long bufferSize,
00129                      HistoricUsage h, unsigned long historicSize)
00130 :FeatureFileReaderAbstract(NULL, c, NULL, b, bufferSize, h, historicSize),
00131  _pFeatureReader(&FeatureMultipleFileReader::create(l, c, p, be, b,
00132  bufferSize, h, historicSize)) {}
00133 //-------------------------------------------------------------------------
00134 R& R::create(const Config& c)
00135 {
00136   FeatureFileReader* p = new (std::nothrow) FeatureFileReader(c);
00137   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00138   return *p;
00139 }
00140 //-------------------------------------------------------------------------
00141 R& R::create(const FileName& f, const Config& c, LabelServer* l,
00142              BigEndian be, BufferUsage b, unsigned long bufferSize,
00143              HistoricUsage h, unsigned long historicSize)
00144 {
00145   R* p = new (std::nothrow) R(f, c, l, be, b, bufferSize, h, historicSize);
00146   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00147   return *p;
00148 }
00149 //-------------------------------------------------------------------------
00150 R& R::create(const XLine& l, const Config& c, LabelServer* ls,
00151              BigEndian be, BufferUsage b, unsigned long bufferSize,
00152              HistoricUsage h, unsigned long historicSize)
00153 {
00154   R* p = new (std::nothrow) R(l, c, ls, be, b, bufferSize, h, historicSize);
00155   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00156   return *p;
00157 }
00158 //-------------------------------------------------------------------------
00159 bool R::readFeature(Feature& f, unsigned long step)
00160 {
00161   if (_pFeatureReader == NULL)
00162     return false;
00163   if (_seekWanted)
00164   {
00165     _seekWanted = false;
00166     _pFeatureReader->seekFeature(_seekWantedIdx, _seekWantedSrcName);
00167   }
00168   bool ok = _pFeatureReader->readFeature(f, step);
00169   _error = _pFeatureReader->getError();
00170   return ok;
00171 }
00172 //-------------------------------------------------------------------------
00173 void R::seekFeature(unsigned long featureNbr, const String& sourceName)
00174 {
00175   if (_pFeatureReader != NULL)
00176       _pFeatureReader->seekFeature(featureNbr, sourceName);
00177 }
00178 //-------------------------------------------------------------------------
00179 bool R::writeFeature(const Feature& f, unsigned long step)
00180 {
00181   if (_pFeatureReader == NULL)
00182     throw Exception("feature writing forbidden", __FILE__, __LINE__);
00183   if (_seekWanted)
00184   {
00185     _seekWanted = false;
00186     _pFeatureReader->seekFeature(_seekWantedIdx, _seekWantedSrcName);
00187   }
00188   bool ok = _pFeatureReader->writeFeature(f, step);
00189   _error = _pFeatureReader->getError();
00190   return ok;
00191 }
00192 //-------------------------------------------------------------------------
00193 unsigned long R::getFeatureCount()
00194 {
00195   if (_pFeatureReader != NULL)
00196     return _pFeatureReader->getFeatureCount();
00197   return 0;
00198 }
00199 //-------------------------------------------------------------------------
00200 unsigned long R::getVectSize()
00201 {
00202   if (_pFeatureReader == NULL)
00203     throw Exception("no file to read", __FILE__, __LINE__);
00204   return _pFeatureReader->getVectSize();
00205 }
00206 //-------------------------------------------------------------------------
00207 void R::setExternalBufferToUse(FloatVector& v)
00208 { _pFeatureReader->setExternalBufferToUse(v); }
00209 //-------------------------------------------------------------------------
00210 const FeatureFlags& R::getFeatureFlags()
00211 {
00212   if (_pFeatureReader == NULL)
00213     throw Exception("no file to read", __FILE__, __LINE__);
00214   return _pFeatureReader->getFeatureFlags();
00215 }
00216 //-------------------------------------------------------------------------
00217 real_t R::getSampleRate() 
00218 {
00219   if (_pFeatureReader == NULL)
00220     throw Exception("no file to read", __FILE__, __LINE__);
00221   return _pFeatureReader->getSampleRate();
00222 }
00223 //-------------------------------------------------------------------------
00224 void R::close()
00225 {
00226   if (_pFeatureReader != NULL)
00227     _pFeatureReader->close();
00228 }
00229 //-------------------------------------------------------------------------
00230 unsigned long R::getSourceCount()
00231 {
00232   if (_pFeatureReader != NULL)
00233     return _pFeatureReader->getSourceCount();
00234   return 0;
00235 }
00236 //-------------------------------------------------------------------------
00237 unsigned long R::getFeatureCountOfASource(unsigned long srcIdx)
00238 {
00239   if (_pFeatureReader == NULL)
00240     throw Exception("No source of features", __FILE__, __LINE__);
00241   return _pFeatureReader->getFeatureCountOfASource(srcIdx);
00242 }
00243 //-------------------------------------------------------------------------
00244 unsigned long R::getFeatureCountOfASource(const FileName& f)
00245 {
00246   if (_pFeatureReader == NULL)
00247     throw Exception("No source of features", __FILE__, __LINE__);
00248   return _pFeatureReader->getFeatureCountOfASource(f);
00249 }
00250 //-------------------------------------------------------------------------
00251 unsigned long R::getFirstFeatureIndexOfASource(unsigned long srcIdx)
00252 {
00253   if (_pFeatureReader == NULL)
00254     throw Exception("No source of features", __FILE__, __LINE__);
00255   return _pFeatureReader->getFirstFeatureIndexOfASource(srcIdx);
00256 }
00257 //-------------------------------------------------------------------------
00258 unsigned long R::getFirstFeatureIndexOfASource(const FileName& f)
00259 {
00260   if (_pFeatureReader == NULL)
00261     throw Exception("No source of features", __FILE__, __LINE__);
00262   return _pFeatureReader->getFirstFeatureIndexOfASource(f);
00263 }
00264 //-------------------------------------------------------------------------
00265 const String& R::getNameOfASource(unsigned long srcIdx)
00266 {
00267   if (_pFeatureReader == NULL)
00268     throw Exception("No source of features", __FILE__, __LINE__);
00269   return _pFeatureReader->getNameOfASource(srcIdx); }
00270 //-------------------------------------------------------------------------
00271 String R::getClassName() const{return "FeatureFileReader";}
00272 //-------------------------------------------------------------------------
00273 R::~FeatureFileReader()
00274 {
00275   if (_pFeatureReader != NULL)
00276     delete _pFeatureReader;
00277 }
00278 //-------------------------------------------------------------------------
00279 
00280 #endif // !defined(ALIZE_FeatureFileReader_cpp)
00281