comparison src/Silvet.cpp @ 31:c6d230c31713

Stubbing out Vamp plugin
author Chris Cannam
date Thu, 03 Apr 2014 17:38:45 +0100
parents
children da54468cc452
comparison
equal deleted inserted replaced
30:d697e78f81f1 31:c6d230c31713
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Silvet
5
6 A Vamp plugin for note transcription.
7 Centre for Digital Music, Queen Mary University of London.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #include "Silvet.h"
17
18 #include "data/include/templates.h"
19
20 #include "dsp/rateconversion/Resampler.h"
21
22 #include "constant-q-cpp/cpp-qm-dsp/ConstantQ.h"
23
24 #include <vector>
25
26 using std::vector;
27 using std::cerr;
28 using std::endl;
29
30 static int processingSampleRate = 44100;
31 static int processingBPO = 60;
32
33
34 Silvet::Silvet(float inputSampleRate) :
35 Plugin(inputSampleRate),
36 m_resampler(0),
37 m_cq(0)
38 {
39 }
40
41 Silvet::~Silvet()
42 {
43 delete m_resampler;
44 delete m_cq;
45 }
46
47 string
48 Silvet::getIdentifier() const
49 {
50 return "silvet";
51 }
52
53 string
54 Silvet::getName() const
55 {
56 return "Silvet Note Transcription";
57 }
58
59 string
60 Silvet::getDescription() const
61 {
62 // Return something helpful here!
63 return "";
64 }
65
66 string
67 Silvet::getMaker() const
68 {
69 // Your name here
70 return "";
71 }
72
73 int
74 Silvet::getPluginVersion() const
75 {
76 return 1;
77 }
78
79 string
80 Silvet::getCopyright() const
81 {
82 // This function is not ideally named. It does not necessarily
83 // need to say who made the plugin -- getMaker does that -- but it
84 // should indicate the terms under which it is distributed. For
85 // example, "Copyright (year). All Rights Reserved", or "GPL"
86 return "";
87 }
88
89 Silvet::InputDomain
90 Silvet::getInputDomain() const
91 {
92 return TimeDomain;
93 }
94
95 size_t
96 Silvet::getPreferredBlockSize() const
97 {
98 return 0;
99 }
100
101 size_t
102 Silvet::getPreferredStepSize() const
103 {
104 return 0;
105 }
106
107 size_t
108 Silvet::getMinChannelCount() const
109 {
110 return 1;
111 }
112
113 size_t
114 Silvet::getMaxChannelCount() const
115 {
116 return 1;
117 }
118
119 Silvet::ParameterList
120 Silvet::getParameterDescriptors() const
121 {
122 ParameterList list;
123 return list;
124 }
125
126 float
127 Silvet::getParameter(string identifier) const
128 {
129 return 0;
130 }
131
132 void
133 Silvet::setParameter(string identifier, float value)
134 {
135 }
136
137 Silvet::ProgramList
138 Silvet::getPrograms() const
139 {
140 ProgramList list;
141 return list;
142 }
143
144 string
145 Silvet::getCurrentProgram() const
146 {
147 return "";
148 }
149
150 void
151 Silvet::selectProgram(string name)
152 {
153 }
154
155 Silvet::OutputList
156 Silvet::getOutputDescriptors() const
157 {
158 OutputList list;
159
160 OutputDescriptor d;
161 d.identifier = "transcription";
162 d.name = "Transcription";
163 d.description = ""; //!!!
164 d.unit = "Hz";
165 d.hasFixedBinCount = true;
166 d.binCount = 2;
167 d.binNames.push_back("Frequency");
168 d.binNames.push_back("Velocity");
169 d.hasKnownExtents = false;
170 d.isQuantized = false;
171 d.sampleType = OutputDescriptor::VariableSampleRate;
172 d.sampleRate = 0;
173 d.hasDuration = true;
174 list.push_back(d);
175
176 return list;
177 }
178
179 bool
180 Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize)
181 {
182 if (channels < getMinChannelCount() ||
183 channels > getMaxChannelCount()) return false;
184
185 if (stepSize != blockSize) {
186 cerr << "Silvet::initialise: Step size must be the same as block size ("
187 << stepSize << " != " << blockSize << ")" << endl;
188 return false;
189 }
190
191 m_blockSize = blockSize;
192
193 reset();
194
195 return true;
196 }
197
198 void
199 Silvet::reset()
200 {
201 delete m_resampler;
202 delete m_cq;
203
204 if (m_inputSampleRate != processingSampleRate) {
205 m_resampler = new Resampler(m_inputSampleRate, processingSampleRate);
206 } else {
207 m_resampler = 0;
208 }
209
210 m_cq = new ConstantQ
211 (processingSampleRate, 27.5, processingSampleRate / 3, processingBPO);
212
213 }
214
215 Silvet::FeatureSet
216 Silvet::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
217 {
218 vector<double> data;
219 for (int i = 0; i < m_blockSize; ++i) data.push_back(inputBuffers[0][i]);
220
221 if (m_resampler) {
222 data = m_resampler->process(data.data(), data.size());
223 }
224
225 vector<vector<double> > cqout = m_cq->process(data);
226
227 return FeatureSet();
228 }
229
230 Silvet::FeatureSet
231 Silvet::getRemainingFeatures()
232 {
233
234 return FeatureSet();
235 }
236