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