MCPcopy Create free account
hub / github.com/LabSound/LabSound / play

Method play

examples/src/Examples.hpp:652–718  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

650struct ex_peak_compressor : public labsound_example
651{
652 virtual void play(int argc, char ** argv) override
653 {
654 const auto defaultAudioDeviceConfigurations = GetDefaultAudioDeviceConfiguration();
655 context = lab::MakeRealtimeAudioContext(defaultAudioDeviceConfigurations.second, defaultAudioDeviceConfigurations.first);
656 lab::AudioContext& ac = *context.get();
657
658 std::shared_ptr<AudioBus> kick = MakeBusFromSampleFile("samples/kick.wav", argc, argv);
659 std::shared_ptr<AudioBus> hihat = MakeBusFromSampleFile("samples/hihat.wav", argc, argv);
660 std::shared_ptr<AudioBus> snare = MakeBusFromSampleFile("samples/snare.wav", argc, argv);
661
662 std::shared_ptr<SampledAudioNode> kick_node = std::make_shared<SampledAudioNode>(ac);
663 std::shared_ptr<SampledAudioNode> hihat_node = std::make_shared<SampledAudioNode>(ac);
664 std::shared_ptr<SampledAudioNode> snare_node = std::make_shared<SampledAudioNode>(ac);
665
666 std::shared_ptr<BiquadFilterNode> filter;
667 std::shared_ptr<PeakCompNode> peakComp;
668
669 {
670 ContextRenderLock r(context.get(), "ex_peak_compressor");
671
672 filter = std::make_shared<BiquadFilterNode>(ac);
673 filter->setType(lab::FilterType::LOWPASS);
674 filter->frequency()->setValue(1800.f);
675
676 peakComp = std::make_shared<PeakCompNode>(ac);
677 context->connect(peakComp, filter, 0, 0);
678 context->connect(context->device(), peakComp, 0, 0);
679
680 kick_node->setBus(r, kick);
681 context->connect(filter, kick_node, 0, 0);
682
683 hihat_node->setBus(r, hihat);
684 context->connect(filter, hihat_node, 0, 0);
685 //hihat_node->gain()->setValue(0.2f);
686
687 snare_node->setBus(r, snare);
688 context->connect(filter, snare_node, 0, 0);
689
690 _nodes.push_back(kick_node);
691 _nodes.push_back(hihat_node);
692 _nodes.push_back(snare_node);
693 _nodes.push_back(peakComp);
694 _nodes.push_back(filter);
695 }
696
697 // Speed Metal
698 float startTime = 0.1f;
699 float bpm = 30.f;
700 float bar_length = 60.f / bpm;
701 float eighthNoteTime = bar_length / 8.0f;
702 for (float bar = 0; bar < 8; bar += 1)
703 {
704 float time = startTime + bar * bar_length;
705
706 kick_node->schedule(time);
707 kick_node->schedule(time + 4 * eighthNoteTime);
708
709 snare_node->schedule(time + 2 * eighthNoteTime);

Callers

nothing calls this directly

Calls 10

MakeRealtimeAudioContextFunction · 0.85
getMethod · 0.80
setValueMethod · 0.80
deviceMethod · 0.80
scheduleMethod · 0.80
setTypeMethod · 0.45
frequencyMethod · 0.45
connectMethod · 0.45
setBusMethod · 0.45

Tested by

no test coverage detected