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