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

Method play

examples/src/Examples.hpp:178–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176struct ex_osc_pop : public labsound_example
177{
178 virtual void play(int argc, char** argv) override final
179 {
180 const auto defaultAudioDeviceConfigurations = GetDefaultAudioDeviceConfiguration();
181 context = lab::MakeRealtimeAudioContext(defaultAudioDeviceConfigurations.second, defaultAudioDeviceConfigurations.first);
182 lab::AudioContext& ac = *context.get();
183
184 std::shared_ptr<OscillatorNode> oscillator;
185 std::shared_ptr<RecorderNode> recorder;
186 std::shared_ptr<GainNode> gain;
187 {
188 oscillator = std::make_shared<OscillatorNode>(ac);
189
190 gain = std::make_shared<GainNode>(ac);
191 gain->gain()->setValue(1);
192
193 // osc -> destination
194 context->connect(gain, oscillator, 0, 0);
195 context->connect(context->device(), gain, 0, 0);
196
197 oscillator->frequency()->setValue(1000.f);
198 oscillator->setType(OscillatorType::SINE);
199
200 recorder = std::make_shared<RecorderNode>(ac, defaultAudioDeviceConfigurations.second);
201 context->addAutomaticPullNode(recorder);
202 recorder->startRecording();
203 context->connect(recorder, gain, 0, 0);
204 }
205
206 // retain nodes until demo end
207 _nodes.push_back(oscillator);
208 _nodes.push_back(recorder);
209 _nodes.push_back(gain);
210
211 // queue up 5 1/2 second chirps
212 for (float i = 0; i < 5.f; i += 1.f)
213 {
214 oscillator->start(0);
215 oscillator->stop(0.5f);
216 Wait(1000);
217 }
218
219 recorder->stopRecording();
220 context->removeAutomaticPullNode(recorder);
221 recorder->writeRecordingToWav("ex_osc_pop.wav", false);
222
223 // wait at least one context update to allow the disconnections to occur, and for any final
224 // render quantum to finish.
225 // @TODO the only safe and reasonable thing is to expose a "join" on the context that
226 // disconnects the destination node from its graph, then waits a quantum.
227
228 // @TODO the example app should have a set<shared_ptr<AudioNode>> so that the shared_ptrs
229 // are not released until the example is finished.
230
231 context->disconnect(context->device());
232 Wait(100);
233 }
234};
235

Callers

nothing calls this directly

Calls 15

MakeRealtimeAudioContextFunction · 0.85
getMethod · 0.80
setValueMethod · 0.80
deviceMethod · 0.80
addAutomaticPullNodeMethod · 0.80
startRecordingMethod · 0.80
stopRecordingMethod · 0.80
writeRecordingToWavMethod · 0.80
gainMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected