MCPcopy Create free account
hub / github.com/LancePutnam/Gamma / MyApp

Class MyApp

examples/source/samplePlayer.cpp:17–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15using namespace gam;
16
17class MyApp : public AudioApp{
18public:
19
20 Accum<> tmr;
21 SamplePlayer<> player; // Uses linear interpolation
22 //SamplePlayer<float, ipl::Trunc> player; // Uses no interpolation
23 //SamplePlayer<float, ipl::Cubic> player; // Uses cubic interpolation
24
25 MyApp(){
26 tmr.period(1);
27
28 // Load sound file into buffer
29 player.load("../../sounds/water3.wav");
30 }
31
32 void onAudio(AudioIOData& io){
33
34 while(io()){
35
36 if(tmr()){
37 // Set playback range
38 player.range(rnd::uni(0.5), rnd::uni(1.));
39
40 // Set playback rate; negative rates play in reverse
41 float r = pow(2, rnd::uniS(1.));
42 player.rate(rnd::neg(r, 0.3));
43
44 // Start sample again from beginning
45 player.reset();
46 }
47
48 //* Mono (left-channel) playback
49 float s = player() * 0.2;
50 //player.loop(); // This makes the sample loop
51 io.out(0) = io.out(1) = s;
52 //*/
53
54 /* Stereo playback
55 float s1 = player.read(0) * 0.2;
56 float s2 = player.read(1) * 0.2;
57 player.advance();
58 io.out(0) = s1;
59 io.out(1) = s2;
60 //*/
61 }
62 }
63};
64
65int main(){
66 MyApp().start();

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected