annotate dsp/segmentation/ClusterMeltSegmenter.h @ 64:6cb2b3cd5356

* Refactor FFT a little bit so as to separate construction and processing rather than have a single static method -- will make it easier to use a different implementation * pull in KissFFT implementation (not hooked up yet)
author cannam
date Wed, 13 May 2009 09:19:12 +0000
parents d096a79fa772
children e5907ae6de17
rev   line source
cannam@24 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@24 2
cannam@18 3 /*
cannam@24 4 * ClusterMeltSegmenter.h
cannam@18 5 *
cannam@24 6 * Created by Mark Levy on 23/03/2006.
cannam@24 7 * Copyright 2006 Centre for Digital Music, Queen Mary, University of London.
cannam@24 8 * All rights reserved.
cannam@18 9 */
cannam@18 10
cannam@18 11 #include <vector>
cannam@18 12
cannam@18 13 #include "segment.h"
cannam@18 14 #include "Segmenter.h"
cannam@20 15 #include "hmm/hmm.h"
cannam@20 16 #include "base/Window.h"
cannam@18 17
cannam@18 18 using std::vector;
cannam@18 19
cannam@24 20 class Decimator;
cannam@24 21 class ConstantQ;
cannam@26 22 class MFCC;
cannam@64 23 class FFTReal;
cannam@24 24
cannam@24 25 class ClusterMeltSegmenterParams
cannam@24 26 // defaults are sensible for 11025Hz with 0.2 second hopsize
cannam@18 27 {
cannam@18 28 public:
cannam@24 29 ClusterMeltSegmenterParams() :
cannam@24 30 featureType(FEATURE_TYPE_CONSTQ),
cannam@24 31 hopSize(0.2),
cannam@24 32 windowSize(0.6),
cannam@24 33 fmin(62),
cannam@24 34 fmax(16000),
cannam@24 35 nbins(8),
cannam@24 36 ncomponents(20),
cannam@24 37 nHMMStates(40),
cannam@24 38 nclusters(10),
cannam@24 39 histogramLength(15),
cannam@24 40 neighbourhoodLimit(20) { }
cannam@24 41 feature_types featureType;
cannam@24 42 double hopSize; // in secs
cannam@24 43 double windowSize; // in secs
cannam@24 44 int fmin;
cannam@24 45 int fmax;
cannam@24 46 int nbins;
cannam@24 47 int ncomponents;
cannam@24 48 int nHMMStates;
cannam@24 49 int nclusters;
cannam@24 50 int histogramLength;
cannam@24 51 int neighbourhoodLimit;
cannam@18 52 };
cannam@18 53
cannam@18 54 class ClusterMeltSegmenter : public Segmenter
cannam@18 55 {
cannam@18 56 public:
cannam@24 57 ClusterMeltSegmenter(ClusterMeltSegmenterParams params);
cannam@24 58 virtual ~ClusterMeltSegmenter();
cannam@24 59 virtual void initialise(int samplerate);
cannam@24 60 virtual int getWindowsize();
cannam@24 61 virtual int getHopsize();
cannam@24 62 virtual void extractFeatures(const double* samples, int nsamples);
cannam@24 63 void setFeatures(const vector<vector<double> >& f); // provide the features yourself
cannam@24 64 virtual void segment(); // segment into default number of segment-types
cannam@24 65 void segment(int m); // segment into m segment-types
cannam@24 66 int getNSegmentTypes() { return nclusters; }
cannam@24 67
cannam@18 68 protected:
cannam@24 69 void makeSegmentation(int* q, int len);
cannam@18 70
cannam@26 71 void extractFeaturesConstQ(const double *, int);
cannam@26 72 void extractFeaturesMFCC(const double *, int);
cannam@26 73
cannam@24 74 Window<double> *window;
cannam@64 75 FFTReal *fft;
cannam@26 76 ConstantQ* constq;
cannam@26 77 MFCC* mfcc;
cannam@24 78 model_t* model; // the HMM
cannam@24 79 int* q; // the decoded HMM state sequence
cannam@24 80 vector<vector<double> > histograms;
cannam@24 81
cannam@24 82 feature_types featureType;
cannam@24 83 double hopSize; // in seconds
cannam@24 84 double windowSize; // in seconds
cannam@24 85
cannam@24 86 // constant-Q parameters
cannam@24 87 int fmin;
cannam@24 88 int fmax;
cannam@24 89 int nbins;
cannam@24 90 int ncoeff;
cannam@24 91
cannam@24 92 // PCA parameters
cannam@24 93 int ncomponents;
cannam@24 94
cannam@24 95 // HMM parameters
cannam@24 96 int nHMMStates;
cannam@24 97
cannam@24 98 // clustering parameters
cannam@24 99 int nclusters;
cannam@24 100 int histogramLength;
cannam@24 101 int neighbourhoodLimit;
cannam@24 102
cannam@24 103 Decimator *decimator;
cannam@18 104 };