Seg.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_Seg_cpp)
00056 #define ALIZE_Seg_cpp
00057 
00058 #include "Seg.h"
00059 #include "Exception.h"
00060 #include <new>
00061 
00062 using namespace alize;
00063 
00064 //-------------------------------------------------------------------------
00065 Seg::Seg(SegServer& ss, unsigned long b, unsigned long l, unsigned long lc,
00066      const String& s, const String& sn)  //private method
00067 :SegAbstract(ss, lc, s, sn), _begin(b), _length(l) {}
00068 //-------------------------------------------------------------------------
00069 Seg& Seg::create(const K&, SegServer& ss, unsigned long b, unsigned long l,
00070     unsigned long lc, const String& s, const String& sn) // static
00071 {
00072   Seg* p = new (std::nothrow) Seg(ss, b, l, lc, s, sn);
00073   assertMemoryIsAllocated(p, __FILE__, __LINE__);
00074   return *p;
00075 }
00076 //-------------------------------------------------------------------------
00077 Seg& Seg::duplicate(const K&, SegServer& ss) const
00078 {
00079   Seg& s = create(K::k, ss, _begin, _length, _labelCode, _string, _srcName);
00080   s.list() = _list;
00081   return s;
00082 }
00083 //-------------------------------------------------------------------------
00084 void Seg::setBegin(unsigned long b) { _begin = b; }
00085 //-------------------------------------------------------------------------
00086 void Seg::setLength(unsigned long l) { _length = l; }
00087 //-------------------------------------------------------------------------
00088 Seg* Seg::getSeg() const
00089 {
00090   if (_current == 0)
00091   {
00092       _current++;
00093       return const_cast<Seg*>(this);
00094   }
00095   return NULL;
00096 }
00097 //-------------------------------------------------------------------------
00098 void Seg::getExtremeBoundaries(const K&, unsigned long& b,
00099                   unsigned long& e, bool& isDefined) const
00100 {
00101   if (!isDefined)
00102   {
00103     b = _begin;
00104     e = _begin+_length;
00105     isDefined = true;
00106   }
00107   else
00108   {
00109     if (_begin < b)
00110       b = _begin;
00111     if (_begin+_length > e)
00112       e = _begin+_length;
00113   }
00114 }
00115 //-------------------------------------------------------------------------
00116 unsigned long Seg::length() const{ return _length; }
00117 //-------------------------------------------------------------------------
00118 unsigned long Seg::begin() const { return _begin; }
00119 //-------------------------------------------------------------------------
00120 Seg& Seg::merge(Seg& s)
00121 {
00122   unsigned long begin = _begin;
00123   unsigned long end = _begin+_length;
00124   if (s._begin < _begin)
00125     begin = s._begin;
00126   if (s._begin + s._length > end)
00127     end = s._begin + s._length;
00128   _begin = begin;
00129   _length = end-begin;
00130   if (_string != s._string)
00131     _string += " " + s._string;
00132   if (_srcName != s._srcName)
00133     _srcName += " " + s._srcName;
00134   // TODO : what to do with s._labelCode ?
00135   const XList& l = s.list();
00136   for (unsigned long i=0; i<l.getLineCount(); i++)
00137   { _list.addLine() = l.getLine(i); }
00138   getServer().remove(s);
00139   return *this;
00140 }
00141 //-------------------------------------------------------------------------
00142 Seg& Seg::duplicate() const {return getServer().duplicateSeg(*this);}
00143 //-------------------------------------------------------------------------
00144 Seg& Seg::split(unsigned long i)
00145 {
00146   if (i >= _begin+_length)
00147     throw Exception("Cannot split a segment(begin="
00148        + String::valueOf(_begin) + " length="
00149        + String::valueOf(_length) + ") from feature #"
00150        + String::valueOf(i), __FILE__, __LINE__);
00151   Seg& newSeg = duplicate();
00152   newSeg.setBegin(i);
00153   newSeg.setLength(_length-i+_begin);
00154   _length = i-_begin;
00155   return newSeg;
00156 }
00157 //-------------------------------------------------------------------------
00158 String Seg::getClassName() const { return "Seg"; }
00159 //-------------------------------------------------------------------------
00160 String Seg::toString() const
00161 {
00162   return Object::toString()
00163     + "\n  begin = " + String::valueOf(_begin)
00164     + "\n  length = " + String::valueOf(_length)
00165     + "\n  labelCode = " + String::valueOf(_labelCode)
00166     + "\n  string = '" + _string + "'"
00167     + "\n  sourceName = '" + _srcName + "'";
00168   // TODO : ajouter l'affichage de _list
00169 }
00170 //-------------------------------------------------------------------------
00171 Seg::~Seg() {}
00172 //-------------------------------------------------------------------------
00173 
00174 #endif // !defined(ALIZE_Seg_cpp)