comparison modules-and-plug-ins/vamp-plugin/BTrackVamp.cpp @ 24:deb49a2590f3 develop

Updated README, commented more code, added a Vamp plug-in
author Adam <adamstark.uk@gmail.com>
date Mon, 27 Jan 2014 23:11:31 +0000
parents
children 7af87d3f2ce2
comparison
equal deleted inserted replaced
23:92ee4ace9d46 24:deb49a2590f3
1
2 // This is a skeleton file for use in creating your own plugin
3 // libraries. Replace BTrackVamp and myPlugin throughout with the name
4 // of your first plugin class, and fill in the gaps as appropriate.
5
6
7 #include "BTrackVamp.h"
8
9
10 BTrackVamp::BTrackVamp(float inputSampleRate) :
11 Plugin(inputSampleRate)
12 // Also be sure to set your plugin parameters (presumably stored
13 // in member variables) to their default values here -- the host
14 // will not do that for you
15 {
16 }
17
18 BTrackVamp::~BTrackVamp()
19 {
20 }
21
22 string
23 BTrackVamp::getIdentifier() const
24 {
25 return "btrack-vamp";
26 }
27
28 string
29 BTrackVamp::getName() const
30 {
31 return "BTrack";
32 }
33
34 string
35 BTrackVamp::getDescription() const
36 {
37 // Return something helpful here!
38 return "A Real-Time Beat Tracker";
39 }
40
41 string
42 BTrackVamp::getMaker() const
43 {
44 // Your name here
45 return "Adam Stark, Matthew Davies and Mark Plumbley";
46 }
47
48 int
49 BTrackVamp::getPluginVersion() const
50 {
51 // Increment this each time you release a version that behaves
52 // differently from the previous one
53 return 1;
54 }
55
56 string
57 BTrackVamp::getCopyright() const
58 {
59 // This function is not ideally named. It does not necessarily
60 // need to say who made the plugin -- getMaker does that -- but it
61 // should indicate the terms under which it is distributed. For
62 // example, "Copyright (year). All Rights Reserved", or "GPL"
63 return "";
64 }
65
66 BTrackVamp::InputDomain
67 BTrackVamp::getInputDomain() const
68 {
69 return TimeDomain;
70 }
71
72 size_t
73 BTrackVamp::getPreferredBlockSize() const
74 {
75 return 1024; // 0 means "I can handle any block size"
76 }
77
78 size_t
79 BTrackVamp::getPreferredStepSize() const
80 {
81 return 512; // 0 means "anything sensible"; in practice this
82 // means the same as the block size for TimeDomain
83 // plugins, or half of it for FrequencyDomain plugins
84 }
85
86 size_t
87 BTrackVamp::getMinChannelCount() const
88 {
89 return 1;
90 }
91
92 size_t
93 BTrackVamp::getMaxChannelCount() const
94 {
95 return 1;
96 }
97
98 BTrackVamp::ParameterList
99 BTrackVamp::getParameterDescriptors() const
100 {
101 ParameterList list;
102
103 // If the plugin has no adjustable parameters, return an empty
104 // list here (and there's no need to provide implementations of
105 // getParameter and setParameter in that case either).
106
107 // Note that it is your responsibility to make sure the parameters
108 // start off having their default values (e.g. in the constructor
109 // above). The host needs to know the default value so it can do
110 // things like provide a "reset to default" function, but it will
111 // not explicitly set your parameters to their defaults for you if
112 // they have not changed in the mean time.
113
114 // ParameterDescriptor d;
115 // d.identifier = "parameter";
116 // d.name = "Some Parameter";
117 // d.description = "";
118 // d.unit = "";
119 // d.minValue = 0;
120 // d.maxValue = 10;
121 // d.defaultValue = 5;
122 // d.isQuantized = false;
123 // list.push_back(d);
124
125 return list;
126 }
127
128 float
129 BTrackVamp::getParameter(string identifier) const
130 {
131 if (identifier == "parameter") {
132 return 5; // return the ACTUAL current value of your parameter here!
133 }
134 return 0;
135 }
136
137 void
138 BTrackVamp::setParameter(string identifier, float value)
139 {
140 if (identifier == "parameter") {
141 // set the actual value of your parameter
142 }
143 }
144
145 BTrackVamp::ProgramList
146 BTrackVamp::getPrograms() const
147 {
148 ProgramList list;
149
150 // If you have no programs, return an empty list (or simply don't
151 // implement this function or getCurrentProgram/selectProgram)
152
153 return list;
154 }
155
156 string
157 BTrackVamp::getCurrentProgram() const
158 {
159 return ""; // no programs
160 }
161
162 void
163 BTrackVamp::selectProgram(string name)
164 {
165 }
166
167 BTrackVamp::OutputList
168 BTrackVamp::getOutputDescriptors() const
169 {
170 OutputList list;
171
172 // See OutputDescriptor documentation for the possibilities here.
173 // Every plugin must have at least one output.
174
175 OutputDescriptor d;
176 d.identifier = "beats";
177 d.name = "Beats";
178 d.description = "Beat locations";
179 d.unit = "";
180 d.hasFixedBinCount = true;
181 d.binCount = 0;
182 d.hasKnownExtents = false;
183 d.isQuantized = false;
184 d.sampleType = OutputDescriptor::VariableSampleRate;
185 d.sampleRate = m_inputSampleRate;
186 list.push_back(d);
187
188 return list;
189 }
190
191 bool
192 BTrackVamp::initialise(size_t channels, size_t stepSize, size_t blockSize)
193 {
194 if (channels < getMinChannelCount() ||
195 channels > getMaxChannelCount()) return false;
196
197
198 m_stepSize = stepSize;
199 m_blockSize = blockSize;
200
201 // Real initialisation work goes here!
202
203 return true;
204 }
205
206 void
207 BTrackVamp::reset()
208 {
209 // Clear buffers, reset stored values, etc
210 }
211
212 BTrackVamp::FeatureSet
213 BTrackVamp::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
214 {
215 double frame[m_blockSize];
216
217 for (int i = 0;i < m_blockSize;i++)
218 {
219 frame[i] = (double) inputBuffers[0][i];
220 }
221
222 b.processAudioFrame(frame);
223
224 FeatureSet featureSet;
225
226 if (b.beatDueInCurrentFrame())
227 {
228 Feature beat;
229 beat.hasTimestamp = true;
230 beat.timestamp = timestamp - Vamp::RealTime::frame2RealTime(m_stepSize, int(m_inputSampleRate + 0.5));
231 featureSet[0].push_back(beat);
232 }
233
234 // Do actual work!
235 return featureSet;
236 }
237
238 BTrackVamp::FeatureSet
239 BTrackVamp::getRemainingFeatures()
240 {
241 return FeatureSet();
242 }
243