@@ -193,11 +193,11 @@ inline std::pair<AudioStreamConfig, AudioStreamConfig> GetDefaultAudioDeviceConf
193
193
return {inputConfig, outputConfig};
194
194
}
195
195
196
- // ///////////////// //
196
+ // ----------------- //
197
197
// ex_simple //
198
- // ///////////////// //
198
+ // ----------------- //
199
199
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.
201
201
struct ex_simple : public labsound_example
202
202
{
203
203
virtual void play (int argc, char ** argv) override final
@@ -245,11 +245,67 @@ struct ex_simple : public labsound_example
245
245
246
246
247
247
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
+
248
304
249
305
250
- // ///////////////// //
306
+ // ----------------- //
251
307
// ex_osc_pop //
252
- // ///////////////// //
308
+ // ----------------- //
253
309
254
310
// ex_osc_pop to test oscillator start/stop popping (it shouldn't pop).
255
311
struct ex_osc_pop : public labsound_example
@@ -1666,6 +1722,7 @@ class Example
1666
1722
int main (int argc, char *argv[]) try
1667
1723
{
1668
1724
Example<ex_simple> simple;
1725
+ Example<ex_test_resample> resample;
1669
1726
Example<ex_osc_pop> osc_pop;
1670
1727
Example<ex_playback_events> playback_events;
1671
1728
Example<ex_offline_rendering> offline_rendering;
@@ -1685,10 +1742,11 @@ int main(int argc, char *argv[]) try
1685
1742
Example<ex_granulation_node> granulation;
1686
1743
Example<ex_poly_blep> poly_blep;
1687
1744
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.
1689
1747
for (int i = 0 ; i < iterations; ++i)
1690
1748
{
1691
- granulation .ex ->play (argc, argv);
1749
+ resample .ex ->play (argc, argv);
1692
1750
}
1693
1751
1694
1752
return EXIT_SUCCESS;
0 commit comments