FeatureFileList.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_FeatureFileList_cpp)
00056 #define ALIZE_FeatureFileList_cpp
00057 
00058 #include "FeatureFileList.h"
00059 #include "FeatureFileReader.h"
00060 
00061 using namespace alize;
00062 
00063 //-------------------------------------------------------------------------
00064 FeatureFileList::FeatureFileList(const XLine& l, const Config& c)
00065 :Object(), _fileNameVect(l), _config(c), _vectSizeDefined(false),
00066  _sampleRateDefined(false), _featureFlagsDefined(false),
00067  _featureCountDefined(false) {}
00068 //-------------------------------------------------------------------------
00069 unsigned long FeatureFileList::size() const
00070 { return _fileNameVect.getElementCount(); }
00071 //-------------------------------------------------------------------------
00072 unsigned long FeatureFileList::getVectSize() const
00073 {
00074   if (!_vectSizeDefined)
00075   {
00076     FeatureFileReader r(_fileNameVect.getElement(0), _config, NULL,
00077                         BIGENDIAN_AUTO, BUFFER_USERDEFINE, 0);
00078     _vectSize = r.getVectSize();
00079     _vectSizeDefined = true;
00080     if (!_sampleRateDefined)
00081       try { _sampleRate = r.getSampleRate(); _sampleRateDefined = true; }
00082       catch (Exception&) {}
00083     if (!_featureFlagsDefined)
00084       try { _featureFlags = r.getFeatureFlags(); _featureFlagsDefined = true; }
00085       catch (Exception&) {}
00086   }
00087   return _vectSize;
00088 }
00089 //-------------------------------------------------------------------------
00090 real_t FeatureFileList::getSampleRate() const
00091 {
00092   if (!_sampleRateDefined)
00093   {
00094     FeatureFileReader r(_fileNameVect.getElement(0), _config);
00095     _sampleRate = r.getSampleRate();
00096     _sampleRateDefined = true;
00097     if (!_vectSizeDefined)
00098       try { _vectSize = r.getVectSize(); _vectSizeDefined = true; }
00099       catch (Exception&) {}
00100     if (!_featureFlagsDefined)
00101       try { _featureFlags = r.getFeatureFlags(); _featureFlagsDefined = true; }
00102       catch (Exception&) {}
00103   }
00104   return _sampleRate;
00105 }
00106 //-------------------------------------------------------------------------
00107 const FeatureFlags& FeatureFileList::getFeatureFlags() const
00108 {
00109   if (!_featureFlagsDefined)
00110   {
00111     FeatureFileReader r(_fileNameVect.getElement(0), _config);
00112     _featureFlags = r.getFeatureFlags();
00113     _featureFlagsDefined = true;
00114     if (!_vectSizeDefined)
00115       try { _vectSize = r.getVectSize(); _vectSizeDefined = true; }
00116       catch (Exception&) {}
00117     if (!_sampleRateDefined)
00118       try { _sampleRate = r.getSampleRate(); _sampleRateDefined = true; }
00119       catch (Exception&) {}
00120   }
00121   return _featureFlags;
00122 }
00123 //-------------------------------------------------------------------------
00124 unsigned long FeatureFileList::getFeatureCount() const
00125 {
00126   if (!_featureCountDefined)
00127   {
00128     unsigned long size = _fileNameVect.getElementCount();
00129     _featureCountTot = 0;
00130     for (unsigned long i=0; i<size; i++)
00131     {
00132       FeatureFileReader r(_fileNameVect.getElement(i), _config);
00133       unsigned long c = r.getFeatureCount();
00134       _featureFirst.addValue(_featureCountTot);
00135       _featureCountTot += c;
00136       _featureCount.addValue(c);
00137       if (i == 0)
00138       {
00139         if (!_vectSizeDefined)
00140           try { _vectSize = r.getVectSize(); _vectSizeDefined = true; }
00141           catch (Exception&) {}
00142         if (!_sampleRateDefined)
00143           try { _sampleRate = r.getSampleRate(); _sampleRateDefined = true; }
00144           catch (Exception&) {}
00145         if (!_featureFlagsDefined)
00146           try { _featureFlags = r.getFeatureFlags(); _featureFlagsDefined = true; }
00147           catch (Exception&) {}
00148        }
00149     }
00150     _featureCountDefined = true;
00151   }
00152   return _featureCountTot;
00153 }
00154 //-------------------------------------------------------------------------
00155 unsigned long FeatureFileList::getIndexOfFirstFeature(
00156                                                unsigned long fileIdx) const
00157 {
00158   if (!_featureCountDefined)
00159     getFeatureCount();
00160   return _featureFirst[fileIdx];
00161 }
00162 //-------------------------------------------------------------------------
00163 unsigned long FeatureFileList::getIndexOfFirstFeature(
00164                                                    const FileName& f) const
00165 { return getIndexOfFirstFeature(getFileIndex(f)); }
00166 //-------------------------------------------------------------------------
00167 unsigned long FeatureFileList::getFeatureCount(unsigned long fileIdx) const
00168 {
00169   if (!_featureCountDefined)
00170     getFeatureCount();
00171   return _featureCount[fileIdx];
00172 }
00173 //-------------------------------------------------------------------------
00174 unsigned long FeatureFileList::getFeatureCount(const FileName& f) const
00175 {
00176   if (!_featureCountDefined)
00177     getFeatureCount();
00178   unsigned long i, size = _fileNameVect.getElementCount();
00179   for (i=0; i<size; i++)
00180   {
00181     if (f == _fileNameVect.getElement(i))
00182       return _featureCount[i];
00183   }
00184   throw Exception(f + " : Unknown feature file name",
00185                   __FILE__, __LINE__);
00186   return 0; // never called
00187 }
00188 //-------------------------------------------------------------------------
00189 const String& FeatureFileList::getFileName(unsigned long fileIdx) const
00190 { return _fileNameVect.getElement(fileIdx); }
00191 //-------------------------------------------------------------------------
00192 unsigned long FeatureFileList::getFileIndex(const FileName& f) const
00193 {
00194   unsigned long i, size = _fileNameVect.getElementCount();
00195   for (i=0; i<size; i++)
00196   {
00197     if (f == _fileNameVect.getElement(i))
00198       return i;
00199   }
00200   throw Exception(f + " : Unknown feature file name",
00201                   __FILE__, __LINE__);
00202   return 0; // never called
00203 }
00204 //-------------------------------------------------------------------------
00205 unsigned long FeatureFileList::getFileIndex(unsigned long featureNbr) const
00206 {
00207   unsigned long i, size = _fileNameVect.getElementCount();
00208   if (size == 0)
00209     throw Exception("The file list is empty", __FILE__, __LINE__);
00210   if (size == 1)
00211     return 0;
00212   for (i=0; i<size-1; i++)
00213   {
00214     if (featureNbr < getIndexOfFirstFeature(i+1))
00215       return i;
00216   }
00217   return i;
00218 }
00219 //-------------------------------------------------------------------------
00220 String FeatureFileList::getClassName() const { return "FeatureFileList"; }
00221 //-------------------------------------------------------------------------
00222 FeatureFileList::~FeatureFileList() {}
00223 //-------------------------------------------------------------------------
00224 
00225 #endif // !defined(ALIZE_FeatureFileList_cpp)
00226