Chris@34
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@34
|
2
|
Chris@34
|
3 /*
|
Chris@34
|
4 Silvet
|
Chris@34
|
5
|
Chris@34
|
6 A Vamp plugin for note transcription.
|
Chris@34
|
7 Centre for Digital Music, Queen Mary University of London.
|
Chris@34
|
8
|
Chris@34
|
9 This program is free software; you can redistribute it and/or
|
Chris@34
|
10 modify it under the terms of the GNU General Public License as
|
Chris@34
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@34
|
12 License, or (at your option) any later version. See the file
|
Chris@34
|
13 COPYING included with this distribution for more information.
|
Chris@34
|
14 */
|
Chris@34
|
15
|
Chris@34
|
16 #ifndef SILVET_EM_H
|
Chris@34
|
17 #define SILVET_EM_H
|
Chris@34
|
18
|
Chris@34
|
19 #include <vector>
|
Chris@34
|
20
|
Chris@34
|
21 class EM
|
Chris@34
|
22 {
|
Chris@34
|
23 public:
|
Chris@110
|
24 EM(bool useShifts);
|
Chris@34
|
25 ~EM();
|
Chris@34
|
26
|
Chris@125
|
27 int getBinCount() const { return m_binCount; }
|
Chris@125
|
28 int getNoteCount() const { return m_noteCount; }
|
Chris@91
|
29 int getSourceCount() const { return m_sourceCount; }
|
Chris@34
|
30
|
Chris@125
|
31 /**
|
Chris@125
|
32 * Carry out one iteration using the given column as input. The
|
Chris@125
|
33 * column must have getBinCount() values.
|
Chris@125
|
34 */
|
Chris@92
|
35 void iterate(const double *column);
|
Chris@91
|
36
|
Chris@125
|
37 /**
|
Chris@125
|
38 * Return the estimated distribution after the current iteration.
|
Chris@125
|
39 * Like the input, this will have getBinCount() values.
|
Chris@125
|
40 */
|
Chris@125
|
41 const double *getEstimate() const {
|
Chris@38
|
42 return m_estimate;
|
Chris@38
|
43 }
|
Chris@125
|
44
|
Chris@125
|
45 /**
|
Chris@125
|
46 * Return the pitch distribution for the current estimate. The
|
Chris@125
|
47 * returned array has getNoteCount() values.
|
Chris@125
|
48 */
|
Chris@125
|
49 const double *getPitchDistribution() const {
|
Chris@38
|
50 return m_pitches;
|
Chris@38
|
51 }
|
Chris@125
|
52
|
Chris@125
|
53 /**
|
Chris@125
|
54 * Return the source distribution for the current estimate. The
|
Chris@125
|
55 * returned pointer refers to getSourceCount() arrays of
|
Chris@125
|
56 * getNoteCount() values.
|
Chris@125
|
57 */
|
Chris@125
|
58 const double *const *getSources() const {
|
Chris@38
|
59 return m_sources;
|
Chris@38
|
60 }
|
Chris@38
|
61
|
Chris@34
|
62 private:
|
Chris@91
|
63 double *m_pitches;
|
Chris@91
|
64 double **m_shifts;
|
Chris@91
|
65 double **m_sources;
|
Chris@55
|
66
|
Chris@100
|
67 double *m_updatePitches;
|
Chris@100
|
68 double **m_updateShifts;
|
Chris@100
|
69 double **m_updateSources;
|
Chris@34
|
70
|
Chris@91
|
71 double *m_estimate;
|
Chris@91
|
72 double *m_q;
|
Chris@55
|
73
|
Chris@83
|
74 const int m_noteCount;
|
Chris@83
|
75 const int m_shiftCount; // 1 + 2 * max template shift
|
Chris@83
|
76 const int m_binCount;
|
Chris@91
|
77 const int m_sourceCount;
|
Chris@55
|
78
|
Chris@83
|
79 const double m_pitchSparsity;
|
Chris@83
|
80 const double m_sourceSparsity;
|
Chris@36
|
81
|
Chris@83
|
82 const int m_lowestPitch;
|
Chris@83
|
83 const int m_highestPitch;
|
Chris@35
|
84
|
Chris@91
|
85 void normaliseColumn(double *column, int size);
|
Chris@92
|
86 void normaliseGrid(double **grid, int size1, int size2);
|
Chris@35
|
87
|
Chris@92
|
88 void expectation(const double *column); // size is m_binCount
|
Chris@92
|
89 void maximisation(const double *column); // size is m_binCount
|
Chris@36
|
90
|
Chris@88
|
91 const double *templateFor(int instrument, int note, int shift);
|
Chris@45
|
92 void rangeFor(int instrument, int &minPitch, int &maxPitch);
|
Chris@45
|
93 bool inRange(int instrument, int pitch);
|
Chris@34
|
94 };
|
Chris@34
|
95
|
Chris@34
|
96 #endif
|