~ubuntu-branches/ubuntu/vivid/ardour/vivid-proposed

« back to all changes in this revision

Viewing changes to libs/rubberband/src/vamp/RubberBandVampPlugin.cpp

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler, Jaromír Mikeš, Felipe Sateler
  • Date: 2014-05-22 14:39:25 UTC
  • mfrom: (29 sid)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: package-import@ubuntu.com-20140522143925-vwqfo9287pmkrroe
Tags: 1:2.8.16+git20131003-3
* Team upload

[ Jaromír Mikeš ]
* Add -dbg package

[ Felipe Sateler ]
* Upload to experimental

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
 
2
 
 
3
/*
 
4
    Rubber Band
 
5
    An audio time-stretching and pitch-shifting library.
 
6
    Copyright 2007-2008 Chris Cannam.
 
7
    
 
8
    This program is free software; you can redistribute it and/or
 
9
    modify it under the terms of the GNU General Public License as
 
10
    published by the Free Software Foundation; either version 2 of the
 
11
    License, or (at your option) any later version.  See the file
 
12
    COPYING included with this distribution for more information.
 
13
*/
 
14
 
 
15
#include "RubberBandVampPlugin.h"
 
16
 
 
17
#include "StretchCalculator.h"
 
18
#include "sysutils.h"
 
19
 
 
20
#include <cmath>
 
21
 
 
22
using std::string;
 
23
using std::vector;
 
24
using std::cerr;
 
25
using std::endl;
 
26
 
 
27
class RubberBandVampPlugin::Impl
 
28
{
 
29
public:
 
30
    size_t m_stepSize;
 
31
    size_t m_blockSize;
 
32
    size_t m_sampleRate;
 
33
 
 
34
    float m_timeRatio;
 
35
    float m_pitchRatio;
 
36
 
 
37
    bool m_realtime;
 
38
    bool m_elasticTiming;
 
39
    int m_transientMode;
 
40
    bool m_phaseIndependent;
 
41
    int m_windowLength;
 
42
 
 
43
    RubberBand::RubberBandStretcher *m_stretcher;
 
44
 
 
45
    int m_incrementsOutput;
 
46
    int m_aggregateIncrementsOutput;
 
47
    int m_divergenceOutput;
 
48
    int m_phaseResetDfOutput;
 
49
    int m_smoothedPhaseResetDfOutput;
 
50
    int m_phaseResetPointsOutput;
 
51
    int m_timeSyncPointsOutput;
 
52
 
 
53
    size_t m_counter;
 
54
    size_t m_accumulatedIncrement;
 
55
 
 
56
    float **m_outputDump;
 
57
 
 
58
    FeatureSet processOffline(const float *const *inputBuffers,
 
59
                              Vamp::RealTime timestamp);
 
60
 
 
61
    FeatureSet getRemainingFeaturesOffline();
 
62
 
 
63
    FeatureSet processRealTime(const float *const *inputBuffers,
 
64
                               Vamp::RealTime timestamp);
 
65
 
 
66
    FeatureSet getRemainingFeaturesRealTime();
 
67
 
 
68
    FeatureSet createFeatures(size_t inputIncrement,
 
69
                              std::vector<int> &outputIncrements,
 
70
                              std::vector<float> &phaseResetDf,
 
71
                              std::vector<int> &exactPoints,
 
72
                              std::vector<float> &smoothedDf,
 
73
                              size_t baseCount,
 
74
                              bool includeFinal);
 
75
};
 
76
 
 
77
 
 
78
RubberBandVampPlugin::RubberBandVampPlugin(float inputSampleRate) :
 
79
    Plugin(inputSampleRate)
 
80
{
 
81
    m_d = new Impl();
 
82
    m_d->m_stepSize = 0;
 
83
    m_d->m_timeRatio = 1.f;
 
84
    m_d->m_pitchRatio = 1.f;
 
85
    m_d->m_realtime = false;
 
86
    m_d->m_elasticTiming = true;
 
87
    m_d->m_transientMode = 0;
 
88
    m_d->m_phaseIndependent = false;
 
89
    m_d->m_windowLength = 0;
 
90
    m_d->m_stretcher = 0;
 
91
    m_d->m_sampleRate = lrintf(m_inputSampleRate);
 
92
}
 
93
 
 
94
RubberBandVampPlugin::~RubberBandVampPlugin()
 
95
{
 
96
    if (m_d->m_outputDump) {
 
97
        for (size_t i = 0; i < m_d->m_stretcher->getChannelCount(); ++i) {
 
98
            delete[] m_d->m_outputDump[i];
 
99
        }
 
100
        delete[] m_d->m_outputDump;
 
101
    }
 
102
    delete m_d->m_stretcher;
 
103
    delete m_d;
 
104
}
 
105
 
 
106
string
 
107
RubberBandVampPlugin::getIdentifier() const
 
108
{
 
109
    return "rubberband";
 
110
}
 
111
 
 
112
string
 
113
RubberBandVampPlugin::getName() const
 
114
{
 
115
    return "Rubber Band Timestretch Analysis";
 
116
}
 
117
 
 
118
string
 
119
RubberBandVampPlugin::getDescription() const
 
120
{
 
121
    return "Carry out analysis phases of time stretcher process";
 
122
}
 
123
 
 
124
string
 
125
RubberBandVampPlugin::getMaker() const
 
126
{
 
127
    return "Breakfast Quay";
 
128
}
 
129
 
 
130
int
 
131
RubberBandVampPlugin::getPluginVersion() const
 
132
{
 
133
    return 1;
 
134
}
 
135
 
 
136
string
 
137
RubberBandVampPlugin::getCopyright() const
 
138
{
 
139
    return "";//!!!
 
140
}
 
141
 
 
142
RubberBandVampPlugin::OutputList
 
143
RubberBandVampPlugin::getOutputDescriptors() const
 
144
{
 
145
    OutputList list;
 
146
 
 
147
    size_t rate = 0;
 
148
    if (m_d->m_stretcher) {
 
149
        rate = lrintf(m_inputSampleRate / m_d->m_stretcher->getInputIncrement());
 
150
    }
 
151
 
 
152
    OutputDescriptor d;
 
153
    d.identifier = "increments";
 
154
    d.name = "Output Increments";
 
155
    d.description = "Output time increment for each input step";
 
156
    d.unit = "samples";
 
157
    d.hasFixedBinCount = true;
 
158
    d.binCount = 1;
 
159
    d.hasKnownExtents = false;
 
160
    d.isQuantized = true;
 
161
    d.quantizeStep = 1.0;
 
162
    d.sampleType = OutputDescriptor::VariableSampleRate;
 
163
    d.sampleRate = float(rate);
 
164
    m_d->m_incrementsOutput = list.size();
 
165
    list.push_back(d);
 
166
 
 
167
    d.identifier = "aggregate_increments";
 
168
    d.name = "Accumulated Output Increments";
 
169
    d.description = "Accumulated output time increments";
 
170
    d.sampleRate = 0;
 
171
    m_d->m_aggregateIncrementsOutput = list.size();
 
172
    list.push_back(d);
 
173
 
 
174
    d.identifier = "divergence";
 
175
    d.name = "Divergence from Linear";
 
176
    d.description = "Difference between actual output time and the output time for a theoretical linear stretch";
 
177
    d.isQuantized = false;
 
178
    d.sampleRate = 0;
 
179
    m_d->m_divergenceOutput = list.size();
 
180
    list.push_back(d);
 
181
 
 
182
    d.identifier = "phaseresetdf";
 
183
    d.name = "Phase Reset Detection Function";
 
184
    d.description = "Curve whose peaks are used to identify transients for phase reset points";
 
185
    d.unit = "";
 
186
    d.sampleRate = float(rate);
 
187
    m_d->m_phaseResetDfOutput = list.size();
 
188
    list.push_back(d);
 
189
 
 
190
    d.identifier = "smoothedphaseresetdf";
 
191
    d.name = "Smoothed Phase Reset Detection Function";
 
192
    d.description = "Phase reset curve smoothed for peak picking";
 
193
    d.unit = "";
 
194
    m_d->m_smoothedPhaseResetDfOutput = list.size();
 
195
    list.push_back(d);
 
196
 
 
197
    d.identifier = "phaseresetpoints";
 
198
    d.name = "Phase Reset Points";
 
199
    d.description = "Points estimated as transients at which phase reset occurs";
 
200
    d.unit = "";
 
201
    d.hasFixedBinCount = true;
 
202
    d.binCount = 0;
 
203
    d.hasKnownExtents = false;
 
204
    d.isQuantized = false;
 
205
    d.sampleRate = 0;
 
206
    m_d->m_phaseResetPointsOutput = list.size();
 
207
    list.push_back(d);
 
208
 
 
209
    d.identifier = "timesyncpoints";
 
210
    d.name = "Time Sync Points";
 
211
    d.description = "Salient points which stretcher aims to place with strictly correct timing";
 
212
    d.unit = "";
 
213
    d.hasFixedBinCount = true;
 
214
    d.binCount = 0;
 
215
    d.hasKnownExtents = false;
 
216
    d.isQuantized = false;
 
217
    d.sampleRate = 0;
 
218
    m_d->m_timeSyncPointsOutput = list.size();
 
219
    list.push_back(d);
 
220
 
 
221
    return list;
 
222
}
 
223
 
 
224
RubberBandVampPlugin::ParameterList
 
225
RubberBandVampPlugin::getParameterDescriptors() const
 
226
{
 
227
    ParameterList list;
 
228
 
 
229
    ParameterDescriptor d;
 
230
    d.identifier = "timeratio";
 
231
    d.name = "Time Ratio";
 
232
    d.description = "Ratio to modify overall duration by";
 
233
    d.unit = "%";
 
234
    d.minValue = 1;
 
235
    d.maxValue = 500;
 
236
    d.defaultValue = 100;
 
237
    d.isQuantized = false;
 
238
    list.push_back(d);
 
239
 
 
240
    d.identifier = "pitchratio";
 
241
    d.name = "Pitch Scale Ratio";
 
242
    d.description = "Frequency ratio to modify pitch by";
 
243
    d.unit = "%";
 
244
    d.minValue = 1;
 
245
    d.maxValue = 500;
 
246
    d.defaultValue = 100;
 
247
    d.isQuantized = false;
 
248
    list.push_back(d);
 
249
 
 
250
    d.identifier = "mode";
 
251
    d.name = "Processing Mode";
 
252
    d.description = ""; //!!!
 
253
    d.unit = "";
 
254
    d.minValue = 0;
 
255
    d.maxValue = 1;
 
256
    d.defaultValue = 0;
 
257
    d.isQuantized = true;
 
258
    d.quantizeStep = 1;
 
259
    d.valueNames.clear();
 
260
    d.valueNames.push_back("Offline");
 
261
    d.valueNames.push_back("Real Time");
 
262
    list.push_back(d);
 
263
 
 
264
    d.identifier = "stretchtype";
 
265
    d.name = "Stretch Flexibility";
 
266
    d.description = ""; //!!!
 
267
    d.unit = "";
 
268
    d.minValue = 0;
 
269
    d.maxValue = 1;
 
270
    d.defaultValue = 0;
 
271
    d.isQuantized = true;
 
272
    d.quantizeStep = 1;
 
273
    d.valueNames.clear();
 
274
    d.valueNames.push_back("Elastic");
 
275
    d.valueNames.push_back("Precise");
 
276
    list.push_back(d);
 
277
 
 
278
    d.identifier = "transientmode";
 
279
    d.name = "Transient Handling";
 
280
    d.description = ""; //!!!
 
281
    d.unit = "";
 
282
    d.minValue = 0;
 
283
    d.maxValue = 2;
 
284
    d.defaultValue = 0;
 
285
    d.isQuantized = true;
 
286
    d.quantizeStep = 1;
 
287
    d.valueNames.clear();
 
288
    d.valueNames.push_back("Mixed");
 
289
    d.valueNames.push_back("Smooth");
 
290
    d.valueNames.push_back("Crisp");
 
291
    list.push_back(d);
 
292
 
 
293
    d.identifier = "phasemode";
 
294
    d.name = "Phase Handling";
 
295
    d.description = ""; //!!!
 
296
    d.unit = "";
 
297
    d.minValue = 0;
 
298
    d.maxValue = 1;
 
299
    d.defaultValue = 0;
 
300
    d.isQuantized = true;
 
301
    d.quantizeStep = 1;
 
302
    d.valueNames.clear();
 
303
    d.valueNames.push_back("Peak Locked");
 
304
    d.valueNames.push_back("Independent");
 
305
    list.push_back(d);
 
306
 
 
307
    d.identifier = "windowmode";
 
308
    d.name = "Window Length";
 
309
    d.description = ""; //!!!
 
310
    d.unit = "";
 
311
    d.minValue = 0;
 
312
    d.maxValue = 2;
 
313
    d.defaultValue = 0;
 
314
    d.isQuantized = true;
 
315
    d.quantizeStep = 1;
 
316
    d.valueNames.clear();
 
317
    d.valueNames.push_back("Standard");
 
318
    d.valueNames.push_back("Short");
 
319
    d.valueNames.push_back("Long");
 
320
    list.push_back(d);
 
321
 
 
322
    return list;
 
323
}
 
324
 
 
325
float
 
326
RubberBandVampPlugin::getParameter(std::string id) const
 
327
{
 
328
    if (id == "timeratio") return m_d->m_timeRatio * 100.f;
 
329
    if (id == "pitchratio") return m_d->m_pitchRatio * 100.f;
 
330
    if (id == "mode") return m_d->m_realtime ? 1.f : 0.f;
 
331
    if (id == "stretchtype") return m_d->m_elasticTiming ? 0.f : 1.f;
 
332
    if (id == "transientmode") return float(m_d->m_transientMode);
 
333
    if (id == "phasemode") return m_d->m_phaseIndependent ? 1.f : 0.f;
 
334
    if (id == "windowmode") return float(m_d->m_windowLength);
 
335
    return 0.f;
 
336
}
 
337
 
 
338
void
 
339
RubberBandVampPlugin::setParameter(std::string id, float value)
 
340
{
 
341
    if (id == "timeratio") {
 
342
        m_d->m_timeRatio = value / 100;
 
343
    } else if (id == "pitchratio") {
 
344
        m_d->m_pitchRatio = value / 100;
 
345
    } else {
 
346
        bool set = (value > 0.5);
 
347
        if (id == "mode") m_d->m_realtime = set;
 
348
        else if (id == "stretchtype") m_d->m_elasticTiming = !set;
 
349
        else if (id == "transientmode") m_d->m_transientMode = int(value + 0.5);
 
350
        else if (id == "phasemode") m_d->m_phaseIndependent = set;
 
351
        else if (id == "windowmode") m_d->m_windowLength = int(value + 0.5);
 
352
    }
 
353
}
 
354
 
 
355
bool
 
356
RubberBandVampPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize)
 
357
{
 
358
    if (channels < getMinChannelCount() ||
 
359
        channels > getMaxChannelCount()) return false;
 
360
 
 
361
    m_d->m_stepSize = std::min(stepSize, blockSize);
 
362
    m_d->m_blockSize = stepSize;
 
363
 
 
364
    RubberBand::RubberBandStretcher::Options options = 0;
 
365
 
 
366
    if (m_d->m_realtime)
 
367
         options |= RubberBand::RubberBandStretcher::OptionProcessRealTime;
 
368
    else options |= RubberBand::RubberBandStretcher::OptionProcessOffline;
 
369
 
 
370
    if (m_d->m_elasticTiming)
 
371
         options |= RubberBand::RubberBandStretcher::OptionStretchElastic;
 
372
    else options |= RubberBand::RubberBandStretcher::OptionStretchPrecise;
 
373
 
 
374
    if (m_d->m_transientMode == 0) 
 
375
         options |= RubberBand::RubberBandStretcher::OptionTransientsMixed;
 
376
    else if (m_d->m_transientMode == 1) 
 
377
         options |= RubberBand::RubberBandStretcher::OptionTransientsSmooth;
 
378
    else options |= RubberBand::RubberBandStretcher::OptionTransientsCrisp;
 
379
 
 
380
    if (m_d->m_phaseIndependent) 
 
381
         options |= RubberBand::RubberBandStretcher::OptionPhaseIndependent;
 
382
    else options |= RubberBand::RubberBandStretcher::OptionPhaseLaminar;
 
383
 
 
384
    if (m_d->m_windowLength == 0)
 
385
         options |= RubberBand::RubberBandStretcher::OptionWindowStandard;
 
386
    else if (m_d->m_windowLength == 1)
 
387
         options |= RubberBand::RubberBandStretcher::OptionWindowShort;
 
388
    else options |= RubberBand::RubberBandStretcher::OptionWindowLong;
 
389
 
 
390
    delete m_d->m_stretcher;
 
391
    m_d->m_stretcher = new RubberBand::RubberBandStretcher
 
392
        (m_d->m_sampleRate, channels, options);
 
393
    m_d->m_stretcher->setDebugLevel(1);
 
394
    m_d->m_stretcher->setTimeRatio(m_d->m_timeRatio);
 
395
    m_d->m_stretcher->setPitchScale(m_d->m_pitchRatio);
 
396
 
 
397
    m_d->m_counter = 0;
 
398
    m_d->m_accumulatedIncrement = 0;
 
399
 
 
400
    m_d->m_outputDump = 0;
 
401
 
 
402
    return true;
 
403
}
 
404
 
 
405
void
 
406
RubberBandVampPlugin::reset()
 
407
{
 
408
//    delete m_stretcher;  //!!! or just if (m_stretcher) m_stretcher->reset();
 
409
//    m_stretcher = new RubberBand::RubberBandStretcher(lrintf(m_inputSampleRate), channels);
 
410
    if (m_d->m_stretcher) m_d->m_stretcher->reset();
 
411
}
 
412
 
 
413
RubberBandVampPlugin::FeatureSet
 
414
RubberBandVampPlugin::process(const float *const *inputBuffers,
 
415
                              Vamp::RealTime timestamp)
 
416
{
 
417
    if (m_d->m_realtime) {
 
418
        return m_d->processRealTime(inputBuffers, timestamp);
 
419
    } else {
 
420
        return m_d->processOffline(inputBuffers, timestamp);
 
421
    }        
 
422
}
 
423
 
 
424
RubberBandVampPlugin::FeatureSet
 
425
RubberBandVampPlugin::getRemainingFeatures()
 
426
{
 
427
    if (m_d->m_realtime) {
 
428
        return m_d->getRemainingFeaturesRealTime();
 
429
    } else {
 
430
        return m_d->getRemainingFeaturesOffline();
 
431
    }
 
432
}
 
433
 
 
434
RubberBandVampPlugin::FeatureSet
 
435
RubberBandVampPlugin::Impl::processOffline(const float *const *inputBuffers,
 
436
                                           Vamp::RealTime timestamp)
 
437
{
 
438
    if (!m_stretcher) {
 
439
        cerr << "ERROR: RubberBandVampPlugin::processOffline: "
 
440
             << "RubberBandVampPlugin has not been initialised"
 
441
             << endl;
 
442
        return FeatureSet();
 
443
    }
 
444
 
 
445
    m_stretcher->study(inputBuffers, m_blockSize, false);
 
446
    return FeatureSet();
 
447
}
 
448
 
 
449
RubberBandVampPlugin::FeatureSet
 
450
RubberBandVampPlugin::Impl::getRemainingFeaturesOffline()
 
451
{
 
452
    m_stretcher->study(0, 0, true);
 
453
 
 
454
    m_stretcher->calculateStretch();
 
455
 
 
456
    int rate = m_sampleRate;
 
457
 
 
458
    RubberBand::StretchCalculator sc(rate,
 
459
                                     m_stretcher->getInputIncrement(),
 
460
                                     true);
 
461
 
 
462
    size_t inputIncrement = m_stretcher->getInputIncrement();
 
463
    std::vector<int> outputIncrements = m_stretcher->getOutputIncrements();
 
464
    std::vector<float> phaseResetDf = m_stretcher->getPhaseResetCurve();
 
465
    std::vector<int> peaks = m_stretcher->getExactTimePoints();
 
466
    std::vector<float> smoothedDf = sc.smoothDF(phaseResetDf);
 
467
 
 
468
    FeatureSet features = createFeatures
 
469
        (inputIncrement, outputIncrements, phaseResetDf, peaks, smoothedDf,
 
470
         0, true);
 
471
 
 
472
    return features;
 
473
}
 
474
 
 
475
RubberBandVampPlugin::FeatureSet
 
476
RubberBandVampPlugin::Impl::processRealTime(const float *const *inputBuffers,
 
477
                                            Vamp::RealTime timestamp)
 
478
{
 
479
    // This function is not in any way a real-time function (i.e. it
 
480
    // has no requirement to be RT safe); it simply operates the
 
481
    // stretcher in RT mode.
 
482
 
 
483
    if (!m_stretcher) {
 
484
        cerr << "ERROR: RubberBandVampPlugin::processRealTime: "
 
485
             << "RubberBandVampPlugin has not been initialised"
 
486
             << endl;
 
487
        return FeatureSet();
 
488
    }
 
489
 
 
490
    m_stretcher->process(inputBuffers, m_blockSize, false);
 
491
    
 
492
    size_t inputIncrement = m_stretcher->getInputIncrement();
 
493
    std::vector<int> outputIncrements = m_stretcher->getOutputIncrements();
 
494
    std::vector<float> phaseResetDf = m_stretcher->getPhaseResetCurve();
 
495
    std::vector<float> smoothedDf; // not meaningful in RT mode
 
496
    std::vector<int> dummyPoints;
 
497
    FeatureSet features = createFeatures
 
498
        (inputIncrement, outputIncrements, phaseResetDf, dummyPoints, smoothedDf, 
 
499
         m_counter, false);
 
500
    m_counter += outputIncrements.size();
 
501
 
 
502
    int available = 0;
 
503
    while ((available = m_stretcher->available()) > 0) {
 
504
        if (!m_outputDump) {
 
505
            m_outputDump = new float *[m_stretcher->getChannelCount()];
 
506
            for (size_t i = 0; i < m_stretcher->getChannelCount(); ++i) {
 
507
                m_outputDump[i] = new float[m_blockSize];
 
508
            }
 
509
        }
 
510
        m_stretcher->retrieve(m_outputDump,
 
511
                              std::min(int(m_blockSize), available));
 
512
    }
 
513
 
 
514
    return features;
 
515
}
 
516
 
 
517
RubberBandVampPlugin::FeatureSet
 
518
RubberBandVampPlugin::Impl::getRemainingFeaturesRealTime()
 
519
{
 
520
    return FeatureSet();
 
521
}
 
522
 
 
523
RubberBandVampPlugin::FeatureSet
 
524
RubberBandVampPlugin::Impl::createFeatures(size_t inputIncrement,
 
525
                                           std::vector<int> &outputIncrements,
 
526
                                           std::vector<float> &phaseResetDf,
 
527
                                           std::vector<int> &exactPoints,
 
528
                                           std::vector<float> &smoothedDf,
 
529
                                           size_t baseCount,
 
530
                                           bool includeFinal)
 
531
{
 
532
    size_t actual = m_accumulatedIncrement;
 
533
 
 
534
    double overallRatio = m_timeRatio * m_pitchRatio;
 
535
 
 
536
    char label[200];
 
537
 
 
538
    FeatureSet features;
 
539
 
 
540
    int rate = m_sampleRate;
 
541
 
 
542
    size_t epi = 0;
 
543
 
 
544
    for (size_t i = 0; i < outputIncrements.size(); ++i) {
 
545
 
 
546
        size_t frame = (baseCount + i) * inputIncrement;
 
547
 
 
548
        int oi = outputIncrements[i];
 
549
        bool hard = false;
 
550
        bool soft = false;
 
551
 
 
552
        if (oi < 0) {
 
553
            oi = -oi;
 
554
            hard = true;
 
555
        }
 
556
 
 
557
        if (epi < exactPoints.size() && int(i) == exactPoints[epi]) {
 
558
            soft = true;
 
559
            ++epi;
 
560
        }
 
561
 
 
562
        double linear = (frame * overallRatio);
 
563
 
 
564
        Vamp::RealTime t = Vamp::RealTime::frame2RealTime(frame, rate);
 
565
 
 
566
        Feature feature;
 
567
        feature.hasTimestamp = true;
 
568
        feature.timestamp = t;
 
569
        feature.values.push_back(float(oi));
 
570
        feature.label = Vamp::RealTime::frame2RealTime(oi, rate).toText();
 
571
        features[m_incrementsOutput].push_back(feature);
 
572
 
 
573
        feature.values.clear();
 
574
        feature.values.push_back(float(actual));
 
575
        feature.label = Vamp::RealTime::frame2RealTime(actual, rate).toText();
 
576
        features[m_aggregateIncrementsOutput].push_back(feature);
 
577
 
 
578
        feature.values.clear();
 
579
        feature.values.push_back(actual - linear);
 
580
 
 
581
        sprintf(label, "expected %ld, actual %ld, difference %ld (%s ms)",
 
582
                long(linear), long(actual), long(actual - linear),
 
583
                // frame2RealTime expects an integer frame number,
 
584
                // hence our multiplication factor
 
585
                (Vamp::RealTime::frame2RealTime
 
586
                 (lrintf((actual - linear) * 1000), rate) / 1000)
 
587
                .toText().c_str());
 
588
        feature.label = label;
 
589
 
 
590
        features[m_divergenceOutput].push_back(feature);
 
591
        actual += oi;
 
592
        
 
593
        char buf[30];
 
594
 
 
595
        if (i < phaseResetDf.size()) {
 
596
            feature.values.clear();
 
597
            feature.values.push_back(phaseResetDf[i]);
 
598
            sprintf(buf, "%d", int(baseCount + i));
 
599
            feature.label = buf;
 
600
            features[m_phaseResetDfOutput].push_back(feature);
 
601
        }
 
602
 
 
603
        if (i < smoothedDf.size()) {
 
604
            feature.values.clear();
 
605
            feature.values.push_back(smoothedDf[i]);
 
606
            features[m_smoothedPhaseResetDfOutput].push_back(feature);
 
607
        }
 
608
 
 
609
        if (hard) {
 
610
            feature.values.clear();
 
611
            feature.label = "Phase Reset";
 
612
            features[m_phaseResetPointsOutput].push_back(feature);
 
613
        }
 
614
 
 
615
        if (hard || soft) {
 
616
            feature.values.clear();
 
617
            feature.label = "Time Sync";
 
618
            features[m_timeSyncPointsOutput].push_back(feature);
 
619
        }            
 
620
    }
 
621
 
 
622
    if (includeFinal) {
 
623
        Vamp::RealTime t = Vamp::RealTime::frame2RealTime
 
624
            (inputIncrement * (baseCount + outputIncrements.size()), rate);
 
625
        Feature feature;
 
626
        feature.hasTimestamp = true;
 
627
        feature.timestamp = t;
 
628
        feature.label = Vamp::RealTime::frame2RealTime(actual, rate).toText();
 
629
        feature.values.clear();
 
630
        feature.values.push_back(float(actual));
 
631
        features[m_aggregateIncrementsOutput].push_back(feature);
 
632
 
 
633
        float linear = ((baseCount + outputIncrements.size())
 
634
                        * inputIncrement * overallRatio);
 
635
        feature.values.clear();
 
636
        feature.values.push_back(actual - linear);
 
637
        feature.label =  // see earlier comment
 
638
            (Vamp::RealTime::frame2RealTime //!!! update this as earlier label
 
639
             (lrintf((actual - linear) * 1000), rate) / 1000)
 
640
            .toText();
 
641
        features[m_divergenceOutput].push_back(feature);
 
642
    }
 
643
 
 
644
    m_accumulatedIncrement = actual;
 
645
 
 
646
    return features;
 
647
}
 
648