| 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 | |
| 65 | int main(){ |