Mercurial > hg > qm-dsp
view dsp/segmentation/SavedFeatureSegmenter.cpp @ 298:255e431ae3d4
* Key detector: when returning key strengths, use the peak value of the
three underlying chromagram correlations (from 36-bin chromagram)
corresponding to each key, instead of the mean.
Rationale: This is the same method as used when returning the key value,
and it's nice to have the same results in both returned value and plot.
The peak performed better than the sum with a simple test set of triads,
so it seems reasonable to change the plot to match the key output rather
than the other way around.
* FFT: kiss_fftr returns only the non-conjugate bins, synthesise the rest
rather than leaving them (perhaps dangerously) undefined. Fixes an
uninitialised data error in chromagram that could cause garbage results
from key detector.
* Constant Q: remove precalculated values again, I reckon they're not
proving such a good tradeoff.
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 05 Jun 2009 15:12:39 +0000 |
parents | dc30e3864ceb |
children |
line wrap: on
line source
/* * SavedFeatureSegmenter.cpp * soundbite * * Created by Mark Levy on 23/03/2006. * Copyright 2006 Centre for Digital Music, Queen Mary, University of London. All rights reserved. * */ #include <cfloat> #include <cmath> #include "SavedFeatureSegmenter.h" #include "cluster_segmenter.h" #include "segment.h" SavedFeatureSegmenter::SavedFeatureSegmenter(SavedFeatureSegmenterParams params) : windowSize(params.windowSize), hopSize(params.hopSize), nHMMStates(params.nHMMStates), nclusters(params.nclusters), histogramLength(params.histogramLength), neighbourhoodLimit(params.neighbourhoodLimit) { } void SavedFeatureSegmenter::initialise(int fs) { samplerate = fs; } SavedFeatureSegmenter::~SavedFeatureSegmenter() { } void SavedFeatureSegmenter::segment(int m) { nclusters = m; segment(); } void SavedFeatureSegmenter::setFeatures(const vector<vector<double> >& f) { features = f; } void SavedFeatureSegmenter::segment() { // for now copy the features to a native array and use the existing C segmenter... double** arrFeatures = new double*[features.size()]; for (int i = 0; i < features.size(); i++) { arrFeatures[i] = new double[features[0].size()]; // allow space for the normalised envelope for (int j = 0; j < features[0].size(); j++) arrFeatures[i][j] = features[i][j]; } q = new int[features.size()]; cluster_segment(q, arrFeatures, features.size(), features[0].size(), nHMMStates, histogramLength, nclusters, neighbourhoodLimit); // convert the cluster assignment sequence to a segmentation makeSegmentation(q, features.size()); // de-allocate arrays delete [] q; for (int i = 0; i < features.size(); i++) delete [] arrFeatures[i]; delete [] arrFeatures; // clear the features clear(); } void SavedFeatureSegmenter::makeSegmentation(int* q, int len) { segmentation.segments.clear(); segmentation.nsegtypes = nclusters; segmentation.samplerate = samplerate; Segment segment; segment.start = 0; segment.type = q[0]; for (int i = 1; i < len; i++) { if (q[i] != q[i-1]) { segment.end = i * getHopsize(); segmentation.segments.push_back(segment); segment.type = q[i]; segment.start = segment.end; } } segment.end = len * getHopsize(); segmentation.segments.push_back(segment); }