History

more comments for example code

Ge Wang committed 5 years ago

Commit ca9d35a1 parent 6a08fca2 files · +47 −22Browse files

Showing the changes to examples/basic (1 of 2 files). Show all

Unified · Split

examples/basic/oscillatronx.ck+24−10
@@ -1,36 +1,50 @@
1// oscillator demo1// oscillator demo
2// - philipd2// - 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
6SinOsc s => dac;8SinOsc s => dac;
7SawOsc saw => dac;9SawOsc saw => dac;
8TriOsc tri => dac;10TriOsc tri => dac;
9PulseOsc pul => dac;11PulseOsc pul => dac;
10SqrOsc sqr => dac;12SqrOsc sqr => dac;
11 13// modulator and carrier
12TriOsc trictrl => SinOsc sintri => dac;14TriOsc trictrl => SinOsc sintri => dac;
15// interpret input as frequency modulation
162 => sintri.sync;
17100 => 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
160.2 => s.gain;230.2 => s.gain;
170.1 => saw.gain;240.1 => saw.gain;
180.1 => tri.gain;250.1 => tri.gain;
190.1 => pul.gain;260.1 => pul.gain;
200.1 => sqr.gain;270.1 => sqr.gain;
210.1 => sintri.gain;280.1 => sintri.gain;
222 => sintri.sync;
23
24while ( true ) {
25 29
30// infinite time-loop
31while( 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}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t