| 398 | struct ex_frequency_modulation : public labsound_example |
| 399 | { |
| 400 | virtual void play(int argc, char ** argv) override |
| 401 | { |
| 402 | UniformRandomGenerator fmrng; |
| 403 | |
| 404 | const auto defaultAudioDeviceConfigurations = GetDefaultAudioDeviceConfiguration(); |
| 405 | context = lab::MakeRealtimeAudioContext(defaultAudioDeviceConfigurations.second, defaultAudioDeviceConfigurations.first); |
| 406 | lab::AudioContext& ac = *context.get(); |
| 407 | |
| 408 | std::shared_ptr<OscillatorNode> modulator; |
| 409 | std::shared_ptr<GainNode> modulatorGain; |
| 410 | std::shared_ptr<OscillatorNode> osc; |
| 411 | std::shared_ptr<ADSRNode> trigger; |
| 412 | |
| 413 | std::shared_ptr<GainNode> signalGain; |
| 414 | std::shared_ptr<GainNode> feedbackTap; |
| 415 | std::shared_ptr<DelayNode> chainDelay; |
| 416 | |
| 417 | { |
| 418 | modulator = std::make_shared<OscillatorNode>(ac); |
| 419 | modulator->setType(OscillatorType::TRIANGLE); |
| 420 | modulator->start(0); |
| 421 | |
| 422 | modulatorGain = std::make_shared<GainNode>(ac); |
| 423 | |
| 424 | osc = std::make_shared<OscillatorNode>(ac); |
| 425 | osc->setType(OscillatorType::SINE); |
| 426 | osc->frequency()->setValue(300); |
| 427 | osc->start(0); |
| 428 | |
| 429 | trigger = std::make_shared<ADSRNode>(ac); |
| 430 | trigger->oneShot()->setBool(true); |
| 431 | |
| 432 | signalGain = std::make_shared<GainNode>(ac); |
| 433 | signalGain->gain()->setValue(1.0f); |
| 434 | |
| 435 | feedbackTap = std::make_shared<GainNode>(ac); |
| 436 | feedbackTap->gain()->setValue(0.5f); |
| 437 | |
| 438 | chainDelay = std::make_shared<DelayNode>(ac, 4); |
| 439 | chainDelay->delayTime()->setFloat(0.0f); // passthrough delay, not sure if this has the same DSP semantic as ChucK |
| 440 | |
| 441 | // device |
| 442 | // signalGain <- chainDelay <- feedbackTap <- signalGain <- trigger <- osc |
| 443 | // osc->freq <- modulatorGain <- modulator |
| 444 | |
| 445 | // Set up FM processing chain: |
| 446 | context->connect(modulatorGain, modulator, 0, 0); // Modulator to Gain |
| 447 | context->connectParam(osc->frequency(), modulatorGain, 0); // Gain to frequency parameter |
| 448 | |
| 449 | #if 1 |
| 450 | // with adsr |
| 451 | context->connect(trigger, osc, 0, 0); // Osc to ADSR |
| 452 | context->connect(signalGain, trigger, 0, 0); // ADSR to signalGain |
| 453 | #else |
| 454 | // sans adsr |
| 455 | context->connect(signalGain, osc, 0, 0); // Osc to ADSR |
| 456 | #endif |
| 457 |
nothing calls this directly
no test coverage detected