Mercurial > hg > svcore
comparison plugin/LADSPAPluginInstance.cpp @ 242:2f7d27648806
* Fix real-time plugin corruption when getLatency is called for some plugins
* Other minor changes
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2007 15:35:27 +0000 |
parents | 71f869dac40b |
children | dc46851837d6 |
comparison
equal
deleted
inserted
replaced
241:2b40f83e7627 | 242:2f7d27648806 |
---|---|
202 void | 202 void |
203 LADSPAPluginInstance::setParameter(std::string id, float value) | 203 LADSPAPluginInstance::setParameter(std::string id, float value) |
204 { | 204 { |
205 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { | 205 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { |
206 if (id == m_descriptor->PortNames[m_controlPortsIn[i].first]) { | 206 if (id == m_descriptor->PortNames[m_controlPortsIn[i].first]) { |
207 #ifdef DEBUG_LADSPA | |
207 std::cerr << "LADSPAPluginInstance::setParameter: Found id " | 208 std::cerr << "LADSPAPluginInstance::setParameter: Found id " |
208 << id << " at control port " << i << std::endl; | 209 << id << " at control port " << i << std::endl; |
210 #endif | |
209 setParameterValue(i, value); | 211 setParameterValue(i, value); |
210 break; | 212 break; |
211 } | 213 } |
212 } | 214 } |
213 } | 215 } |
220 << m_descriptor->PortCount << " ports" << std::endl; | 222 << m_descriptor->PortCount << " ports" << std::endl; |
221 #endif | 223 #endif |
222 | 224 |
223 // Discover ports numbers and identities | 225 // Discover ports numbers and identities |
224 // | 226 // |
225 for (unsigned long i = 0; i < m_descriptor->PortCount; ++i) | 227 for (unsigned long i = 0; i < m_descriptor->PortCount; ++i) { |
226 { | 228 |
227 if (LADSPA_IS_PORT_AUDIO(m_descriptor->PortDescriptors[i])) | 229 if (LADSPA_IS_PORT_AUDIO(m_descriptor->PortDescriptors[i])) { |
228 { | 230 |
229 if (LADSPA_IS_PORT_INPUT(m_descriptor->PortDescriptors[i])) { | 231 if (LADSPA_IS_PORT_INPUT(m_descriptor->PortDescriptors[i])) { |
230 #ifdef DEBUG_LADSPA | 232 #ifdef DEBUG_LADSPA |
231 std::cerr << "LADSPAPluginInstance::init: port " << i << " is audio in" << std::endl; | 233 std::cerr << "LADSPAPluginInstance::init: port " << i << " is audio in" << std::endl; |
232 #endif | 234 #endif |
233 m_audioPortsIn.push_back(i); | 235 m_audioPortsIn.push_back(i); |
235 #ifdef DEBUG_LADSPA | 237 #ifdef DEBUG_LADSPA |
236 std::cerr << "LADSPAPluginInstance::init: port " << i << " is audio out" << std::endl; | 238 std::cerr << "LADSPAPluginInstance::init: port " << i << " is audio out" << std::endl; |
237 #endif | 239 #endif |
238 m_audioPortsOut.push_back(i); | 240 m_audioPortsOut.push_back(i); |
239 } | 241 } |
240 } | 242 |
241 else | 243 } else if (LADSPA_IS_PORT_CONTROL(m_descriptor->PortDescriptors[i])) { |
242 if (LADSPA_IS_PORT_CONTROL(m_descriptor->PortDescriptors[i])) | 244 |
243 { | |
244 if (LADSPA_IS_PORT_INPUT(m_descriptor->PortDescriptors[i])) { | 245 if (LADSPA_IS_PORT_INPUT(m_descriptor->PortDescriptors[i])) { |
246 | |
245 #ifdef DEBUG_LADSPA | 247 #ifdef DEBUG_LADSPA |
246 std::cerr << "LADSPAPluginInstance::init: port " << i << " is control in" << std::endl; | 248 std::cerr << "LADSPAPluginInstance::init: port " << i << " is control in" << std::endl; |
247 #endif | 249 #endif |
248 LADSPA_Data *data = new LADSPA_Data(0.0); | 250 LADSPA_Data *data = new LADSPA_Data(0.0); |
249 m_controlPortsIn.push_back( | 251 m_controlPortsIn.push_back( |
250 std::pair<unsigned long, LADSPA_Data*>(i, data)); | 252 std::pair<unsigned long, LADSPA_Data*>(i, data)); |
253 | |
251 } else { | 254 } else { |
255 | |
252 #ifdef DEBUG_LADSPA | 256 #ifdef DEBUG_LADSPA |
253 std::cerr << "LADSPAPluginInstance::init: port " << i << " is control out" << std::endl; | 257 std::cerr << "LADSPAPluginInstance::init: port " << i << " is control out" << std::endl; |
254 #endif | 258 #endif |
255 LADSPA_Data *data = new LADSPA_Data(0.0); | 259 LADSPA_Data *data = new LADSPA_Data(0.0); |
256 m_controlPortsOut.push_back( | 260 m_controlPortsOut.push_back( |
260 #ifdef DEBUG_LADSPA | 264 #ifdef DEBUG_LADSPA |
261 std::cerr << "Wooo! We have a latency port!" << std::endl; | 265 std::cerr << "Wooo! We have a latency port!" << std::endl; |
262 #endif | 266 #endif |
263 m_latencyPort = data; | 267 m_latencyPort = data; |
264 } | 268 } |
269 | |
265 } | 270 } |
266 } | 271 } |
267 #ifdef DEBUG_LADSPA | 272 #ifdef DEBUG_LADSPA |
268 else | 273 else |
269 std::cerr << "LADSPAPluginInstance::init - " | 274 std::cerr << "LADSPAPluginInstance::init - " |
283 | 288 |
284 size_t | 289 size_t |
285 LADSPAPluginInstance::getLatency() | 290 LADSPAPluginInstance::getLatency() |
286 { | 291 { |
287 if (m_latencyPort) { | 292 if (m_latencyPort) { |
288 if (!m_run) run(Vamp::RealTime::zeroTime); | 293 if (!m_run) { |
294 for (int i = 0; i < getAudioInputCount(); ++i) { | |
295 for (int j = 0; j < m_blockSize; ++j) { | |
296 m_inputBuffers[i][j] = 0.f; | |
297 } | |
298 } | |
299 run(Vamp::RealTime::zeroTime); | |
300 } | |
289 if (*m_latencyPort > 0) return (size_t)*m_latencyPort; | 301 if (*m_latencyPort > 0) return (size_t)*m_latencyPort; |
290 } | 302 } |
291 return 0; | 303 return 0; |
292 } | 304 } |
293 | 305 |
504 void | 516 void |
505 LADSPAPluginInstance::run(const Vamp::RealTime &) | 517 LADSPAPluginInstance::run(const Vamp::RealTime &) |
506 { | 518 { |
507 if (!m_descriptor || !m_descriptor->run) return; | 519 if (!m_descriptor || !m_descriptor->run) return; |
508 | 520 |
521 int inbuf = 0, outbuf = 0; | |
522 | |
509 for (std::vector<LADSPA_Handle>::iterator hi = m_instanceHandles.begin(); | 523 for (std::vector<LADSPA_Handle>::iterator hi = m_instanceHandles.begin(); |
510 hi != m_instanceHandles.end(); ++hi) { | 524 hi != m_instanceHandles.end(); ++hi) { |
525 | |
511 m_descriptor->run(*hi, m_blockSize); | 526 m_descriptor->run(*hi, m_blockSize); |
512 } | 527 } |
513 | 528 |
514 m_run = true; | 529 m_run = true; |
515 } | 530 } |