comparison dsp/segmentation/ClusterMeltSegmenter.cpp @ 480:175e51ae78eb

Untabify, indent, tidy
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 31 May 2019 10:53:39 +0100
parents 7e8d1f26b098
children bb78ca3fe7de
comparison
equal deleted inserted replaced
479:7e52c034cf62 480:175e51ae78eb
34 hopSize(params.hopSize), 34 hopSize(params.hopSize),
35 windowSize(params.windowSize), 35 windowSize(params.windowSize),
36 fmin(params.fmin), 36 fmin(params.fmin),
37 fmax(params.fmax), 37 fmax(params.fmax),
38 nbins(params.nbins), 38 nbins(params.nbins),
39 ncomponents(params.ncomponents), // NB currently not passed - no. of PCA components is set in cluser_segmenter.c 39 ncomponents(params.ncomponents), // NB currently not passed - no. of PCA components is set in cluser_segmenter.c
40 nHMMStates(params.nHMMStates), 40 nHMMStates(params.nHMMStates),
41 nclusters(params.nclusters), 41 nclusters(params.nclusters),
42 histogramLength(params.histogramLength), 42 histogramLength(params.histogramLength),
43 neighbourhoodLimit(params.neighbourhoodLimit), 43 neighbourhoodLimit(params.neighbourhoodLimit),
44 decimator(NULL) 44 decimator(NULL)
210 window->cut(frame); 210 window->cut(frame);
211 211
212 fft->forward(frame, real, imag); 212 fft->forward(frame, real, imag);
213 213
214 constq->process(real, imag, cqre, cqim); 214 constq->process(real, imag, cqre, cqim);
215 215
216 for (int i = 0; i < ncoeff; ++i) { 216 for (int i = 0; i < ncoeff; ++i) {
217 cq[i] += sqrt(cqre[i] * cqre[i] + cqim[i] * cqim[i]); 217 cq[i] += sqrt(cqre[i] * cqre[i] + cqim[i] * cqim[i]);
218 } 218 }
219 ++frames; 219 ++frames;
220 220
285 frame[i] = 0.0; 285 frame[i] = 0.0;
286 } 286 }
287 } 287 }
288 288
289 mfcc->process(frame, ccout); 289 mfcc->process(frame, ccout);
290 290
291 for (int i = 0; i < ncoeff; ++i) { 291 for (int i = 0; i < ncoeff; ++i) {
292 cc[i] += ccout[i]; 292 cc[i] += ccout[i];
293 } 293 }
294 ++frames; 294 ++frames;
295 295
335 /* 335 /*
336 std::cerr << "ClusterMeltSegmenter::segment: have " << features.size() 336 std::cerr << "ClusterMeltSegmenter::segment: have " << features.size()
337 << " features with " << features[0].size() << " coefficients (ncoeff = " << ncoeff << ", ncomponents = " << ncomponents << ")" << std::endl; 337 << " features with " << features[0].size() << " coefficients (ncoeff = " << ncoeff << ", ncomponents = " << ncomponents << ")" << std::endl;
338 */ 338 */
339 // copy the features to a native array and use the existing C segmenter... 339 // copy the features to a native array and use the existing C segmenter...
340 double** arrFeatures = new double*[features.size()]; 340 double** arrFeatures = new double*[features.size()];
341 for (int i = 0; i < sz; i++) 341 for (int i = 0; i < sz; i++) {
342 {
343 if (featureType == FEATURE_TYPE_UNKNOWN) { 342 if (featureType == FEATURE_TYPE_UNKNOWN) {
344 arrFeatures[i] = new double[features[0].size()]; 343 arrFeatures[i] = new double[features[0].size()];
345 for (int j = 0; j < int(features[0].size()); j++) { 344 for (int j = 0; j < int(features[0].size()); j++) {
346 arrFeatures[i][j] = features[i][j]; 345 arrFeatures[i][j] = features[i][j];
347 } 346 }
348 } else { 347 } else {
349 arrFeatures[i] = new double[ncoeff+1]; // allow space for the normalised envelope 348 arrFeatures[i] = new double[ncoeff+1]; // allow space for the normalised envelope
350 for (int j = 0; j < ncoeff; j++) { 349 for (int j = 0; j < ncoeff; j++) {
351 arrFeatures[i][j] = features[i][j]; 350 arrFeatures[i][j] = features[i][j];
352 } 351 }
353 } 352 }
354 } 353 }
355 354
356 q = new int[features.size()]; 355 q = new int[features.size()];
357 356
358 if (featureType == FEATURE_TYPE_UNKNOWN || 357 if (featureType == FEATURE_TYPE_UNKNOWN ||
359 featureType == FEATURE_TYPE_MFCC) 358 featureType == FEATURE_TYPE_MFCC) {
360 cluster_segment(q, arrFeatures, features.size(), features[0].size(), nHMMStates, histogramLength, 359 cluster_segment(q, arrFeatures, features.size(), features[0].size(), nHMMStates, histogramLength,
361 nclusters, neighbourhoodLimit); 360 nclusters, neighbourhoodLimit);
362 else 361 } else {
363 constq_segment(q, arrFeatures, features.size(), nbins, ncoeff, featureType, 362 constq_segment(q, arrFeatures, features.size(), nbins, ncoeff, featureType,
364 nHMMStates, histogramLength, nclusters, neighbourhoodLimit); 363 nHMMStates, histogramLength, nclusters, neighbourhoodLimit);
365 364 }
365
366 // convert the cluster assignment sequence to a segmentation 366 // convert the cluster assignment sequence to a segmentation
367 makeSegmentation(q, features.size()); 367 makeSegmentation(q, features.size());
368 368
369 // de-allocate arrays 369 // de-allocate arrays
370 delete [] q; 370 delete [] q;
371 for (int i = 0; i < int(features.size()); i++) delete [] arrFeatures[i]; 371 for (int i = 0; i < int(features.size()); i++) delete [] arrFeatures[i];
372 delete [] arrFeatures; 372 delete [] arrFeatures;
373 373
374 // clear the features 374 // clear the features
375 clear(); 375 clear();
376 } 376 }
377 377
378 void ClusterMeltSegmenter::makeSegmentation(int* q, int len) 378 void ClusterMeltSegmenter::makeSegmentation(int* q, int len)
379 { 379 {
380 segmentation.segments.clear(); 380 segmentation.segments.clear();
381 segmentation.nsegtypes = nclusters; 381 segmentation.nsegtypes = nclusters;
382 segmentation.samplerate = samplerate; 382 segmentation.samplerate = samplerate;
383 383
384 Segment segment; 384 Segment segment;
385 segment.start = 0; 385 segment.start = 0;
386 segment.type = q[0]; 386 segment.type = q[0];
387 387
388 for (int i = 1; i < len; i++) 388 for (int i = 1; i < len; i++) {
389 { 389 if (q[i] != q[i-1]) {
390 if (q[i] != q[i-1])
391 {
392 segment.end = i * getHopsize(); 390 segment.end = i * getHopsize();
393 segmentation.segments.push_back(segment); 391 segmentation.segments.push_back(segment);
394 segment.type = q[i]; 392 segment.type = q[i];
395 segment.start = segment.end; 393 segment.start = segment.end;
396 } 394 }