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

Method play

examples/src/Examples.hpp:847–906  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

845struct ex_convolution_reverb : public labsound_example
846{
847 virtual void play(int argc, char ** argv) override
848 {
849 const auto defaultAudioDeviceConfigurations = GetDefaultAudioDeviceConfiguration();
850 context = lab::MakeRealtimeAudioContext(defaultAudioDeviceConfigurations.second, defaultAudioDeviceConfigurations.first);
851 lab::AudioContext& ac = *context.get();
852
853 std::shared_ptr<AudioBus> impulseResponseClip = MakeBusFromSampleFile("impulse/cardiod-rear-levelled.wav", argc, argv);
854 std::shared_ptr<AudioBus> voiceClip = MakeBusFromSampleFile("samples/voice.ogg", argc, argv);
855
856 if (!impulseResponseClip || !voiceClip)
857 {
858 std::cerr << "Could not open sample data\n";
859 return;
860 }
861
862 std::shared_ptr<ConvolverNode> convolve;
863 std::shared_ptr<GainNode> wetGain;
864 std::shared_ptr<GainNode> dryGain;
865 std::shared_ptr<SampledAudioNode> voiceNode;
866 std::shared_ptr<GainNode> outputGain = std::make_shared<GainNode>(ac);
867
868 {
869 // voice --+-> dry -------------------+
870 // | |
871 // +---> convolve ---> wet ---+--->out ---> device
872
873 ContextRenderLock r(context.get(), "ex_convolution_reverb");
874
875 convolve = std::make_shared<ConvolverNode>(ac);
876 convolve->setImpulse(impulseResponseClip);
877
878 wetGain = std::make_shared<GainNode>(ac);
879 wetGain->gain()->setValue(0.5f);
880 dryGain = std::make_shared<GainNode>(ac);
881 dryGain->gain()->setValue(0.1f);
882
883 context->connect(wetGain, convolve, 0, 0);
884 context->connect(outputGain, wetGain, 0, 0);
885 context->connect(outputGain, dryGain, 0, 0);
886 context->connect(convolve, dryGain, 0, 0);
887
888 outputGain->gain()->setValue(0.5f);
889
890 voiceNode = std::make_shared<SampledAudioNode>(ac);
891 voiceNode->setBus(r, voiceClip);
892 context->connect(dryGain, voiceNode, 0, 0);
893
894 voiceNode->schedule(0.0);
895
896 context->connect(context->device(), outputGain, 0, 0);
897 }
898
899 _nodes.push_back(convolve);
900 _nodes.push_back(wetGain);
901 _nodes.push_back(dryGain);
902 _nodes.push_back(voiceNode);
903 _nodes.push_back(outputGain);
904

Callers

nothing calls this directly

Calls 10

MakeRealtimeAudioContextFunction · 0.85
getMethod · 0.80
setImpulseMethod · 0.80
setValueMethod · 0.80
scheduleMethod · 0.80
deviceMethod · 0.80
gainMethod · 0.45
connectMethod · 0.45
setBusMethod · 0.45

Tested by

no test coverage detected