comparison VampTestPlugin.cpp @ 3:72c80798371e

Some output data
author Chris Cannam
date Mon, 25 Mar 2013 22:07:30 +0000
parents 3d07cfc3ee70
children 6ece30ceb931
comparison
equal deleted inserted replaced
2:3d07cfc3ee70 3:72c80798371e
1 1
2 2
3 #include "VampTestPlugin.h" 3 #include "VampTestPlugin.h"
4 4
5 #include <sstream>
6
7 using std::stringstream;
8
9 using Vamp::RealTime;
5 10
6 VampTestPlugin::VampTestPlugin(float inputSampleRate) : 11 VampTestPlugin::VampTestPlugin(float inputSampleRate) :
7 Plugin(inputSampleRate) 12 Plugin(inputSampleRate),
8 // Also be sure to set your plugin parameters (presumably stored 13 m_n(0),
9 // in member variables) to their default values here -- the host 14 m_stepSize(0),
10 // will not do that for you 15 m_blockSize(0)
11 { 16 {
17 for (int i = 0; i < 10; ++i) {
18 m_instants.push_back(RealTime::fromSeconds(1.5 * i));
19 }
12 } 20 }
13 21
14 VampTestPlugin::~VampTestPlugin() 22 VampTestPlugin::~VampTestPlugin()
15 { 23 {
16 } 24 }
122 { 130 {
123 OutputList list; 131 OutputList list;
124 132
125 OutputDescriptor d; 133 OutputDescriptor d;
126 134
127 //!!! review these: extents, units etc 135 // 0 -> instants
128
129 d.identifier = "instants"; 136 d.identifier = "instants";
130 d.name = "Instants"; 137 d.name = "Instants";
131 d.description = "Single time points without values"; 138 d.description = "Single time points without values";
132 d.unit = ""; 139 d.unit = "";
133 d.hasFixedBinCount = true; 140 d.hasFixedBinCount = true;
136 d.isQuantized = false; 143 d.isQuantized = false;
137 d.sampleType = OutputDescriptor::VariableSampleRate; 144 d.sampleType = OutputDescriptor::VariableSampleRate;
138 d.hasDuration = false; 145 d.hasDuration = false;
139 list.push_back(d); 146 list.push_back(d);
140 147
148 // 1 -> curve-oss
141 d.identifier = "curve-oss"; 149 d.identifier = "curve-oss";
142 d.name = "Curve: OneSamplePerStep"; 150 d.name = "Curve: OneSamplePerStep";
143 d.description = "A time series with one value per process block"; 151 d.description = "A time series with one value per process block";
144 d.unit = ""; 152 d.unit = "";
145 d.hasFixedBinCount = true; 153 d.hasFixedBinCount = true;
148 d.isQuantized = false; 156 d.isQuantized = false;
149 d.sampleType = OutputDescriptor::OneSamplePerStep; 157 d.sampleType = OutputDescriptor::OneSamplePerStep;
150 d.hasDuration = false; 158 d.hasDuration = false;
151 list.push_back(d); 159 list.push_back(d);
152 160
161 // 2 -> curve-fsr
153 d.identifier = "curve-fsr"; 162 d.identifier = "curve-fsr";
154 d.name = "Curve: FixedSampleRate"; 163 d.name = "Curve: FixedSampleRate";
155 d.description = "A time series with equally-spaced values (independent of process step size)"; 164 d.description = "A time series with equally-spaced values (independent of process step size)";
156 d.unit = ""; 165 d.unit = "";
157 d.hasFixedBinCount = true; 166 d.hasFixedBinCount = true;
158 d.binCount = 1; 167 d.binCount = 1;
159 d.hasKnownExtents = false; 168 d.hasKnownExtents = false;
160 d.isQuantized = false; 169 d.isQuantized = false;
161 d.sampleType = OutputDescriptor::FixedSampleRate; 170 d.sampleType = OutputDescriptor::FixedSampleRate;
162 d.sampleRate = 2; //!!! 171 d.sampleRate = 2;
163 d.hasDuration = false; 172 d.hasDuration = false;
164 list.push_back(d); 173 list.push_back(d);
165 174
175 // 3 -> curve-vsr
166 d.identifier = "curve-vsr"; 176 d.identifier = "curve-vsr";
167 d.name = "Curve: VariableSampleRate"; 177 d.name = "Curve: VariableSampleRate";
168 d.description = "A variably-spaced series of values"; 178 d.description = "A variably-spaced series of values";
169 d.unit = ""; 179 d.unit = "";
170 d.hasFixedBinCount = true; 180 d.hasFixedBinCount = true;
174 d.sampleType = OutputDescriptor::VariableSampleRate; 184 d.sampleType = OutputDescriptor::VariableSampleRate;
175 d.sampleRate = 0; 185 d.sampleRate = 0;
176 d.hasDuration = false; 186 d.hasDuration = false;
177 list.push_back(d); 187 list.push_back(d);
178 188
189 // 4 -> grid-oss
179 d.identifier = "grid-oss"; 190 d.identifier = "grid-oss";
180 d.name = "Grid: OneSamplePerStep"; 191 d.name = "Grid: OneSamplePerStep";
181 d.description = "A fixed-height grid of values with one column per process block"; 192 d.description = "A fixed-height grid of values with one column per process block";
182 d.unit = ""; 193 d.unit = "";
183 d.hasFixedBinCount = true; 194 d.hasFixedBinCount = true;
187 d.sampleType = OutputDescriptor::VariableSampleRate; 198 d.sampleType = OutputDescriptor::VariableSampleRate;
188 d.sampleRate = 0; 199 d.sampleRate = 0;
189 d.hasDuration = false; 200 d.hasDuration = false;
190 list.push_back(d); 201 list.push_back(d);
191 202
203 // 5 -> grid-fsr
192 d.identifier = "grid-fsr"; 204 d.identifier = "grid-fsr";
193 d.name = "Grid: FixedSampleRate"; 205 d.name = "Grid: FixedSampleRate";
194 d.description = "A fixed-height grid of values with equally-spaced columns (independent of process step size)"; 206 d.description = "A fixed-height grid of values with equally-spaced columns (independent of process step size)";
195 d.unit = ""; 207 d.unit = "";
196 d.hasFixedBinCount = true; 208 d.hasFixedBinCount = true;
210 VampTestPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize) 222 VampTestPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize)
211 { 223 {
212 if (channels < getMinChannelCount() || 224 if (channels < getMinChannelCount() ||
213 channels > getMaxChannelCount()) return false; 225 channels > getMaxChannelCount()) return false;
214 226
215 // Real initialisation work goes here! 227 m_stepSize = stepSize;
228 m_blockSize = blockSize;
216 229
217 return true; 230 return true;
218 } 231 }
219 232
220 void 233 void
221 VampTestPlugin::reset() 234 VampTestPlugin::reset()
222 { 235 {
223 // Clear buffers, reset stored values, etc 236 m_n = 0;
237 }
238
239 static Vamp::Plugin::Feature
240 instant(RealTime r, int i, int n)
241 {
242 std::stringstream s;
243 Vamp::Plugin::Feature f;
244 f.hasTimestamp = true;
245 f.timestamp = r;
246 f.hasDuration = false;
247 s << i+1 << " of " << n << " at " << r.toText();
248 f.label = s.str();
249 return f;
250 }
251
252 static Vamp::Plugin::Feature
253 untimedCurveValue(RealTime r, int i, int n)
254 {
255 std::stringstream s;
256 Vamp::Plugin::Feature f;
257 f.hasTimestamp = false;
258 f.hasDuration = false;
259 float v = float(i) / float(n);
260 f.values.push_back(v);
261 s << i+1 << " of " << n << ": " << v << " at " << r.toText();
262 f.label = s.str();
263 return f;
224 } 264 }
225 265
226 VampTestPlugin::FeatureSet 266 VampTestPlugin::FeatureSet
227 VampTestPlugin::process(const float *const *inputBuffers, Vamp::RealTime timestamp) 267 VampTestPlugin::process(const float *const *inputBuffers, RealTime timestamp)
228 { 268 {
229 // Do actual work! 269 FeatureSet fs;
230 return FeatureSet(); 270
271 RealTime endTime = timestamp + RealTime::frame2RealTime
272 (m_stepSize, m_inputSampleRate);
273
274 for (int i = 0; i < (int)m_instants.size(); ++i) {
275 if (m_instants[i] >= timestamp && m_instants[i] < endTime) {
276 // instants output
277 fs[0].push_back(instant(m_instants[i], i, m_instants.size()));
278 }
279 }
280
281 if (m_n < 20) {
282 // curve-oss output
283 fs[1].push_back(untimedCurveValue(timestamp, m_n, 20));
284 }
285
286 if (m_n < 5) {
287 // curve-fsr output
288 fs[2].push_back(untimedCurveValue(RealTime::fromSeconds(m_n / 2.0), m_n, 10));
289 }
290
291 m_lastTime = endTime;
292 m_n = m_n + 1;
293 return fs;
231 } 294 }
232 295
233 VampTestPlugin::FeatureSet 296 VampTestPlugin::FeatureSet
234 VampTestPlugin::getRemainingFeatures() 297 VampTestPlugin::getRemainingFeatures()
235 { 298 {
236 return FeatureSet(); 299 FeatureSet fs;
237 } 300
238 301 for (int i = 0; i < (int)m_instants.size(); ++i) {
302 if (m_instants[i] >= m_lastTime) {
303 fs[0].push_back(instant(m_instants[i], i, m_instants.size()));
304 }
305 }
306
307 for (int i = (m_n > 5 ? 5 : m_n); i < 10; ++i) {
308 // curve-fsr output
309 fs[2].push_back(untimedCurveValue(RealTime::fromSeconds(i / 2.0), i, 10));
310 }
311
312 return fs;
313 }
314