Go to the documentation of this file.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_ShiftedDeltaFeat_cpp)
00056 #define ALIZE_ShiftedDeltaFeat_cpp
00057
00058 #include <iostream>
00059 #include <fstream>
00060 #include <cstdio>
00061 #include <cassert>
00062 #include <cmath>
00063 #include <liatools.h>
00064 #include "ShiftedDeltaFeat.h"
00065
00066 using namespace alize;
00067 using namespace std;
00068
00069
00079 int ShiftedDeltaFeat (Config & config) {
00080 unsigned int numCeps = 0 ;
00081 unsigned int deltaDelay ;
00082 unsigned int timeAdvance ;
00083 unsigned int deltaBlocks ;
00084 bool keepCepstra = true ;
00085
00086 String inputFeatureFileName =config.getParam("inputFeatureFilename");
00087 if (config.existsParam("vectSize")) numCeps = config.getParam("vectSize").toLong();
00088 deltaDelay = config.getParam("SDCdeltaDelay").toLong();
00089 timeAdvance = config.getParam("SDCtimeAdvance").toLong();
00090 deltaBlocks = config.getParam("SDCdeltaBlocks").toLong();
00091 if (config.existsParam("SDCkeepCepstra")) keepCepstra = config.getParam("SDCkeepCepstra").toBool();
00092 if (verbose){
00093 cout << "ShiftedDeltaFeat: SDC parameters (N-d-P-k) are: ["<<numCeps<<"-"<<deltaDelay<<"-"<<timeAdvance<<"-"<<deltaBlocks<<"]" << endl;
00094 }
00095 if(debug) cout << "SDC parameters: SDCkeepCepstra["<<keepCepstra<<"] vectSize=numCeps["<<numCeps<<"] SDCdeltaDelay["<<deltaDelay<<"] SDCtimeAdvance["<<timeAdvance<<"] SDCdeltaBlocks["<<deltaBlocks<<"]" << endl;
00096
00097
00098
00099 XLine inputFeatureFileNameList;
00100 if ( inputFeatureFileName.endsWith(".lst")){
00101 XList inputFileNameXList(inputFeatureFileName,config);
00102 inputFeatureFileNameList=inputFileNameXList.getAllElements();
00103 }
00104 else {
00105 inputFeatureFileNameList.addElement(inputFeatureFileName);
00106 }
00107 try{
00108 String *file;
00109 while ((file=inputFeatureFileNameList.getElement())!= NULL){
00110
00111 String & featureFileName=(*file);
00112 FeatureServer fs(config,featureFileName);
00113 if(!numCeps) numCeps = fs.getVectSize();
00114 unsigned long numFeats = fs.getFeatureCount() ;
00115
00116 Feature lowerFeat ;
00117 Feature upperFeat ;
00118 unsigned int cepFeatsInBase = (keepCepstra) ? numCeps : 0 ;
00119 unsigned int shiftedDeltaVectSize = cepFeatsInBase + (deltaBlocks*numCeps) ;
00120
00121 Config configOut( config) ;
00122 configOut.setParam("vectSize", String::valueOf(shiftedDeltaVectSize) ) ;
00123 configOut.setParam("featureServerMask", "0-"+String::valueOf(shiftedDeltaVectSize-1)) ;
00124 cout << "ShiftedDeltaFeat: numCeps["<<numCeps<<"] vectSize["<<fs.getVectSize()<<"] numFeats["<<fs.getFeatureCount()<<"] keepCeps["<<keepCepstra<<"] cepsInBase["<<cepFeatsInBase<<"] OUTnumFeats["<<shiftedDeltaVectSize<<"] OUTcfgVectSize["<<configOut.getParam("vectSize")<<"]" <<endl;
00125
00126 FeatureServer fsOut(configOut);
00127 if(debug) cout << "FeatureServer fsOut instantiated" << endl ;
00128
00129
00130 if (!(configOut.existsParam("featureFlags")))
00131 configOut.setParam("featureFlags",fs.getFeatureFlags().getString());
00132 cout << "Writing to: " << featureFileName << endl;
00133 FeatureFileWriter w(featureFileName, configOut);
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 for( unsigned long currentTime=0; currentTime<numFeats; currentTime++) {
00147
00148
00149 Feature shiftedDeltaFeature( shiftedDeltaVectSize) ;
00150
00151
00152
00153
00154 if( cepFeatsInBase > 0) {
00155 assert( cepFeatsInBase==numCeps) ;
00156 Feature cepFeats;
00157 fs.seekFeature( currentTime) ;
00158 fs.readFeature( cepFeats,0) ;
00159
00160 for( unsigned int i=0; i<numCeps; i++) {
00161 shiftedDeltaFeature[i] = cepFeats[i] ;
00162 }
00163 }
00164
00165
00166 for( unsigned int currentDeltaBlock=0; currentDeltaBlock<deltaBlocks; currentDeltaBlock++) {
00167
00168 int lowerTime = currentTime + (currentDeltaBlock*timeAdvance) - deltaDelay ;
00169 unsigned int upperTime = currentTime + (currentDeltaBlock*timeAdvance) + deltaDelay ;
00170
00171
00172 if( lowerTime < 0 ) lowerTime = 0 ;
00173 if( (unsigned long)lowerTime >= numFeats) lowerTime = numFeats-1 ;
00174 if( upperTime >= numFeats) upperTime = numFeats-1 ;
00175
00176 if (debug || (verboseLevel>2)) cout << "t["<<currentTime<<"] block["<<currentDeltaBlock<<"] lowerT["<<lowerTime<<"] upperT["<<upperTime<<"]" <<endl ;
00177
00178
00179 fs.seekFeature( lowerTime) ;
00180
00181 fs.readFeature( lowerFeat, 0);
00182 if (debug || (verboseLevel>2)) { cout << " lowerFeat[" ; for(unsigned int i=0; i<lowerFeat.getVectSize();i++){ cout<<lowerFeat[i]<<" " ;} ; cout <<"]"<< endl; }
00183 fs.seekFeature( upperTime) ;
00184 fs.readFeature( upperFeat);
00185 if (debug || (verboseLevel>2)) { cout << " upperFeat[" ; for(unsigned int i=0; i<upperFeat.getVectSize();i++){ cout<<upperFeat[i]<<" " ;} ; cout <<"]"<< endl; }
00186
00187
00188 Feature deltaBlockFeature( numCeps) ;
00189 for( unsigned int i=0; i<numCeps; i++) {
00190 deltaBlockFeature[i] = upperFeat[i] - lowerFeat[i] ;
00191 }
00192 if (debug || (verboseLevel>2)) { cout << " deltaFeat[" ; for(unsigned int i=0; i<deltaBlockFeature.getVectSize();i++){ cout<<deltaBlockFeature[i]<<" " ;} ; cout <<"]"<< endl; }
00193
00194
00195 unsigned int blockBase = cepFeatsInBase + (currentDeltaBlock*numCeps) ;
00196 if (debug || (verboseLevel>2)) cout << " blkBase["<<blockBase<<"] cepsInBase["<<cepFeatsInBase<<"] curD Blk["<<currentDeltaBlock<<"]" << endl;
00197
00198
00199
00200 for( unsigned int i=0; i<deltaBlockFeature.getVectSize(); i++) {
00201 shiftedDeltaFeature[blockBase+i] = deltaBlockFeature[i] ;
00202 }
00203 if (debug || (verboseLevel>2)) { cout << " ShDltFeat[" ; for(unsigned int i=0; i<shiftedDeltaFeature.getVectSize();i++){ cout<<shiftedDeltaFeature[i]<<" " ;} ; cout <<"]"<< endl; }
00204 }
00205
00206
00207 if (debug || (verboseLevel>2)){ cout << "WRITE: t["<<currentTime<<"] ShDltFeat[" ; for(unsigned int i=0; i<shiftedDeltaFeature.getVectSize();i++){ cout<<shiftedDeltaFeature[i]<<" " ;} ; cout <<"]"<< endl; }
00208 w.writeFeature( shiftedDeltaFeature) ;
00209 }
00211 if (debug || (verboseLevel>2)){ cout <<"SDC, number of frames= ["<<fsOut.getFeatureCount()<<"]"<<endl; }
00212
00213 }
00214
00215 }
00216
00217 catch (Exception & e)
00218 {
00219 cout << e.toString ().c_str () << endl;
00220 }
00221 return 0;
00222 }
00223
00224
00225 #endif // !defined(ALIZE_ShiftedDeltaFeat_cpp)
00226