| 34 | } |
| 35 | |
| 36 | void onAudio(AudioIOData& io){ |
| 37 | while(io()){ |
| 38 | if(tmr()){ |
| 39 | // Add to the phase a low-integer division of 2π plus a small |
| 40 | // offset for variation. |
| 41 | phase = scl::wrapPhase(phase + 2*M_PI / (rnd::prob(0.9)?3:2) + 0.012); |
| 42 | |
| 43 | float frq = sin(phase) * 8; |
| 44 | |
| 45 | // Map sine value to nearest pitch in C-major scale |
| 46 | frq = scl::ratioET(scl::nearest(frq, "2212221")) * scl::freq("c4"); |
| 47 | |
| 48 | src.freq(frq); |
| 49 | env.reset(); |
| 50 | } |
| 51 | |
| 52 | float s = src() * env() * 0.2; |
| 53 | |
| 54 | io.out(0) = s; |
| 55 | io.out(1) = s; |
| 56 | } |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | int main(){ |