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