Mercurial > hg > qm-vamp-plugins
comparison plugins/AdaptiveSpectrogram.h @ 100:bae940a2ff18
* some experiments in working from the original paper for the adaptive
spectrogram (to be continued)
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Mon, 27 Apr 2009 15:30:05 +0000 |
parents | 8700a93424f4 |
children | ef22bed1626a |
comparison
equal
deleted
inserted
replaced
99:8700a93424f4 | 100:bae940a2ff18 |
---|---|
53 inline double xlogx(double x) { | 53 inline double xlogx(double x) { |
54 if (x == 0.0) return 0.0; | 54 if (x == 0.0) return 0.0; |
55 else return x * log(x); | 55 else return x * log(x); |
56 } | 56 } |
57 | 57 |
58 struct Spectrogram | |
59 { | |
60 int resolution; | |
61 int width; | |
62 double **data; | |
63 | |
64 Spectrogram(int r, int w) : | |
65 resolution(r), width(w) { | |
66 data = new double *[width]; | |
67 for (int i = 0; i < width; ++i) data[i] = new double[resolution]; | |
68 } | |
69 | |
70 ~Spectrogram() { | |
71 for (int i = 0; i < width; ++i) delete[] data[i]; | |
72 delete[] data; | |
73 } | |
74 }; | |
75 | |
76 struct Spectrograms | |
77 { | |
78 int minres; | |
79 int maxres; | |
80 int n; | |
81 Spectrogram **spectrograms; | |
82 | |
83 Spectrograms(int mn, int mx, int widthofmax) : | |
84 minres(mn), maxres(mx) { | |
85 n = log2(maxres/minres) + 1; | |
86 spectrograms = new Spectrogram *[n]; | |
87 int r = mn; | |
88 for (int i = 0; i < n; ++i) { | |
89 spectrograms[i] = new Spectrogram(r, widthofmax * (mx / r)); | |
90 r = r * 2; | |
91 } | |
92 } | |
93 ~Spectrograms() { | |
94 for (int i = 0; i < n; ++i) { | |
95 delete spectrograms[i]; | |
96 } | |
97 delete[] spectrograms; | |
98 } | |
99 }; | |
100 | |
101 struct Cutting | |
102 { | |
103 enum Cut { Horizontal, Vertical, Finished }; | |
104 Cut cut; | |
105 Cutting *first; | |
106 Cutting *second; | |
107 double cost; | |
108 double value; | |
109 | |
110 ~Cutting() { | |
111 delete first; | |
112 delete second; | |
113 } | |
114 }; | |
115 | |
116 double cost(const Spectrogram &s, int x, int y) { | |
117 return xlogx(s.data[x][y]); | |
118 } | |
119 | |
120 double value(const Spectrogram &s, int x, int y) { | |
121 return s.data[x][y]; | |
122 } | |
123 | |
124 Cutting *cut(const Spectrograms &, int res, int x, int y, int h); | |
125 | |
126 void printCutting(Cutting *, std::string); | |
127 | |
128 void assemble(const Spectrograms &, const Cutting *, std::vector<std::vector<float> > &, int x, int y, int w, int h); | |
129 | |
58 void unpackResultMatrix(std::vector<std::vector<float> > &rmat, | 130 void unpackResultMatrix(std::vector<std::vector<float> > &rmat, |
59 int x, int y, int w, int h, | 131 int x, int y, int w, int h, |
60 int *spl, | 132 int *spl, |
61 double *spec, int specsz, int res); | 133 double *spec, int specsz, int res); |
62 | 134 |