Mercurial > hg > qm-dsp
comparison dsp/segmentation/ClusterMeltSegmenter.cpp @ 252:89a2b34a098f
* Adjust MFCC params in segmenter to match timbral MFCC params from Soundbite
| author | Chris Cannam <c.cannam@qmul.ac.uk> |
|---|---|
| date | Thu, 10 Jan 2008 17:26:15 +0000 |
| parents | c3600d3cfe5c |
| children | a251fb0de594 |
comparison
equal
deleted
inserted
replaced
| 251:c3600d3cfe5c | 252:89a2b34a098f |
|---|---|
| 74 | 74 |
| 75 ncoeff = constq->getK(); | 75 ncoeff = constq->getK(); |
| 76 | 76 |
| 77 } else if (featureType == FEATURE_TYPE_MFCC) { | 77 } else if (featureType == FEATURE_TYPE_MFCC) { |
| 78 | 78 |
| 79 // run internal processing at 22050 or thereabouts | |
| 80 int internalRate = 22050; | |
| 81 int decimationFactor = samplerate / internalRate; | |
| 82 if (decimationFactor < 1) decimationFactor = 1; | |
| 83 | |
| 84 // must be a power of two | |
| 85 while (decimationFactor & (decimationFactor - 1)) ++decimationFactor; | |
| 86 | |
| 87 if (decimationFactor > Decimator::getHighestSupportedFactor()) { | |
| 88 decimationFactor = Decimator::getHighestSupportedFactor(); | |
| 89 } | |
| 90 | |
| 91 if (decimationFactor > 1) { | |
| 92 decimator = new Decimator(getWindowsize(), decimationFactor); | |
| 93 } | |
| 94 | |
| 79 MFCCConfig config; | 95 MFCCConfig config; |
| 80 config.FS = samplerate; | 96 config.FS = samplerate / decimationFactor; |
| 81 config.fftsize = 1024; | 97 config.fftsize = 2048; |
| 82 config.nceps = 20; | 98 config.nceps = 19; |
| 83 config.want_c0 = false; | 99 config.want_c0 = true; |
| 84 | 100 |
| 85 mfcc = new MFCC(config); | 101 mfcc = new MFCC(config); |
| 86 ncoeff = config.nceps; | 102 ncoeff = config.nceps + 1; |
| 87 } | 103 } |
| 88 } | 104 } |
| 89 | 105 |
| 90 ClusterMeltSegmenter::~ClusterMeltSegmenter() | 106 ClusterMeltSegmenter::~ClusterMeltSegmenter() |
| 91 { | 107 { |
| 233 for (int i = 0; i < ncoeff; ++i) cc[i] = 0.0; | 249 for (int i = 0; i < ncoeff; ++i) cc[i] = 0.0; |
| 234 | 250 |
| 235 const double *psource = samples; | 251 const double *psource = samples; |
| 236 int pcount = nsamples; | 252 int pcount = nsamples; |
| 237 | 253 |
| 254 if (decimator) { | |
| 255 pcount = nsamples / decimator->getFactor(); | |
| 256 double *decout = new double[pcount]; | |
| 257 decimator->process(samples, decout); | |
| 258 psource = decout; | |
| 259 } | |
| 260 | |
| 238 int origin = 0; | 261 int origin = 0; |
| 239 int frames = 0; | 262 int frames = 0; |
| 240 | 263 |
| 241 double *frame = new double[fftsize]; | 264 double *frame = new double[fftsize]; |
| 242 double *ccout = new double[ncoeff]; | 265 double *ccout = new double[ncoeff]; |
| 269 delete [] frame; | 292 delete [] frame; |
| 270 | 293 |
| 271 for (int i = 0; i < ncoeff; ++i) { | 294 for (int i = 0; i < ncoeff; ++i) { |
| 272 cc[i] /= frames; | 295 cc[i] /= frames; |
| 273 } | 296 } |
| 297 | |
| 298 if (decimator) delete[] psource; | |
| 274 | 299 |
| 275 features.push_back(cc); | 300 features.push_back(cc); |
| 276 } | 301 } |
| 277 | 302 |
| 278 void ClusterMeltSegmenter::segment(int m) | 303 void ClusterMeltSegmenter::segment(int m) |
