comparison src/vamp-hostsdk/PluginInputDomainAdapter.cpp @ 288:283e15f6e548

* The beginnings of making the shift-timestamp or shift-data behaviour of PluginInputDomainAdapter into an option
author cannam
date Tue, 15 Sep 2009 16:24:53 +0000
parents 6c9f10b8a53a
children 3e5ab1c7ea8c
comparison
equal deleted inserted replaced
287:f3b1ba71a305 288:283e15f6e548
81 public: 81 public:
82 Impl(Plugin *plugin, float inputSampleRate); 82 Impl(Plugin *plugin, float inputSampleRate);
83 ~Impl(); 83 ~Impl();
84 84
85 bool initialise(size_t channels, size_t stepSize, size_t blockSize); 85 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
86 void reset();
86 87
87 size_t getPreferredStepSize() const; 88 size_t getPreferredStepSize() const;
88 size_t getPreferredBlockSize() const; 89 size_t getPreferredBlockSize() const;
89 90
90 FeatureSet process(const float *const *inputBuffers, RealTime timestamp); 91 FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
92
93 void setProcessTimestampMethod(ProcessTimestampMethod m);
94 ProcessTimestampMethod getProcessTimestampMethod() const;
91 95
92 RealTime getTimestampAdjustment() const; 96 RealTime getTimestampAdjustment() const;
93 97
94 protected: 98 protected:
95 Plugin *m_plugin; 99 Plugin *m_plugin;
96 float m_inputSampleRate; 100 float m_inputSampleRate;
97 int m_channels; 101 int m_channels;
102 int m_stepSize;
98 int m_blockSize; 103 int m_blockSize;
99 float **m_freqbuf; 104 float **m_freqbuf;
100 105
101 double *m_ri; 106 double *m_ri;
102 double *m_window; 107 double *m_window;
108
109 ProcessTimestampMethod m_method;
110 int m_processCount;
111 FeatureSet prepadProcess(const float *const *inputBuffers,
112 RealTime timestamp);
103 113
104 #ifdef HAVE_FFTW3 114 #ifdef HAVE_FFTW3
105 fftw_plan m_plan; 115 fftw_plan m_plan;
106 fftw_complex *m_cbuf; 116 fftw_complex *m_cbuf;
107 #else 117 #else
129 PluginInputDomainAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize) 139 PluginInputDomainAdapter::initialise(size_t channels, size_t stepSize, size_t blockSize)
130 { 140 {
131 return m_impl->initialise(channels, stepSize, blockSize); 141 return m_impl->initialise(channels, stepSize, blockSize);
132 } 142 }
133 143
144 void
145 PluginInputDomainAdapter::reset()
146 {
147 m_impl->reset();
148 }
149
134 Plugin::InputDomain 150 Plugin::InputDomain
135 PluginInputDomainAdapter::getInputDomain() const 151 PluginInputDomainAdapter::getInputDomain() const
136 { 152 {
137 return TimeDomain; 153 return TimeDomain;
138 } 154 }
151 167
152 Plugin::FeatureSet 168 Plugin::FeatureSet
153 PluginInputDomainAdapter::process(const float *const *inputBuffers, RealTime timestamp) 169 PluginInputDomainAdapter::process(const float *const *inputBuffers, RealTime timestamp)
154 { 170 {
155 return m_impl->process(inputBuffers, timestamp); 171 return m_impl->process(inputBuffers, timestamp);
172 }
173
174 void
175 PluginInputDomainAdapter::setProcessTimestampMethod(ProcessTimestampMethod m)
176 {
177 m_impl->setProcessTimestampMethod(m);
178 }
179
180 PluginInputDomainAdapter::ProcessTimestampMethod
181 PluginInputDomainAdapter::getProcessTimestampMethod() const
182 {
183 return m_impl->getProcessTimestampMethod();
156 } 184 }
157 185
158 RealTime 186 RealTime
159 PluginInputDomainAdapter::getTimestampAdjustment() const 187 PluginInputDomainAdapter::getTimestampAdjustment() const
160 { 188 {
164 192
165 PluginInputDomainAdapter::Impl::Impl(Plugin *plugin, float inputSampleRate) : 193 PluginInputDomainAdapter::Impl::Impl(Plugin *plugin, float inputSampleRate) :
166 m_plugin(plugin), 194 m_plugin(plugin),
167 m_inputSampleRate(inputSampleRate), 195 m_inputSampleRate(inputSampleRate),
168 m_channels(0), 196 m_channels(0),
197 m_stepSize(0),
169 m_blockSize(0), 198 m_blockSize(0),
170 m_freqbuf(0), 199 m_freqbuf(0),
171 m_ri(0), 200 m_ri(0),
172 m_window(0), 201 m_window(0),
202 m_method(ShiftTimestamp),
203 m_processCount(0),
173 #ifdef HAVE_FFTW3 204 #ifdef HAVE_FFTW3
174 m_plan(0), 205 m_plan(0),
175 m_cbuf(0) 206 m_cbuf(0)
176 #else 207 #else
177 m_ro(0), 208 m_ro(0),
213 bool 244 bool
214 PluginInputDomainAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t blockSize) 245 PluginInputDomainAdapter::Impl::initialise(size_t channels, size_t stepSize, size_t blockSize)
215 { 246 {
216 if (m_plugin->getInputDomain() == TimeDomain) { 247 if (m_plugin->getInputDomain() == TimeDomain) {
217 248
249 m_stepSize = int(stepSize);
218 m_blockSize = int(blockSize); 250 m_blockSize = int(blockSize);
219 m_channels = int(channels); 251 m_channels = int(channels);
220 252
221 return m_plugin->initialise(channels, stepSize, blockSize); 253 return m_plugin->initialise(channels, stepSize, blockSize);
222 } 254 }
249 delete[] m_io; 281 delete[] m_io;
250 #endif 282 #endif
251 delete[] m_window; 283 delete[] m_window;
252 } 284 }
253 285
286 m_stepSize = int(stepSize);
254 m_blockSize = int(blockSize); 287 m_blockSize = int(blockSize);
255 m_channels = int(channels); 288 m_channels = int(channels);
256 289
257 m_freqbuf = new float *[m_channels]; 290 m_freqbuf = new float *[m_channels];
258 for (int c = 0; c < m_channels; ++c) { 291 for (int c = 0; c < m_channels; ++c) {
273 m_ri = new double[m_blockSize]; 306 m_ri = new double[m_blockSize];
274 m_ro = new double[m_blockSize]; 307 m_ro = new double[m_blockSize];
275 m_io = new double[m_blockSize]; 308 m_io = new double[m_blockSize];
276 #endif 309 #endif
277 310
311 m_processCount = 0;
312
278 return m_plugin->initialise(channels, stepSize, blockSize); 313 return m_plugin->initialise(channels, stepSize, blockSize);
314 }
315
316 void
317 PluginInputDomainAdapter::Impl::reset()
318 {
319 m_processCount = 0;
320 m_plugin->reset();
279 } 321 }
280 322
281 size_t 323 size_t
282 PluginInputDomainAdapter::Impl::getPreferredStepSize() const 324 PluginInputDomainAdapter::Impl::getPreferredStepSize() const
283 { 325 {
356 return RealTime::zeroTime; 398 return RealTime::zeroTime;
357 } else { 399 } else {
358 return RealTime::frame2RealTime 400 return RealTime::frame2RealTime
359 (m_blockSize/2, int(m_inputSampleRate + 0.5)); 401 (m_blockSize/2, int(m_inputSampleRate + 0.5));
360 } 402 }
403 }
404
405 void
406 PluginInputDomainAdapter::Impl::setProcessTimestampMethod(ProcessTimestampMethod m)
407 {
408 m_method = m;
409 }
410
411 PluginInputDomainAdapter::ProcessTimestampMethod
412 PluginInputDomainAdapter::Impl::getProcessTimestampMethod() const
413 {
414 return m_method;
361 } 415 }
362 416
363 Plugin::FeatureSet 417 Plugin::FeatureSet
364 PluginInputDomainAdapter::Impl::process(const float *const *inputBuffers, 418 PluginInputDomainAdapter::Impl::process(const float *const *inputBuffers,
365 RealTime timestamp) 419 RealTime timestamp)
410 // particular that this means some results can differ from those 464 // particular that this means some results can differ from those
411 // produced by SV. 465 // produced by SV.
412 466
413 // std::cerr << "PluginInputDomainAdapter: sampleRate " << m_inputSampleRate << ", blocksize " << m_blockSize << ", adjusting time from " << timestamp; 467 // std::cerr << "PluginInputDomainAdapter: sampleRate " << m_inputSampleRate << ", blocksize " << m_blockSize << ", adjusting time from " << timestamp;
414 468
415 timestamp = timestamp + getTimestampAdjustment(); 469 //!!! update the above comment for ProcessTimestampMethod
470
471 FeatureSet fs;
472 if (m_method == ShiftTimestamp) {
473 timestamp = timestamp + getTimestampAdjustment();
474 } else if (m_processCount == 0) {
475 fs = prepadProcess(inputBuffers, timestamp);
476 }
477 ++m_processCount;
416 478
417 // std::cerr << " to " << timestamp << std::endl; 479 // std::cerr << " to " << timestamp << std::endl;
418 480
419 for (int c = 0; c < m_channels; ++c) { 481 for (int c = 0; c < m_channels; ++c) {
420 482
448 } 510 }
449 511
450 #endif 512 #endif
451 } 513 }
452 514
453 return m_plugin->process(m_freqbuf, timestamp); 515 FeatureSet pfs(m_plugin->process(m_freqbuf, timestamp));
516
517 if (!fs.empty()) { // add any prepad results back in
518 for (FeatureSet::const_iterator i = pfs.begin(); i != pfs.end(); ++i) {
519 for (FeatureList::const_iterator j = i->second.begin();
520 j != i->second.end(); ++j) {
521 fs[i->first].push_back(*j);
522 }
523 }
524 pfs = fs;
525 }
526
527 return pfs;
528 }
529
530 Plugin::FeatureSet
531 PluginInputDomainAdapter::Impl::prepadProcess(const float *const *inputBuffers,
532 RealTime timestamp)
533 {
534 FeatureSet fs;
535 //!!!
536 return fs;
454 } 537 }
455 538
456 #ifndef HAVE_FFTW3 539 #ifndef HAVE_FFTW3
457 540
458 void 541 void