00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
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
00090 FeatureFileReaderAbstract& R::createStream(const Config& c)
00091 { return FeatureFileReader::create(c); }
00092
00093
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
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