annotate 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
rev   line source
c@92 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@92 2
c@92 3 /*
c@92 4 QM Vamp Plugin Set
c@92 5
c@92 6 Centre for Digital Music, Queen Mary, University of London.
c@92 7 All rights reserved.
c@92 8 */
c@92 9
c@92 10 #ifndef _ADAPTIVE_SPECTROGRAM_H_
c@92 11 #define _ADAPTIVE_SPECTROGRAM_H_
c@92 12
c@92 13 #include <vamp-sdk/Plugin.h>
c@92 14 #include <cmath>
c@92 15 #include <vector>
c@92 16
c@92 17 class AdaptiveSpectrogram : public Vamp::Plugin
c@92 18 {
c@92 19 public:
c@92 20 AdaptiveSpectrogram(float inputSampleRate);
c@92 21 virtual ~AdaptiveSpectrogram();
c@92 22
c@92 23 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
c@92 24 void reset();
c@92 25
c@92 26 InputDomain getInputDomain() const { return TimeDomain; }
c@92 27
c@92 28 std::string getIdentifier() const;
c@92 29 std::string getName() const;
c@92 30 std::string getDescription() const;
c@92 31 std::string getMaker() const;
c@92 32 int getPluginVersion() const;
c@92 33 std::string getCopyright() const;
c@92 34
c@92 35 size_t getPreferredStepSize() const;
c@92 36 size_t getPreferredBlockSize() const;
c@92 37
c@92 38 ParameterList getParameterDescriptors() const;
c@92 39 float getParameter(std::string id) const;
c@92 40 void setParameter(std::string id, float value);
c@92 41
c@92 42 OutputList getOutputDescriptors() const;
c@92 43
c@92 44 FeatureSet process(const float *const *inputBuffers,
c@92 45 Vamp::RealTime timestamp);
c@92 46
c@92 47 FeatureSet getRemainingFeatures();
c@92 48
c@92 49 protected:
c@92 50 int m_w;
c@92 51 int m_n;
c@92 52
c@92 53 inline double xlogx(double x) {
c@92 54 if (x == 0.0) return 0.0;
c@92 55 else return x * log(x);
c@92 56 }
c@92 57
c@100 58 struct Spectrogram
c@100 59 {
c@100 60 int resolution;
c@100 61 int width;
c@100 62 double **data;
c@100 63
c@100 64 Spectrogram(int r, int w) :
c@100 65 resolution(r), width(w) {
c@100 66 data = new double *[width];
c@100 67 for (int i = 0; i < width; ++i) data[i] = new double[resolution];
c@100 68 }
c@100 69
c@100 70 ~Spectrogram() {
c@100 71 for (int i = 0; i < width; ++i) delete[] data[i];
c@100 72 delete[] data;
c@100 73 }
c@100 74 };
c@100 75
c@100 76 struct Spectrograms
c@100 77 {
c@100 78 int minres;
c@100 79 int maxres;
c@100 80 int n;
c@100 81 Spectrogram **spectrograms;
c@100 82
c@100 83 Spectrograms(int mn, int mx, int widthofmax) :
c@100 84 minres(mn), maxres(mx) {
c@100 85 n = log2(maxres/minres) + 1;
c@100 86 spectrograms = new Spectrogram *[n];
c@100 87 int r = mn;
c@100 88 for (int i = 0; i < n; ++i) {
c@100 89 spectrograms[i] = new Spectrogram(r, widthofmax * (mx / r));
c@100 90 r = r * 2;
c@100 91 }
c@100 92 }
c@100 93 ~Spectrograms() {
c@100 94 for (int i = 0; i < n; ++i) {
c@100 95 delete spectrograms[i];
c@100 96 }
c@100 97 delete[] spectrograms;
c@100 98 }
c@100 99 };
c@100 100
c@100 101 struct Cutting
c@100 102 {
c@100 103 enum Cut { Horizontal, Vertical, Finished };
c@100 104 Cut cut;
c@100 105 Cutting *first;
c@100 106 Cutting *second;
c@100 107 double cost;
c@100 108 double value;
c@100 109
c@100 110 ~Cutting() {
c@100 111 delete first;
c@100 112 delete second;
c@100 113 }
c@100 114 };
c@100 115
c@100 116 double cost(const Spectrogram &s, int x, int y) {
c@100 117 return xlogx(s.data[x][y]);
c@100 118 }
c@100 119
c@100 120 double value(const Spectrogram &s, int x, int y) {
c@100 121 return s.data[x][y];
c@100 122 }
c@100 123
c@100 124 Cutting *cut(const Spectrograms &, int res, int x, int y, int h);
c@100 125
c@100 126 void printCutting(Cutting *, std::string);
c@100 127
c@100 128 void assemble(const Spectrograms &, const Cutting *, std::vector<std::vector<float> > &, int x, int y, int w, int h);
c@100 129
c@92 130 void unpackResultMatrix(std::vector<std::vector<float> > &rmat,
c@92 131 int x, int y, int w, int h,
c@92 132 int *spl,
c@92 133 double *spec, int specsz, int res);
c@92 134
c@92 135 double DoCutSpectrogramBlock2(int* spl, double*** Specs, int Y, int R0,
c@99 136 int x0, int Y0, int N, double& ene,
c@99 137 std::string pfx = "");
c@92 138
c@92 139 double DoMixSpectrogramBlock2(int* spl, double* Spec, double*** Specs,
c@92 140 int Y, int R0, int x0, int Y0,
c@92 141 bool normmix, int res, double* e);
c@92 142
c@92 143 double MixSpectrogramBlock2(int* spl, double* Spec, double*** Specs,
c@92 144 int WID, int wid, bool normmix);
c@92 145
c@92 146 double MixSpectrogram2(int** spl, double** Spec, double*** Specs, int Fr,
c@92 147 int WID, int wid, bool norm, bool normmix);
c@92 148 };
c@92 149
c@92 150
c@92 151 #endif