| 726 | struct ex_stereo_panning : public labsound_example |
| 727 | { |
| 728 | virtual void play(int argc, char ** argv) override |
| 729 | { |
| 730 | const auto defaultAudioDeviceConfigurations = GetDefaultAudioDeviceConfiguration(false); |
| 731 | context = lab::MakeRealtimeAudioContext(defaultAudioDeviceConfigurations.second, defaultAudioDeviceConfigurations.first); |
| 732 | lab::AudioContext& ac = *context.get(); |
| 733 | |
| 734 | std::shared_ptr<AudioBus> audioClip = MakeBusFromSampleFile("samples/trainrolling.wav", argc, argv); |
| 735 | std::shared_ptr<SampledAudioNode> audioClipNode = std::make_shared<SampledAudioNode>(ac); |
| 736 | auto stereoPanner = std::make_shared<StereoPannerNode>(ac); |
| 737 | |
| 738 | { |
| 739 | ContextRenderLock r(context.get(), "ex_stereo_panning"); |
| 740 | |
| 741 | audioClipNode->setBus(r, audioClip); |
| 742 | context->connect(stereoPanner, audioClipNode, 0, 0); |
| 743 | audioClipNode->schedule(0.0, -1); // -1 to loop forever |
| 744 | |
| 745 | context->connect(context->device(), stereoPanner, 0, 0); |
| 746 | } |
| 747 | |
| 748 | if (audioClipNode) |
| 749 | { |
| 750 | _nodes.push_back(audioClipNode); |
| 751 | _nodes.push_back(stereoPanner); |
| 752 | |
| 753 | const int seconds = 8; |
| 754 | |
| 755 | std::thread controlThreadTest([this, &stereoPanner, seconds]() { |
| 756 | float halfTime = seconds * 0.5f; |
| 757 | for (float i = 0; i < seconds; i += 0.01f) |
| 758 | { |
| 759 | float x = (i - halfTime) / halfTime; |
| 760 | stereoPanner->pan()->setValue(x); |
| 761 | Wait(10); |
| 762 | } |
| 763 | }); |
| 764 | |
| 765 | Wait(seconds * 1000); |
| 766 | |
| 767 | controlThreadTest.join(); |
| 768 | } |
| 769 | else |
| 770 | { |
| 771 | std::cerr << "Couldn't initialize train node to play" << std::endl; |
| 772 | } |
| 773 | } |
| 774 | }; |
| 775 | |
| 776 | ////////////////////////////////// |
nothing calls this directly
no test coverage detected