Chris@8
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@8
|
2 /*
|
Chris@8
|
3 Permission is hereby granted, free of charge, to any person
|
Chris@8
|
4 obtaining a copy of this software and associated documentation
|
Chris@8
|
5 files (the "Software"), to deal in the Software without
|
Chris@8
|
6 restriction, including without limitation the rights to use, copy,
|
Chris@8
|
7 modify, merge, publish, distribute, sublicense, and/or sell copies
|
Chris@8
|
8 of the Software, and to permit persons to whom the Software is
|
Chris@8
|
9 furnished to do so, subject to the following conditions:
|
Chris@8
|
10
|
Chris@8
|
11 The above copyright notice and this permission notice shall be
|
Chris@8
|
12 included in all copies or substantial portions of the Software.
|
Chris@8
|
13
|
Chris@8
|
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@8
|
15 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@8
|
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@8
|
17 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
Chris@8
|
18 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@8
|
19 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@8
|
20 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@8
|
21 */
|
Chris@8
|
22
|
Chris@8
|
23 #ifndef _CEPSTRUM_PITCH_H_
|
Chris@8
|
24 #define _CEPSTRUM_PITCH_H_
|
Chris@8
|
25
|
Chris@8
|
26 #include <vamp-sdk/Plugin.h>
|
Chris@8
|
27
|
Chris@8
|
28 class CepstrumPitchTracker : public Vamp::Plugin
|
Chris@8
|
29 {
|
Chris@8
|
30 public:
|
Chris@8
|
31 CepstrumPitchTracker(float inputSampleRate);
|
Chris@8
|
32 virtual ~CepstrumPitchTracker();
|
Chris@8
|
33
|
Chris@8
|
34 std::string getIdentifier() const;
|
Chris@8
|
35 std::string getName() const;
|
Chris@8
|
36 std::string getDescription() const;
|
Chris@8
|
37 std::string getMaker() const;
|
Chris@8
|
38 int getPluginVersion() const;
|
Chris@8
|
39 std::string getCopyright() const;
|
Chris@8
|
40
|
Chris@8
|
41 InputDomain getInputDomain() const;
|
Chris@8
|
42 size_t getPreferredBlockSize() const;
|
Chris@8
|
43 size_t getPreferredStepSize() const;
|
Chris@8
|
44 size_t getMinChannelCount() const;
|
Chris@8
|
45 size_t getMaxChannelCount() const;
|
Chris@8
|
46
|
Chris@8
|
47 ParameterList getParameterDescriptors() const;
|
Chris@8
|
48 float getParameter(std::string identifier) const;
|
Chris@8
|
49 void setParameter(std::string identifier, float value);
|
Chris@8
|
50
|
Chris@8
|
51 ProgramList getPrograms() const;
|
Chris@8
|
52 std::string getCurrentProgram() const;
|
Chris@8
|
53 void selectProgram(std::string name);
|
Chris@8
|
54
|
Chris@8
|
55 OutputList getOutputDescriptors() const;
|
Chris@8
|
56
|
Chris@8
|
57 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
|
Chris@8
|
58 void reset();
|
Chris@8
|
59
|
Chris@8
|
60 FeatureSet process(const float *const *inputBuffers,
|
Chris@8
|
61 Vamp::RealTime timestamp);
|
Chris@8
|
62
|
Chris@8
|
63 FeatureSet getRemainingFeatures();
|
Chris@8
|
64
|
Chris@8
|
65 protected:
|
Chris@8
|
66 size_t m_channels;
|
Chris@8
|
67 size_t m_stepSize;
|
Chris@8
|
68 size_t m_blockSize;
|
Chris@8
|
69 float m_fmin;
|
Chris@8
|
70 float m_fmax;
|
Chris@8
|
71 int m_histlen;
|
Chris@10
|
72 int m_vflen;
|
Chris@8
|
73
|
Chris@8
|
74 int m_binFrom;
|
Chris@8
|
75 int m_binTo;
|
Chris@8
|
76 int m_bins; // count of "interesting" bins, those returned in m_cepOutput
|
Chris@8
|
77
|
Chris@12
|
78 class Hypothesis {
|
Chris@12
|
79
|
Chris@12
|
80 public:
|
Chris@12
|
81 struct Estimate {
|
Chris@12
|
82 double freq;
|
Chris@12
|
83 Vamp::RealTime time;
|
Chris@12
|
84 };
|
Chris@12
|
85 typedef std::vector<Estimate> Estimates;
|
Chris@12
|
86
|
Chris@13
|
87 Hypothesis();
|
Chris@12
|
88 ~Hypothesis();
|
Chris@12
|
89
|
Chris@12
|
90 enum State {
|
Chris@13
|
91 New,
|
Chris@12
|
92 Provisional,
|
Chris@12
|
93 Satisfied,
|
Chris@12
|
94 Rejected,
|
Chris@12
|
95 Expired
|
Chris@12
|
96 };
|
Chris@12
|
97
|
Chris@12
|
98 bool test(Estimate);
|
Chris@13
|
99
|
Chris@13
|
100 void advanceTime();
|
Chris@13
|
101
|
Chris@12
|
102 State getState();
|
Chris@12
|
103
|
Chris@17
|
104 int getPendingLength();
|
Chris@12
|
105 Estimates getAcceptedEstimates();
|
Chris@12
|
106
|
Chris@16
|
107 void addFeatures(FeatureList &fl);
|
Chris@16
|
108
|
Chris@12
|
109 private:
|
Chris@12
|
110 bool isWithinTolerance(Estimate);
|
Chris@12
|
111 bool isSatisfied();
|
Chris@12
|
112
|
Chris@12
|
113 State m_state;
|
Chris@12
|
114 Estimates m_pending;
|
Chris@12
|
115 int m_age;
|
Chris@12
|
116 };
|
Chris@12
|
117
|
Chris@12
|
118 typedef std::vector<Hypothesis> Hypotheses;
|
Chris@12
|
119 Hypotheses m_possible;
|
Chris@13
|
120 Hypothesis m_accepted;
|
Chris@12
|
121
|
Chris@8
|
122 double **m_history;
|
Chris@8
|
123
|
Chris@11
|
124 int m_prevpeak;
|
Chris@11
|
125 double m_prevprop;
|
Chris@11
|
126
|
Chris@11
|
127 double calculatePeakProportion(const double *data, double abstot, int n);
|
Chris@11
|
128 bool acceptPeak(int n, double peakProportion);
|
Chris@11
|
129
|
Chris@8
|
130 void filter(const double *in, double *out);
|
Chris@8
|
131 void fft(unsigned int n, bool inverse,
|
Chris@8
|
132 double *ri, double *ii, double *ro, double *io);
|
Chris@8
|
133 };
|
Chris@8
|
134
|
Chris@8
|
135 #endif
|