NOOP, remove trailing tabs/whitespace.
[ardour.git] / libs / qm-dsp / dsp / segmentation / ClusterMeltSegmenter.h
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3 /*
4  * ClusterMeltSegmenter.h
5  *
6  * Created by Mark Levy on 23/03/2006.
7  * Copyright 2006 Centre for Digital Music, Queen Mary, University of London.
8
9     This program is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public License as
11     published by the Free Software Foundation; either version 2 of the
12     License, or (at your option) any later version.  See the file
13     COPYING included with this distribution for more information.
14  */
15
16 #include <vector>
17
18 #include "segment.h"
19 #include "Segmenter.h"
20 #include "hmm/hmm.h"
21 #include "base/Window.h"
22
23 using std::vector;
24
25 class Decimator;
26 class ConstantQ;
27 class MFCC;
28 class FFTReal;
29
30 class ClusterMeltSegmenterParams
31 // defaults are sensible for 11025Hz with 0.2 second hopsize
32 {
33 public:
34     ClusterMeltSegmenterParams() :
35         featureType(FEATURE_TYPE_CONSTQ),
36         hopSize(0.2),
37         windowSize(0.6),
38         fmin(62),
39         fmax(16000),
40         nbins(8),
41         ncomponents(20),
42         nHMMStates(40),
43         nclusters(10),
44         histogramLength(15),
45         neighbourhoodLimit(20) { }
46     feature_types featureType;
47     double hopSize;     // in secs
48     double windowSize;  // in secs
49     int fmin;
50     int fmax;
51     int nbins;
52     int ncomponents;
53     int nHMMStates;
54     int nclusters;
55     int histogramLength;
56     int neighbourhoodLimit;
57 };
58
59 class ClusterMeltSegmenter : public Segmenter
60 {
61 public:
62     ClusterMeltSegmenter(ClusterMeltSegmenterParams params);
63     virtual ~ClusterMeltSegmenter();
64     virtual void initialise(int samplerate);
65     virtual int getWindowsize();
66     virtual int getHopsize();
67     virtual void extractFeatures(const double* samples, int nsamples);
68     void setFeatures(const vector<vector<double> >& f);         // provide the features yourself
69     virtual void segment();             // segment into default number of segment-types
70     void segment(int m);                // segment into m segment-types
71     int getNSegmentTypes() { return nclusters; }
72
73 protected:
74     void makeSegmentation(int* q, int len);
75
76     void extractFeaturesConstQ(const double *, int);
77     void extractFeaturesMFCC(const double *, int);
78
79     Window<double> *window;
80     FFTReal *fft;
81     ConstantQ* constq;
82     MFCC* mfcc;
83     model_t* model;                             // the HMM
84     int* q;                                     // the decoded HMM state sequence
85     vector<vector<double> > histograms;
86
87     feature_types featureType;
88     double hopSize;             // in seconds
89     double windowSize;  // in seconds
90
91     // constant-Q parameters
92     int fmin;
93     int fmax;
94     int nbins;
95     int ncoeff;
96
97     // PCA parameters
98     int ncomponents;
99
100     // HMM parameters
101     int nHMMStates;
102
103     // clustering parameters
104     int nclusters;
105     int histogramLength;
106     int neighbourhoodLimit;
107
108     Decimator *decimator;
109 };