comparison modules-and-plug-ins/vamp-plugin/BTrackVamp.cpp @ 72:f4d9410f187e

flow: Merged <release> '1.0.0' to <master> ('master').
author Adam Stark <adamstark@users.noreply.github.com>
date Tue, 08 Jul 2014 12:32:27 +0100
parents 105999275c2e
children
comparison
equal deleted inserted replaced
44:3049937d6ef1 72:f4d9410f187e
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 b.updateHopAndFrameSize(m_stepSize,m_blockSize);
202
203
204 return true;
205 }
206
207 void
208 BTrackVamp::reset()
209 {
210 // Clear buffers, reset stored values, etc
211 }
212
213 BTrackVamp::FeatureSet
214 BTrackVamp::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
215 {
216 // create an array to hold our audio frame
217 double frame[m_blockSize];
218
219 // copy samples into our frame
220 for (int i = 0;i < m_blockSize;i++)
221 {
222 frame[i] = (double) inputBuffers[0][i];
223 }
224
225 // process the frame in the beat tracker
226 b.processAudioFrame(frame);
227
228 // create a FeatureSet
229 FeatureSet featureSet;
230
231 // if there is a beat in this frame
232 if (b.beatDueInCurrentFrame())
233 {
234 // add a beat to the FeatureSet
235 Feature beat;
236 beat.hasTimestamp = true;
237 beat.timestamp = timestamp - Vamp::RealTime::frame2RealTime(m_stepSize, int(m_inputSampleRate + 0.5));
238 featureSet[0].push_back(beat);
239 }
240
241 // return the feature set
242 return featureSet;
243 }
244
245 BTrackVamp::FeatureSet
246 BTrackVamp::getRemainingFeatures()
247 {
248 return FeatureSet();
249 }
250