Showing the changes to examples/basic (1 of 2 files). Show all
Unified · Split
| @@ -1,36 +1,50 @@ | ||
| 1 | 1 | // oscillator demo |
| 2 | 2 | // - philipd |
| 3 | 3 | |
| 4 | +// scale degrees in semi-tones | |
| 4 | 5 | [ 0, 2, 4, 7, 9 ] @=> int f[]; |
| 5 | 6 | |
| 7 | +// various oscialltors | |
| 6 | 8 | SinOsc s => dac; |
| 7 | 9 | SawOsc saw => dac; |
| 8 | 10 | TriOsc tri => dac; |
| 9 | 11 | PulseOsc pul => dac; |
| 10 | 12 | SqrOsc sqr => dac; |
| 11 | − | |
| 13 | +// modulator and carrier | |
| 12 | 14 | TriOsc trictrl => SinOsc sintri => dac; |
| 15 | +// interpret input as frequency modulation | |
| 16 | +2 => sintri.sync; | |
| 17 | +100 => trictrl.gain; | |
| 13 | 18 | |
| 19 | +// array of Oscs | |
| 14 | 20 | [ s, saw, tri, pul, sqr, trictrl ] @=> Osc oscillators[]; |
| 15 | 21 | |
| 22 | +// set gains | |
| 16 | 23 | 0.2 => s.gain; |
| 17 | 24 | 0.1 => saw.gain; |
| 18 | 25 | 0.1 => tri.gain; |
| 19 | 26 | 0.1 => pul.gain; |
| 20 | 27 | 0.1 => sqr.gain; |
| 21 | 28 | 0.1 => sintri.gain; |
| 22 | −2 => sintri.sync; | |
| 23 | − | |
| 24 | −while ( true ) { | |
| 25 | 29 | |
| 30 | +// infinite time-loop | |
| 31 | +while( true ) | |
| 32 | +{ | |
| 33 | + // randomize | |
| 26 | 34 | Math.random2(0,7) => int select; |
| 27 | − if ( select > 5 ) 5 => select; | |
| 35 | + // clamp (giving more weight to 5) | |
| 36 | + if( select > 5 ) 5 => select; | |
| 37 | + // generate new frequenc value | |
| 28 | 38 | Std.mtof( f[Math.random2( 0, 4 )] + 60 ) => float newnote; |
| 39 | + // set frequency | |
| 29 | 40 | newnote => oscillators[select].freq; |
| 41 | + // wait a bit | |
| 30 | 42 | 0.25::second => now; |
| 31 | − for ( 0 => int i; i < 10; i+1 => i ) { | |
| 32 | − Math.random2f (0.2, .8 ) => trictrl.width; | |
| 33 | − 0.05 ::second => now; | |
| 34 | − } | |
| 35 | − | |
| 43 | + // 10 times | |
| 44 | + repeat(10) | |
| 45 | + { | |
| 46 | + Math.random2f( 0.2, 0.8 ) => trictrl.width; | |
| 47 | + // <<< "trictrl width:", trictrl.width() >>>; | |
| 48 | + 0.05::second => now; | |
| 49 | + } | |
| 36 | 50 | } |