comparison plugin/LADSPAPluginInstance.cpp @ 1040:a1cd5abcb38b cxx11

Introduce and use a samplerate type
author Chris Cannam
date Wed, 04 Mar 2015 12:01:04 +0000
parents b14064bd1f97
children 48e9f538e6e9
comparison
equal deleted inserted replaced
1039:b14064bd1f97 1040:a1cd5abcb38b
35 35
36 LADSPAPluginInstance::LADSPAPluginInstance(RealTimePluginFactory *factory, 36 LADSPAPluginInstance::LADSPAPluginInstance(RealTimePluginFactory *factory,
37 int clientId, 37 int clientId,
38 QString identifier, 38 QString identifier,
39 int position, 39 int position,
40 unsigned long sampleRate, 40 sv_samplerate_t sampleRate,
41 size_t blockSize, 41 int blockSize,
42 int idealChannelCount, 42 int idealChannelCount,
43 const LADSPA_Descriptor* descriptor) : 43 const LADSPA_Descriptor* descriptor) :
44 RealTimePluginInstance(factory, identifier), 44 RealTimePluginInstance(factory, identifier),
45 m_client(clientId), 45 m_client(clientId),
46 m_position(position), 46 m_position(position),
287 m_instanceCount = idealChannelCount; 287 m_instanceCount = idealChannelCount;
288 } 288 }
289 } 289 }
290 } 290 }
291 291
292 size_t 292 sv_frame_t
293 LADSPAPluginInstance::getLatency() 293 LADSPAPluginInstance::getLatency()
294 { 294 {
295 if (m_latencyPort) { 295 if (m_latencyPort) {
296 if (!m_run) { 296 if (!m_run) {
297 for (size_t i = 0; i < getAudioInputCount(); ++i) { 297 for (int i = 0; i < getAudioInputCount(); ++i) {
298 for (size_t j = 0; j < m_blockSize; ++j) { 298 for (int j = 0; j < m_blockSize; ++j) {
299 m_inputBuffers[i][j] = 0.f; 299 m_inputBuffers[i][j] = 0.f;
300 } 300 }
301 } 301 }
302 run(Vamp::RealTime::zeroTime); 302 run(Vamp::RealTime::zeroTime);
303 } 303 }
304 if (*m_latencyPort > 0) return (size_t)*m_latencyPort; 304 if (*m_latencyPort > 0) return (sv_frame_t)*m_latencyPort;
305 } 305 }
306 return 0; 306 return 0;
307 } 307 }
308 308
309 void 309 void
314 activate(); 314 activate();
315 } 315 }
316 } 316 }
317 317
318 void 318 void
319 LADSPAPluginInstance::setIdealChannelCount(size_t channels) 319 LADSPAPluginInstance::setIdealChannelCount(int channels)
320 { 320 {
321 if (m_audioPortsIn.size() != 1 || channels == m_instanceCount) { 321 if (m_audioPortsIn.size() != 1 || channels == m_instanceCount) {
322 silence(); 322 silence();
323 return; 323 return;
324 } 324 }
376 m_audioPortsOut.clear(); 376 m_audioPortsOut.clear();
377 } 377 }
378 378
379 379
380 void 380 void
381 LADSPAPluginInstance::instantiate(unsigned long sampleRate) 381 LADSPAPluginInstance::instantiate(sv_samplerate_t sampleRate)
382 { 382 {
383 if (!m_descriptor) return; 383 if (!m_descriptor) return;
384 384
385 #ifdef DEBUG_LADSPA 385 #ifdef DEBUG_LADSPA
386 cout << "LADSPAPluginInstance::instantiate - plugin unique id = " 386 cout << "LADSPAPluginInstance::instantiate - plugin unique id = "
392 << ":" << m_descriptor->Label 392 << ":" << m_descriptor->Label
393 << " has no instantiate method!" << endl; 393 << " has no instantiate method!" << endl;
394 return; 394 return;
395 } 395 }
396 396
397 for (size_t i = 0; i < m_instanceCount; ++i) { 397 unsigned long pluginRate = (unsigned long)(sampleRate);
398 if (sampleRate != sv_samplerate_t(pluginRate)) {
399 cerr << "LADSPAPluginInstance: WARNING: Non-integer sample rate "
400 << sampleRate << " presented, rounding to " << pluginRate
401 << endl;
402 }
403
404 for (int i = 0; i < m_instanceCount; ++i) {
398 m_instanceHandles.push_back 405 m_instanceHandles.push_back
399 (m_descriptor->instantiate(m_descriptor, sampleRate)); 406 (m_descriptor->instantiate(m_descriptor, pluginRate));
400 } 407 }
401 } 408 }
402 409
403 void 410 void
404 LADSPAPluginInstance::activate() 411 LADSPAPluginInstance::activate()
489 496
490 (*m_controlPortsIn[parameter].second) = value; 497 (*m_controlPortsIn[parameter].second) = value;
491 } 498 }
492 499
493 float 500 float
494 LADSPAPluginInstance::getControlOutputValue(size_t output) const 501 LADSPAPluginInstance::getControlOutputValue(int output) const
495 { 502 {
496 if (!in_range_for(m_controlPortsOut, output)) return 0.0; 503 if (!in_range_for(m_controlPortsOut, output)) return 0.0;
497 return (*m_controlPortsOut[output].second); 504 return (*m_controlPortsOut[output].second);
498 } 505 }
499 506
529 return PortHint::NoHint; 536 return PortHint::NoHint;
530 } 537 }
531 } 538 }
532 539
533 void 540 void
534 LADSPAPluginInstance::run(const Vamp::RealTime &, size_t count) 541 LADSPAPluginInstance::run(const RealTime &, int count)
535 { 542 {
536 if (!m_descriptor || !m_descriptor->run) return; 543 if (!m_descriptor || !m_descriptor->run) return;
537 544
538 if (count == 0) count = m_blockSize; 545 if (count == 0) count = m_blockSize;
539 546