SegCluster.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_SegCluster_cpp)
00056 #define ALIZE_SegCluster_cpp
00057 
00058 #include "SegCluster.h"
00059 #include "SegServer.h"
00060 #include "Exception.h"
00061 #include <new>
00062 #include "limits.h"
00063 #include <iostream>
00064 
00065 using namespace alize;
00066 using namespace std;
00067 typedef SegCluster C;
00068 //-------------------------------------------------------------------------
00069 C::SegCluster(SegServer& ss, unsigned long lc, const String& s,
00070                                                           const String& sn)
00071 :SegAbstract(ss, lc, s, sn), _pCurrentSeg(NULL) { rewind(); }
00072 //-------------------------------------------------------------------------
00073 SegCluster& C::create(const K&, SegServer& ss, unsigned long lc,
00074                       const String& s, const String& sn)
00075 {
00076   SegCluster* p = new (std::nothrow) SegCluster(ss, lc, s, sn);
00077   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00078   return *p;
00079 }
00080 //-------------------------------------------------------------------------
00081 /*C::SegCluster(const SegCluster& s)
00082 :SegAbstract(*s._pServer, s._begin, s._end, s._labelCode, s._string,
00083  s._srcName) {}*/
00084 //-------------------------------------------------------------------------
00085 SegCluster& C::duplicate(const K&, SegServer& ss) const
00086 {
00087   SegCluster& cl = create(K::k, ss, labelCode(), string(), sourceName());
00088   cl.list() = _list;
00089   return cl;
00090 }
00091 //-------------------------------------------------------------------------
00092 unsigned long C::getId() const { return _id; }
00093 //-------------------------------------------------------------------------
00094 void C::setId(const K&, unsigned long id) { _id = id; }
00095 //-------------------------------------------------------------------------
00096 void C::rewind() const
00097 {
00098   _current = 0;
00099   _pCurrentSubSeg = NULL;
00100 }
00101 //-------------------------------------------------------------------------
00102 Seg* C::getSeg() const
00103 {
00104   do
00105   {
00106     if (_pCurrentSubSeg == NULL)
00107     {
00108       if (_current >= _vect.size())
00109         return NULL;
00110       _pCurrentSubSeg = &get(_current);
00111       _pCurrentSubSeg->rewind();
00112     }
00113     Seg* p = _pCurrentSubSeg->getSeg();
00114     if (p != NULL)
00115       return p;
00116     _pCurrentSubSeg = NULL;
00117     _current++;
00118   }
00119   while (true);
00120 }
00121 //-------------------------------------------------------------------------
00122 unsigned long C::begin() const
00123 {
00124   bool isDefined = false;
00125   unsigned long b, e;
00126   getExtremeBoundaries(K::k, b, e, isDefined);
00127   if (!isDefined)
00128     throw Exception("Undefined begin value", __FILE__, __LINE__);
00129   return b;
00130 }
00131 //-------------------------------------------------------------------------
00132 unsigned long C::length() const
00133 {
00134   bool isDefined = false;
00135   unsigned long b, e;
00136   getExtremeBoundaries(K::k, b, e, isDefined);
00137   if (!isDefined)
00138     throw Exception("Undefined length value", __FILE__, __LINE__);
00139   return e-b;
00140 }
00141 //-------------------------------------------------------------------------
00142 void C::add(SegAbstract& s)
00143 {
00144   if (!getServer().isSameObject(s.getServer()))
00145     throw Exception("Cannot add a extern segment", __FILE__, __LINE__);
00146   _vect.addObject(s);
00147   s.addOwner(K::k, *this);
00148 }
00149 //-------------------------------------------------------------------------
00150 void C::add(SegAbstract& s, unsigned long pos)
00151 {
00152   if (!getServer().isSameObject(s.getServer()))
00153     throw Exception("Cannot add a extern segment", __FILE__, __LINE__);
00154   _vect.addObject(s, pos);
00155   s.addOwner(K::k, *this);
00156 }
00157 //-------------------------------------------------------------------------
00158 Seg& C::addCopy(const Seg& s)
00159 {
00160   Seg& seg = getServer().duplicateSeg(s);
00161   _vect.addObject(seg);
00162   seg.addOwner(K::k, *this);
00163   return seg;
00164 }
00165 //-------------------------------------------------------------------------
00166 Seg& C::addCopy(const Seg& s, unsigned long pos)
00167 {
00168   Seg& seg = getServer().duplicateSeg(s);
00169   _vect.addObject(seg, pos);
00170   seg.addOwner(K::k, *this);
00171   return seg;
00172 }
00173 //-------------------------------------------------------------------------
00174 Seg& C::addNewSeg(unsigned long b, unsigned long l, unsigned long lc,
00175                   const String& s, const String& sn)
00176 {
00177   Seg& seg = getServer().createSeg(b, l, lc, s, sn);
00178   _vect.addObject(seg);
00179   seg.addOwner(K::k, *this);
00180   return seg;
00181 }
00182 //-------------------------------------------------------------------------
00183 void C::remove(SegAbstract& s)
00184 {
00185   s.removeOwner(K::k, *this);
00186   _vect.removeObject(s);
00187 }
00188 //-------------------------------------------------------------------------
00189 SegAbstract& C::remove(unsigned long i)
00190 {
00191   SegAbstract& s = get(i);
00192   s.removeOwner(K::k, *this);
00193   _vect.removeObject(i);
00194   return s;
00195 }
00196 //-------------------------------------------------------------------------
00197 void C::removeAll()
00198 {
00199   for (unsigned long i=0; i<_vect.size(); i++)
00200     get(i).removeOwner(K::k, *this);
00201   _vect.clear(); // do not call deleteAllObjects()
00202 }
00203 //-------------------------------------------------------------------------
00204 unsigned long C::getCount() const { return _vect.size(); }
00205 //-------------------------------------------------------------------------
00206 SegAbstract& C::get(unsigned long i) const { return _vect.getObject(i); }
00207 //-------------------------------------------------------------------------
00208 bool C::getFeatureLabelCode(unsigned long n, unsigned long& lc) const
00209 {
00210   if (_pCurrentSeg != NULL && n >= _b && n < _e)
00211   {
00212     lc = _lc;
00213     return true;
00214   }
00215   bool f, l;
00216   return getFeatureLabelCode(n, lc, f, l);
00217 }
00218 //-------------------------------------------------------------------------
00219 bool C::getFeatureLabelCode(unsigned long n, unsigned long& lc,
00220                             bool& isFirst, bool& isLast) const
00221 {
00222   if (_pCurrentSeg != NULL && n >= _b && n < _e)
00223   {
00224     isFirst = (n == _b);
00225     isLast = (n == _e-1);
00226     lc = _lc;
00227     return true;
00228   }
00229   _pStartSeg = NULL;
00230 
00231   do
00232   {
00233     _pCurrentSeg = getSeg();
00234 
00235     if (_pCurrentSeg != NULL)
00236     {
00237       if (_pCurrentSeg == _pStartSeg)
00238         break;
00239       _b = _pCurrentSeg->begin();
00240       _e = _b + _pCurrentSeg->length();
00241       if (n >= _b && n < _e)
00242       {
00243         isFirst = (n == _b);
00244         isLast = (n == _e-1);
00245         lc = _lc = _pCurrentSeg->labelCode();
00246         return true;
00247       }
00248       if (_pStartSeg == NULL)
00249         _pStartSeg = _pCurrentSeg;
00250     }
00251     else
00252       rewind();
00253   }
00254   while (true);
00255 
00256   _pCurrentSeg = NULL;
00257   return false;
00258 }
00259 //-------------------------------------------------------------------------
00260 void C::getExtremeBoundaries(const K&, unsigned long& b,
00261   /* methode recursive */     unsigned long& e, bool& isDefined) const
00262 {
00263   for (unsigned long i=0; i<getCount(); i++)
00264   { get(i).getExtremeBoundaries(K::k, b, e, isDefined); }
00265 }
00266 //-------------------------------------------------------------------------
00267 String C::getClassName() const { return "SegCluster"; }
00268 //-------------------------------------------------------------------------
00269 String C::toString() const
00270 {
00271   String b("undefined");
00272   String l("undefined");
00273   try { b = String::valueOf(begin()); } catch (Exception&) {}
00274   try { l = String::valueOf(length()); } catch (Exception&) {}
00275   return Object::toString()
00276     + "\n  server name = '" + getServer().getServerName() + "'"
00277     + "\n  begin = " + b
00278     + "\n  length   = " + l
00279     + "\n  labelCode = " + String::valueOf(_labelCode)
00280     + "\n  string = '" + _string + "'"
00281     + "\n  sourceName = '" + _srcName + "'";
00282   // TODO : ajouter l'affichage de _list
00283 }
00284 //-------------------------------------------------------------------------
00285 C::~SegCluster() { removeAll(); }
00286 //-------------------------------------------------------------------------
00287 
00288 #endif // !defined(ALIZE_SegCluster_cpp)