@@ -193,11 +193,11 @@ inline std::pair<AudioStreamConfig, AudioStreamConfig> GetDefaultAudioDeviceConf
193193 return {inputConfig, outputConfig};
194194}
195195
196- // ///////////////// //
196+ // ----------------- //
197197// ex_simple //
198- // ///////////////// //
198+ // ----------------- //
199199
200- // ex_simple demonstrate the use of an audio clip loaded from disk and a basic sine oscillator.
200+ // demonstrate the use of an audio clip loaded from disk and a basic sine oscillator.
201201struct ex_simple : public labsound_example
202202{
203203 virtual void play (int argc, char ** argv) override final
@@ -245,11 +245,67 @@ struct ex_simple : public labsound_example
245245
246246
247247
248+ // ------------------------//
249+ // ex_test_resample //
250+ // ------------------------//
251+
252+ // demonstrate the use of an audio clip loaded from disk and a basic sine oscillator.
253+ struct ex_test_resample : public labsound_example
254+ {
255+ virtual void play (int argc, char ** argv) override final
256+ {
257+ std::unique_ptr<lab::AudioContext> context;
258+ const auto defaultAudioDeviceConfigurations = GetDefaultAudioDeviceConfiguration ();
259+ context = lab::MakeRealtimeAudioContext (defaultAudioDeviceConfigurations.second , defaultAudioDeviceConfigurations.first );
260+ lab::AudioContext& ac = *context.get ();
261+
262+ auto musicClip = MakeBusFromSampleFile (" samples/sin440-22050.wav" , argc, argv);
263+ if (!musicClip)
264+ return ;
265+
266+ std::shared_ptr<OscillatorNode> oscillator;
267+ std::shared_ptr<SampledAudioNode> musicClipNode;
268+ std::shared_ptr<GainNode> gain;
269+
270+ oscillator = std::make_shared<OscillatorNode>(ac);
271+ gain = std::make_shared<GainNode>(ac);
272+ gain->gain ()->setValue (0 .5f );
273+
274+ musicClipNode = std::make_shared<SampledAudioNode>(ac);
275+ {
276+ ContextRenderLock r (context.get (), " ex_test_resample" );
277+ musicClipNode->setBus (r, musicClip);
278+ }
279+ context->connect (context->device (), musicClipNode, 0 , 0 );
280+
281+ // osc -> gain -> destination
282+ context->connect (gain, oscillator, 0 , 0 );
283+ context->connect (context->device (), gain, 0 , 0 );
284+
285+ oscillator->frequency ()->setValue (440 .f );
286+ oscillator->setType (OscillatorType::SINE);
287+
288+ _nodes.push_back (oscillator);
289+ _nodes.push_back (musicClipNode);
290+ _nodes.push_back (gain);
291+
292+ oscillator->start (0 .0f );
293+ Wait (std::chrono::seconds (1 ));
294+ oscillator->stop (0 .0f );
295+ Wait (std::chrono::milliseconds (500 ));
296+ musicClipNode->schedule (0.0 );
297+ Wait (std::chrono::milliseconds (500 ));
298+ musicClipNode->detune ()->setValue (1000 .f );
299+ Wait (std::chrono::milliseconds (500 ));
300+ }
301+ };
302+
303+
248304
249305
250- // ///////////////// //
306+ // ----------------- //
251307// ex_osc_pop //
252- // ///////////////// //
308+ // ----------------- //
253309
254310// ex_osc_pop to test oscillator start/stop popping (it shouldn't pop).
255311struct ex_osc_pop : public labsound_example
@@ -1666,6 +1722,7 @@ class Example
16661722int main (int argc, char *argv[]) try
16671723{
16681724 Example<ex_simple> simple;
1725+ Example<ex_test_resample> resample;
16691726 Example<ex_osc_pop> osc_pop;
16701727 Example<ex_playback_events> playback_events;
16711728 Example<ex_offline_rendering> offline_rendering;
@@ -1685,10 +1742,11 @@ int main(int argc, char *argv[]) try
16851742 Example<ex_granulation_node> granulation;
16861743 Example<ex_poly_blep> poly_blep;
16871744
1688- // We can optionally play for a number of iterations as a way of testing lifetime & memory issues.
1745+ // We can optionally play for a number of iterations as a
1746+ // way of testing lifetime & memory issues.
16891747 for (int i = 0 ; i < iterations; ++i)
16901748 {
1691- granulation .ex ->play (argc, argv);
1749+ resample .ex ->play (argc, argv);
16921750 }
16931751
16941752 return EXIT_SUCCESS;
0 commit comments