Mercurial > hg > svapp
comparison audioio/AudioGenerator.cpp @ 295:14b1768e5406 tonioni
Merge from default branch
author | Chris Cannam |
---|---|
date | Tue, 26 Nov 2013 14:39:57 +0000 |
parents | cba1e2a3d14b 933b5aed341a |
children | ae1eedd6951f |
comparison
equal
deleted
inserted
replaced
292:bc78f88a66f5 | 295:14b1768e5406 |
---|---|
77 if (m_sampleDir != "") return; | 77 if (m_sampleDir != "") return; |
78 | 78 |
79 try { | 79 try { |
80 m_sampleDir = TempDirectory::getInstance()->getSubDirectoryPath("samples"); | 80 m_sampleDir = TempDirectory::getInstance()->getSubDirectoryPath("samples"); |
81 } catch (DirectoryCreationFailed f) { | 81 } catch (DirectoryCreationFailed f) { |
82 std::cerr << "WARNING: AudioGenerator::initialiseSampleDir:" | 82 cerr << "WARNING: AudioGenerator::initialiseSampleDir:" |
83 << " Failed to create temporary sample directory" | 83 << " Failed to create temporary sample directory" |
84 << std::endl; | 84 << endl; |
85 m_sampleDir = ""; | 85 m_sampleDir = ""; |
86 return; | 86 return; |
87 } | 87 } |
88 | 88 |
89 QDir sampleResourceDir(":/samples", "*.wav"); | 89 QDir sampleResourceDir(":/samples", "*.wav"); |
93 QString fileName(sampleResourceDir[i]); | 93 QString fileName(sampleResourceDir[i]); |
94 QFile file(sampleResourceDir.filePath(fileName)); | 94 QFile file(sampleResourceDir.filePath(fileName)); |
95 QString target = QDir(m_sampleDir).filePath(fileName); | 95 QString target = QDir(m_sampleDir).filePath(fileName); |
96 | 96 |
97 if (!file.copy(target)) { | 97 if (!file.copy(target)) { |
98 std::cerr << "WARNING: AudioGenerator::getSampleDir: " | 98 cerr << "WARNING: AudioGenerator::getSampleDir: " |
99 << "Unable to copy " << fileName.toStdString() | 99 << "Unable to copy " << fileName |
100 << " into temporary directory \"" | 100 << " into temporary directory \"" |
101 << m_sampleDir << "\"" << std::endl; | 101 << m_sampleDir << "\"" << endl; |
102 } else { | 102 } else { |
103 QFile tf(target); | 103 QFile tf(target); |
104 tf.setPermissions(tf.permissions() | | 104 tf.setPermissions(tf.permissions() | |
105 QFile::WriteOwner | | 105 QFile::WriteOwner | |
106 QFile::WriteUser); | 106 QFile::WriteUser); |
139 void | 139 void |
140 AudioGenerator::playPluginIdChanged(const Playable *playable, QString) | 140 AudioGenerator::playPluginIdChanged(const Playable *playable, QString) |
141 { | 141 { |
142 const Model *model = dynamic_cast<const Model *>(playable); | 142 const Model *model = dynamic_cast<const Model *>(playable); |
143 if (!model) { | 143 if (!model) { |
144 std::cerr << "WARNING: AudioGenerator::playPluginIdChanged: playable " | 144 cerr << "WARNING: AudioGenerator::playPluginIdChanged: playable " |
145 << playable << " is not a supported model type" | 145 << playable << " is not a supported model type" |
146 << std::endl; | 146 << endl; |
147 return; | 147 return; |
148 } | 148 } |
149 | 149 |
150 if (m_synthMap.find(model) == m_synthMap.end()) return; | 150 if (m_synthMap.find(model) == m_synthMap.end()) return; |
151 | 151 |
163 { | 163 { |
164 // SVDEBUG << "AudioGenerator::playPluginConfigurationChanged" << endl; | 164 // SVDEBUG << "AudioGenerator::playPluginConfigurationChanged" << endl; |
165 | 165 |
166 const Model *model = dynamic_cast<const Model *>(playable); | 166 const Model *model = dynamic_cast<const Model *>(playable); |
167 if (!model) { | 167 if (!model) { |
168 std::cerr << "WARNING: AudioGenerator::playPluginIdChanged: playable " | 168 cerr << "WARNING: AudioGenerator::playPluginIdChanged: playable " |
169 << playable << " is not a supported model type" | 169 << playable << " is not a supported model type" |
170 << std::endl; | 170 << endl; |
171 return; | 171 return; |
172 } | 172 } |
173 | 173 |
174 if (m_synthMap.find(model) == m_synthMap.end()) { | 174 if (m_synthMap.find(model) == m_synthMap.end()) { |
175 SVDEBUG << "AudioGenerator::playPluginConfigurationChanged: We don't know about this plugin" << endl; | 175 SVDEBUG << "AudioGenerator::playPluginConfigurationChanged: We don't know about this plugin" << endl; |
238 { | 238 { |
239 RealTimePluginFactory *factory = | 239 RealTimePluginFactory *factory = |
240 RealTimePluginFactory::instanceFor(pluginId); | 240 RealTimePluginFactory::instanceFor(pluginId); |
241 | 241 |
242 if (!factory) { | 242 if (!factory) { |
243 std::cerr << "Failed to get plugin factory" << std::endl; | 243 cerr << "Failed to get plugin factory" << endl; |
244 return 0; | 244 return 0; |
245 } | 245 } |
246 | 246 |
247 RealTimePluginInstance *instance = | 247 RealTimePluginInstance *instance = |
248 factory->instantiatePlugin | 248 factory->instantiatePlugin |
249 (pluginId, 0, 0, m_sourceSampleRate, m_pluginBlockSize, m_targetChannelCount); | 249 (pluginId, 0, 0, m_sourceSampleRate, m_pluginBlockSize, m_targetChannelCount); |
250 | 250 |
251 if (!instance) { | 251 if (!instance) { |
252 std::cerr << "Failed to instantiate plugin " << pluginId << std::endl; | 252 cerr << "Failed to instantiate plugin " << pluginId << endl; |
253 return 0; | 253 return 0; |
254 } | 254 } |
255 | 255 |
256 setSampleDir(instance); | 256 setSampleDir(instance); |
257 | 257 |
258 for (unsigned int i = 0; i < instance->getParameterCount(); ++i) { | 258 for (unsigned int i = 0; i < instance->getParameterCount(); ++i) { |
259 instance->setParameterValue(i, instance->getParameterDefault(i)); | 259 instance->setParameterValue(i, instance->getParameterDefault(i)); |
260 } | 260 } |
261 std::string defaultProgram = instance->getProgram(0, 0); | 261 std::string defaultProgram = instance->getProgram(0, 0); |
262 if (defaultProgram != "") { | 262 if (defaultProgram != "") { |
263 std::cerr << "first selecting default program " << defaultProgram << std::endl; | 263 cerr << "first selecting default program " << defaultProgram << endl; |
264 instance->selectProgram(defaultProgram); | 264 instance->selectProgram(defaultProgram); |
265 } | 265 } |
266 if (program != "") { | 266 if (program != "") { |
267 std::cerr << "now selecting desired program " << program << std::endl; | 267 cerr << "now selecting desired program " << program << endl; |
268 instance->selectProgram(program.toStdString()); | 268 instance->selectProgram(program.toStdString()); |
269 } | 269 } |
270 instance->setIdealChannelCount(m_targetChannelCount); // reset! | 270 instance->setIdealChannelCount(m_targetChannelCount); // reset! |
271 | 271 |
272 return instance; | 272 return instance; |
355 size_t | 355 size_t |
356 AudioGenerator::mixModel(Model *model, size_t startFrame, size_t frameCount, | 356 AudioGenerator::mixModel(Model *model, size_t startFrame, size_t frameCount, |
357 float **buffer, size_t fadeIn, size_t fadeOut) | 357 float **buffer, size_t fadeIn, size_t fadeOut) |
358 { | 358 { |
359 if (m_sourceSampleRate == 0) { | 359 if (m_sourceSampleRate == 0) { |
360 std::cerr << "WARNING: AudioGenerator::mixModel: No base source sample rate available" << std::endl; | 360 cerr << "WARNING: AudioGenerator::mixModel: No base source sample rate available" << endl; |
361 return frameCount; | 361 return frameCount; |
362 } | 362 } |
363 | 363 |
364 QMutexLocker locker(&m_mutex); | 364 QMutexLocker locker(&m_mutex); |
365 | 365 |
371 if (!parameters) return frameCount; | 371 if (!parameters) return frameCount; |
372 | 372 |
373 bool playing = !parameters->isPlayMuted(); | 373 bool playing = !parameters->isPlayMuted(); |
374 if (!playing) { | 374 if (!playing) { |
375 #ifdef DEBUG_AUDIO_GENERATOR | 375 #ifdef DEBUG_AUDIO_GENERATOR |
376 std::cout << "AudioGenerator::mixModel(" << model << "): muted" << std::endl; | 376 cout << "AudioGenerator::mixModel(" << model << "): muted" << endl; |
377 #endif | 377 #endif |
378 return frameCount; | 378 return frameCount; |
379 } | 379 } |
380 | 380 |
381 if (m_soloing) { | 381 if (m_soloing) { |
382 if (m_soloModelSet.find(model) == m_soloModelSet.end()) { | 382 if (m_soloModelSet.find(model) == m_soloModelSet.end()) { |
383 #ifdef DEBUG_AUDIO_GENERATOR | 383 #ifdef DEBUG_AUDIO_GENERATOR |
384 std::cout << "AudioGenerator::mixModel(" << model << "): not one of the solo'd models" << std::endl; | 384 cout << "AudioGenerator::mixModel(" << model << "): not one of the solo'd models" << endl; |
385 #endif | 385 #endif |
386 return frameCount; | 386 return frameCount; |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
530 //calls to mixModel | 530 //calls to mixModel |
531 | 531 |
532 size_t got = blocks * m_pluginBlockSize; | 532 size_t got = blocks * m_pluginBlockSize; |
533 | 533 |
534 #ifdef DEBUG_AUDIO_GENERATOR | 534 #ifdef DEBUG_AUDIO_GENERATOR |
535 std::cout << "mixModel [synthetic note]: frames " << frames | 535 cout << "mixModel [synthetic note]: frames " << frames |
536 << ", blocks " << blocks << std::endl; | 536 << ", blocks " << blocks << endl; |
537 #endif | 537 #endif |
538 | 538 |
539 snd_seq_event_t onEv; | 539 snd_seq_event_t onEv; |
540 onEv.type = SND_SEQ_EVENT_NOTEON; | 540 onEv.type = SND_SEQ_EVENT_NOTEON; |
541 onEv.data.note.channel = 0; | 541 onEv.data.note.channel = 0; |
575 (noteOffs.begin()->frame, m_sourceSampleRate); | 575 (noteOffs.begin()->frame, m_sourceSampleRate); |
576 | 576 |
577 offEv.data.note.note = noteOffs.begin()->pitch; | 577 offEv.data.note.note = noteOffs.begin()->pitch; |
578 | 578 |
579 #ifdef DEBUG_AUDIO_GENERATOR | 579 #ifdef DEBUG_AUDIO_GENERATOR |
580 std::cerr << "mixModel [synthetic]: sending note-off event at time " << eventTime << " frame " << noteOffs.begin()->frame << " pitch " << noteOffs.begin()->pitch << std::endl; | 580 cerr << "mixModel [synthetic]: sending note-off event at time " << eventTime << " frame " << noteOffs.begin()->frame << " pitch " << noteOffs.begin()->pitch << endl; |
581 #endif | 581 #endif |
582 | 582 |
583 plugin->sendEvent(eventTime, &offEv); | 583 plugin->sendEvent(eventTime, &offEv); |
584 noteOffs.erase(noteOffs.begin()); | 584 noteOffs.erase(noteOffs.begin()); |
585 } | 585 } |
589 | 589 |
590 if (ni->isMidiPitchQuantized) { | 590 if (ni->isMidiPitchQuantized) { |
591 onEv.data.note.note = ni->midiPitch; | 591 onEv.data.note.note = ni->midiPitch; |
592 } else { | 592 } else { |
593 #ifdef DEBUG_AUDIO_GENERATOR | 593 #ifdef DEBUG_AUDIO_GENERATOR |
594 std::cerr << "mixModel [synthetic]: non-pitch-quantized notes are not supported [yet], quantizing" << std::endl; | 594 cerr << "mixModel [synthetic]: non-pitch-quantized notes are not supported [yet], quantizing" << endl; |
595 #endif | 595 #endif |
596 onEv.data.note.note = Pitch::getPitchForFrequency(ni->frequency); | 596 onEv.data.note.note = Pitch::getPitchForFrequency(ni->frequency); |
597 } | 597 } |
598 | 598 |
599 onEv.data.note.velocity = ni->velocity; | 599 onEv.data.note.velocity = ni->velocity; |
600 | 600 |
601 plugin->sendEvent(eventTime, &onEv); | 601 plugin->sendEvent(eventTime, &onEv); |
602 | 602 |
603 #ifdef DEBUG_AUDIO_GENERATOR | 603 #ifdef DEBUG_AUDIO_GENERATOR |
604 std::cout << "mixModel [synthetic]: note at frame " << noteFrame << ", block start " << (startFrame + i * m_pluginBlockSize) << ", resulting time " << eventTime << std::endl; | 604 cout << "mixModel [synthetic]: note at frame " << noteFrame << ", block start " << (startFrame + i * m_pluginBlockSize) << ", resulting time " << eventTime << endl; |
605 #endif | 605 #endif |
606 | 606 |
607 noteOffs.insert | 607 noteOffs.insert |
608 (NoteOff(onEv.data.note.note, noteFrame + ni->duration)); | 608 (NoteOff(onEv.data.note.note, noteFrame + ni->duration)); |
609 } | 609 } |
616 (noteOffs.begin()->frame, m_sourceSampleRate); | 616 (noteOffs.begin()->frame, m_sourceSampleRate); |
617 | 617 |
618 offEv.data.note.note = noteOffs.begin()->pitch; | 618 offEv.data.note.note = noteOffs.begin()->pitch; |
619 | 619 |
620 #ifdef DEBUG_AUDIO_GENERATOR | 620 #ifdef DEBUG_AUDIO_GENERATOR |
621 std::cerr << "mixModel [synthetic]: sending leftover note-off event at time " << eventTime << " frame " << noteOffs.begin()->frame << " pitch " << noteOffs.begin()->pitch << std::endl; | 621 cerr << "mixModel [synthetic]: sending leftover note-off event at time " << eventTime << " frame " << noteOffs.begin()->frame << " pitch " << noteOffs.begin()->pitch << endl; |
622 #endif | 622 #endif |
623 | 623 |
624 plugin->sendEvent(eventTime, &offEv); | 624 plugin->sendEvent(eventTime, &offEv); |
625 noteOffs.erase(noteOffs.begin()); | 625 noteOffs.erase(noteOffs.begin()); |
626 } | 626 } |
628 plugin->run(blockTime); | 628 plugin->run(blockTime); |
629 float **outs = plugin->getAudioOutputBuffers(); | 629 float **outs = plugin->getAudioOutputBuffers(); |
630 | 630 |
631 for (size_t c = 0; c < m_targetChannelCount; ++c) { | 631 for (size_t c = 0; c < m_targetChannelCount; ++c) { |
632 #ifdef DEBUG_AUDIO_GENERATOR | 632 #ifdef DEBUG_AUDIO_GENERATOR |
633 std::cout << "mixModel [synthetic]: adding " << m_pluginBlockSize << " samples from plugin output " << c << std::endl; | 633 cout << "mixModel [synthetic]: adding " << m_pluginBlockSize << " samples from plugin output " << c << endl; |
634 #endif | 634 #endif |
635 | 635 |
636 size_t sourceChannel = (c % plugin->getAudioOutputCount()); | 636 size_t sourceChannel = (c % plugin->getAudioOutputCount()); |
637 | 637 |
638 float channelGain = gain; | 638 float channelGain = gain; |