qm-dsp  1.8
ClusterMeltSegmenter.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004  * ClusterMeltSegmenter.h
00005  *
00006  * Created by Mark Levy on 23/03/2006.
00007  * Copyright 2006 Centre for Digital Music, Queen Mary, University of London.
00008 
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014  */
00015 
00016 #include <vector>
00017 
00018 #include "segment.h"
00019 #include "Segmenter.h"
00020 #include "hmm/hmm.h"
00021 #include "base/Window.h"
00022 
00023 using std::vector;
00024 
00025 class Decimator;
00026 class ConstantQ;
00027 class MFCC;
00028 class FFTReal;
00029 
00030 class ClusterMeltSegmenterParams
00031 // defaults are sensible for 11025Hz with 0.2 second hopsize
00032 {
00033 public:
00034     ClusterMeltSegmenterParams() : 
00035         featureType(FEATURE_TYPE_CONSTQ),
00036         hopSize(0.2),
00037         windowSize(0.6),
00038         fmin(62),
00039         fmax(16000), 
00040         nbins(8),
00041         ncomponents(20),
00042         nHMMStates(40),
00043         nclusters(10),
00044         histogramLength(15),
00045         neighbourhoodLimit(20) { }
00046     feature_types featureType;
00047     double hopSize;     // in secs
00048     double windowSize;  // in secs
00049     int fmin;
00050     int fmax;
00051     int nbins;
00052     int ncomponents;
00053     int nHMMStates;
00054     int nclusters;
00055     int histogramLength;
00056     int neighbourhoodLimit;
00057 };
00058 
00059 class ClusterMeltSegmenter : public Segmenter
00060 {
00061 public:
00062     ClusterMeltSegmenter(ClusterMeltSegmenterParams params);
00063     virtual ~ClusterMeltSegmenter();
00064     virtual void initialise(int samplerate);
00065     virtual int getWindowsize();
00066     virtual int getHopsize();
00067     virtual void extractFeatures(const double* samples, int nsamples);
00068     void setFeatures(const vector<vector<double> >& f);         // provide the features yourself
00069     virtual void segment();             // segment into default number of segment-types
00070     void segment(int m);                // segment into m segment-types
00071     int getNSegmentTypes() { return nclusters; }
00072 
00073 protected:
00074     void makeSegmentation(int* q, int len);
00075         
00076     void extractFeaturesConstQ(const double *, int);
00077     void extractFeaturesMFCC(const double *, int);
00078 
00079     Window<double> *window;
00080     FFTReal *fft;
00081     ConstantQ* constq; 
00082     MFCC* mfcc;
00083     model_t* model;                             // the HMM
00084     int* q;                                     // the decoded HMM state sequence
00085     vector<vector<double> > histograms; 
00086     
00087     feature_types featureType;  
00088     double hopSize;             // in seconds
00089     double windowSize;  // in seconds
00090     
00091     // constant-Q parameters
00092     int fmin;
00093     int fmax;
00094     int nbins;
00095     int ncoeff;
00096     
00097     // PCA parameters
00098     int ncomponents;
00099     
00100     // HMM parameters
00101     int nHMMStates;
00102     
00103     // clustering parameters
00104     int nclusters;
00105     int histogramLength;
00106     int neighbourhoodLimit;
00107 
00108     Decimator *decimator;
00109 };