History

moving examples to top dir

Ge Wang committed 9 years ago

Commit 35ca2f61 parent fd011ef486 files · +-44 −-44Browse files

Showing the changes to examples/basic (48 of 486 files). Show all

Unified · Split

48 files
  1. examples/basic/adc.ck +11 −0
  2. examples/basic/adsr.ck +24 −0
  3. examples/basic/alarm.ck +31 −0
  4. examples/basic/args.ck +11 −0
  5. examples/basic/bar.ck +17 −0
  6. examples/basic/blit.ck +23 −0
  7. examples/basic/blit2.ck +30 −0
  8. examples/basic/chirp.ck +47 −0
  9. examples/basic/chirp2.ck +81 −0
  10. examples/basic/comb.ck +22 −0
  11. examples/basic/curly++.ck +30 −0
  12. examples/basic/curly.ck +27 −0
  13. examples/basic/delay.ck +9 −0
  14. examples/basic/demo0.ck +12 −0
  15. examples/basic/demo1.ck +14 −0
  16. examples/basic/demo2.ck +65 −0
  17. examples/basic/demo3.ck +27 −0
  18. examples/basic/echo.ck +15 −0
  19. examples/basic/envelope.ck +20 −0
  20. examples/basic/fm.ck +22 −0
  21. examples/basic/fm2.ck +17 −0
  22. examples/basic/fm3.ck +16 −0
  23. examples/basic/foo.ck +17 −0
  24. examples/basic/foo2.ck +38 −0
  25. examples/basic/func.ck +36 −0
  26. examples/basic/i-robot.ck +17 −0
  27. examples/basic/imp.ck +18 −0
  28. examples/basic/infnan.ck +16 −0
  29. examples/basic/larry++.ck +40 −0
  30. examples/basic/larry.ck +27 −0
  31. examples/basic/lfo.ck +13 −0
  32. examples/basic/moe++.ck +42 −0
  33. examples/basic/moe.ck +27 −0
  34. examples/basic/rec-auto-stereo.ck +29 −0
  35. examples/basic/rec-auto.ck +28 −0
  36. examples/basic/rec.ck +23 −0
  37. examples/basic/ring.ck +26 −0
  38. examples/basic/sndbuf.ck +17 −0
  39. examples/basic/step.ck +13 −0
  40. examples/basic/tick.ck +9 −0
  41. examples/basic/tick2.ck +12 −0
  42. examples/basic/unchuck.ck +41 −0
  43. examples/basic/valueat.ck +24 −0
  44. examples/basic/whirl.ck +16 −0
  45. examples/basic/whole.ck +30 −0
  46. examples/basic/wind.ck +20 −0
  47. examples/basic/wind2.ck +37 −0
  48. examples/basic/zerox.ck +14 −0
examples/basic/adc.ck+11−0
@@ -0,0 +1,11 @@
1+// mic-in to audio out
2+
3+// the patch
4+adc => dac;
5+
6+// infinite time-loop
7+while( true )
8+{
9+ // advance time
10+ 100::ms => now;
11+}
examples/basic/adsr.ck+24−0
@@ -0,0 +1,24 @@
1+// an ADSR envelope
2+// (also see envelope.ck)
3+SinOsc s => ADSR e => dac;
4+
5+// set a, d, s, and r
6+e.set( 10::ms, 8::ms, .5, 500::ms );
7+// set gain
8+.5 => s.gain;
9+
10+// infinite time-loop
11+while( true )
12+{
13+ // choose freq
14+ Math.random2( 20, 120 ) => Std.mtof => s.freq;
15+
16+ // key on - start attack
17+ e.keyOn();
18+ // advance time by 800 ms
19+ 500::ms => now;
20+ // key off - start release
21+ e.keyOff();
22+ // advance time by 800 ms
23+ 800::ms => now;
24+}
examples/basic/alarm.ck+31−0
@@ -0,0 +1,31 @@
1+// how long
2+2::hour => dur T;
3+// frequency
4+880 => float f;
5+
6+// remember
7+now => time start;
8+now + T => time later;
9+
10+// wait
11+while( now < later )
12+{
13+ <<< (T - (now - start)) / second, "left..." >>>;
14+ 1::second => now;
15+}
16+
17+// patch
18+SinOsc s => JCRev r => dac;
19+.025 => r.mix;
20+f => s.freq;
21+
22+// infinite while loop
23+while( true )
24+{
25+ // go
26+ 1.0 => s.gain;
27+ 300::ms => now;
28+ // stop
29+ 0.0 => s.gain;
30+ 300::ms => now;
31+}
examples/basic/args.ck+11−0
@@ -0,0 +1,11 @@
1+// shows getting command line arguments
2+// (example run: chuck args:1:2:foo)
3+
4+// print number of args
5+<<< "number of arguments:", me.args() >>>;
6+
7+// print each
8+for( int i; i < me.args(); i++ )
9+{
10+ <<< " ", me.arg(i) >>>;
11+}
examples/basic/bar.ck+17−0
@@ -0,0 +1,17 @@
1+// point of attack for random otf demo
2+
3+SinOsc s => dac;
4+.2 => s.gain;
5+
6+// an array: add stuff
7+[ 0 ] @=> int hi[];
8+
9+while( true )
10+{
11+ // change parameters here
12+ Std.mtof( 45 + Math.random2(0,0) * 12 +
13+ hi[Math.random2(0,hi.size()-1)] ) => s.freq;
14+
15+ // different rate
16+ 200::ms => now;
17+}
examples/basic/blit.ck+23−0
@@ -0,0 +1,23 @@
1+// patch
2+Blit s => JCRev r => dac;
3+.5 => s.gain;
4+.05 => r.mix;
5+
6+// an array
7+[ 0, 2, 4, 7, 9, 11 ] @=> int hi[];
8+// <<< hi.size() >>>;
9+// <<< hi[0], hi[1], hi[2], hi[3], hi[4], hi[5] >>>;
10+
11+// infinite time loop
12+while( true )
13+{
14+ // frequency
15+ Std.mtof( 33 + Math.random2(0,3) * 12 +
16+ hi[Math.random2(0,hi.size()-1)] ) => s.freq;
17+
18+ // harmonics
19+ Math.random2( 1, 5 ) => s.harmonics;
20+
21+ // advance time
22+ 120::ms => now;
23+}
examples/basic/blit2.ck+30−0
@@ -0,0 +1,30 @@
1+// patch
2+Blit s => ADSR e => JCRev r => dac;
3+.5 => s.gain;
4+.05 => r.mix;
5+
6+// set adsr
7+e.set( 5::ms, 3::ms, .5, 5::ms );
8+
9+// an array
10+[ 0, 2, 4, 7, 9, 11 ] @=> int hi[];
11+
12+// infinite time loop
13+while( true )
14+{
15+ // frequency
16+ Std.mtof( 33 + Math.random2(0,3) * 12 +
17+ hi[Math.random2(0,hi.size()-1)] ) => s.freq;
18+
19+ // harmonics
20+ Math.random2( 1, 5 ) => s.harmonics;
21+
22+ // key on
23+ e.keyOn();
24+ // advance time
25+ 120::ms => now;
26+ // key off
27+ e.keyOff();
28+ // advance time
29+ 5::ms => now;
30+}
examples/basic/chirp.ck+47−0
@@ -0,0 +1,47 @@
1+// po-tweet!
2+
3+// patch
4+SinOsc s => dac;
5+// gain
6+.4 => s.gain;
7+
8+// call chirp
9+chirp( 127, 20, 1::second );
10+
11+// call chirp (with tinc)
12+chirp( 20, 120, 1.5::second, 100::ms );
13+
14+// chirp function
15+fun void chirp( float src, float target, dur duration )
16+{
17+ chirp( src, target, duration, 1::ms );
18+}
19+
20+// chirp function (with tinc)
21+fun void chirp( float src, float target, dur duration, dur tinc )
22+{
23+ // initialize freq
24+ src => float freq;
25+ // find the number of steps
26+ duration / tinc => float steps;
27+ // find the inc
28+ ( target - src ) / steps => float inc;
29+ // counter
30+ float count;
31+
32+ // do the actual work over time
33+ while( count < steps )
34+ {
35+ // increment the freq
36+ freq + inc => freq;
37+ // count
38+ 1 +=> count;
39+
40+ // set the freq
41+ Std.mtof( freq ) => s.freq;
42+
43+ // advance time
44+ tinc => now;
45+ }
46+}
47+
examples/basic/chirp2.ck+81−0
@@ -0,0 +1,81 @@
1+// more chirping...
2+
3+// patch with envelope and pan
4+SinOsc s => Envelope e => Pan2 p => dac;
5+// gain
6+.5 => s.gain;
7+
8+// pan hard left
9+-1 => p.pan;
10+// call chirp
11+chirp( 127, 20, 1::second );
12+
13+// wait for envelope to go down
14+10::ms => now;
15+// pan hard right
16+1 => p.pan;
17+// call chirp
18+chirp( 20, 120, 1::second, 100::ms );
19+
20+// wait a second
21+1::second => now;
22+
23+// randomize pan
24+Math.random2f( -1, 1 ) => p.pan;
25+// call chirp
26+chirp( 30, 110, .5::second );
27+
28+// wait for envelope to go down
29+10::ms => now;
30+// pan
31+Math.random2f( -1, 1 ) => p.pan;
32+// call chirp
33+chirp( 110, 30, 1::second, 100::ms );
34+
35+// wait a second
36+1::second => now;
37+
38+
39+// chirp function
40+fun void chirp( float src, float target, dur duration )
41+{
42+ // just call the other one with default tinc
43+ chirp( src, target, duration, 1::ms );
44+}
45+
46+
47+// chirp function (with tinc)
48+fun void chirp( float src, float target, dur duration, dur tinc )
49+{
50+ // initialize freq
51+ src => float freq;
52+ // find the number of steps
53+ duration / tinc => float steps;
54+ // find the inc
55+ ( target - src ) / steps => float inc;
56+ // counter
57+ float count;
58+ // set env
59+ .01 * duration / second => e.time;
60+ // open env
61+ 1 => e.keyOn;
62+
63+ // do the actual work over time
64+ while( count < steps )
65+ {
66+ // increment the freq
67+ freq + inc => freq;
68+ // count
69+ 1 +=> count;
70+
71+ // set the freq
72+ Std.mtof( freq ) => s.freq;
73+
74+ // advance time
75+ tinc => now;
76+ }
77+
78+ // close env
79+ 1 => e.keyOff;
80+}
81+
examples/basic/comb.ck+22−0
@@ -0,0 +1,22 @@
1+// a simple comb filter
2+// Ge Wang (gewang@cs.princeton.edu)
3+
4+// feedforward
5+Impulse imp => Gain out => dac;
6+// feedback
7+out => Delay delay => out;
8+
9+// our radius
10+.99999 => float R;
11+// our delay order
12+500 => float L;
13+// set delay
14+L::samp => delay.delay;
15+// set dissipation factor
16+Math.pow( R, L ) => delay.gain;
17+
18+// fire impulse
19+1 => imp.next;
20+
21+// advance time
22+(Math.log(.0001) / Math.log(R))::samp => now;
examples/basic/curly++.ck+30−0
@@ -0,0 +1,30 @@
1+// run each stooge, or run three stooges concurrently
2+// %> chuck moe++ larry++ curly++
3+
4+// impulse to filter to dac
5+SndBuf i => NRev r => dac;
6+
7+// load glottal ooo
8+"special:glot_ooo" => i.read;
9+// play
10+//5.0 => i.rate;
11+.1 => r.mix;
12+
13+0.0 => float v;
14+
15+// infinite time-loop
16+while( true )
17+{
18+ // set the current sample/impulse
19+ 0 => i.pos;
20+ // control gain
21+ Math.cos(v) => i.gain;
22+ // increment v
23+ .05 +=> v;
24+ // advance time
25+ 81.0::ms => now;
26+}
27+
28+
29+
30+
examples/basic/curly.ck+27−0
@@ -0,0 +1,27 @@
1+// run each stooge, or run three stooges concurrently
2+// %> chuck moe larry curly
3+
4+// impulse to filter to dac
5+Impulse i => BiQuad f => dac;
6+// set the filter's pole radius
7+.99 => f.prad;
8+// set equal gain zeros
9+1 => f.eqzs;
10+// initialize float variable
11+0.0 => float v;
12+// set filter gain
13+.5 => f.gain;
14+
15+// infinite time-loop
16+while( true )
17+{
18+ // set the current sample/impulse
19+ 1.0 => i.next;
20+ // sweep the filter resonant frequency
21+ Std.fabs(Math.sin(v)) * 800.0 => f.pfreq;
22+ // increment v
23+ v + .1 => v;
24+ // advance time
25+ 101::ms => now;
26+}
27+
examples/basic/delay.ck+9−0
@@ -0,0 +1,9 @@
1+// patch
2+adc => DelayL delay => dac;
3+
4+// set delay parameters
5+.75::second => delay.max => delay.delay;
6+
7+// infinite time loop
8+while( true ) 1::second => now;
9+
examples/basic/demo0.ck+12−0
@@ -0,0 +1,12 @@
1+// demo0.ck
2+// basic demo showing time and duration
3+
4+5::second + now => time later;
5+
6+while( now < later )
7+{
8+ <<<now>>>;
9+ 1::second => now;
10+}
11+
12+<<<now>>>;
examples/basic/demo1.ck+14−0
@@ -0,0 +1,14 @@
1+// demo1.ck
2+// candidate for most trivial demo
3+
4+0 => int a => int t;
5+1 => int b;
6+15 => int c;
7+
8+while( c > 0 )
9+{
10+ a + b => t;
11+ b => a;
12+ <<<t => b>>>;
13+ c - 1 => c;
14+}
examples/basic/demo2.ck+65−0
@@ -0,0 +1,65 @@
1+// demo2.ck
2+// really lame!
3+
4+// set the global gain
5+.1 => dac.gain;
6+
7+/*
8+// connect
9+SinOsc a => dac;
10+110.0 => a.freq;
11+1::second => now;
12+SinOsc b => dac;
13+220.0 => b.freq;
14+1::second => now;
15+SinOsc c => dac;
16+440.0 => c.freq;
17+1::second => now;
18+SinOsc d => dac;
19+880.0 => d.freq;
20+1::second => now;
21+SinOsc e => dac;
22+1760.0 => e.freq;
23+1::second => now;
24+*/
25+
26+SinOsc oscarray[5];
27+for(0 => int i; i<5; i++) {
28+
29+ oscarray[i] => dac;
30+ Math.pow(2, i) * 110.0 => oscarray[i].freq;
31+
32+}
33+
34+/*
35+// disconnect
36+a =< dac;
37+1::second => now;
38+b =< dac;
39+1::second => now;
40+c =< dac;
41+1::second => now;
42+d =< dac;
43+1::second => now;
44+e =< dac;
45+1::second => now;
46+*/
47+
48+for(0 => int i; i<5; i++) {
49+
50+ oscarray[i] =< dac;
51+ 1::second => now;
52+
53+}
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
examples/basic/demo3.ck+27−0
@@ -0,0 +1,27 @@
1+// demo3.ck
2+// super lame
3+
4+// global gain
5+Gain g => dac;
6+// set gain
7+.5 => g.gain;
8+
9+110.0 => float freq;
10+6 => int x;
11+
12+// loop
13+while( x > 0 )
14+{
15+ // connect to gain
16+ SinOsc s => g;
17+ // change frequency
18+ freq => s.freq;
19+ freq * 2.0 => freq;
20+ // decrement x
21+ 1 -=> x;
22+
23+ // advance time by 1 second
24+ 1::second => now;
25+ // disconnect the sinosc
26+ s =< g;
27+}
examples/basic/echo.ck+15−0
@@ -0,0 +1,15 @@
1+// feedforward
2+adc => Gain g => dac;
3+// feedback
4+g => Gain feedback => DelayL delay => g;
5+
6+// set delay parameters
7+.75::second => delay.max => delay.delay;
8+// set feedback
9+.5 => feedback.gain;
10+// set effects mix
11+.75 => delay.gain;
12+
13+// infinite time loop
14+while( true ) 1::second => now;
15+
examples/basic/envelope.ck+20−0
@@ -0,0 +1,20 @@
1+// run white noise through envelope
2+Noise n => Envelope e => dac;
3+
4+// infinite time-loop
5+while( true )
6+{
7+ // random choose rise/fall time
8+ Math.random2f(10,500)::ms => dur t => e.duration;
9+ // print
10+ <<< "rise/fall:", t/ms, "ms" >>>;
11+
12+ // key on - start attack
13+ e.keyOn();
14+ // advance time by 800 ms
15+ 800::ms => now;
16+ // key off - start release
17+ e.keyOff();
18+ // advance time by 800 ms
19+ 800::ms => now;
20+}
examples/basic/fm.ck+22−0
@@ -0,0 +1,22 @@
1+// FM synthesis by hand
2+
3+// carrier
4+SinOsc c => dac;
5+// modulator
6+SinOsc m => blackhole;
7+
8+// carrier frequency
9+220 => float cf;
10+// modulator frequency
11+550 => float mf => m.freq;
12+// index of modulation
13+200 => float index;
14+
15+// time-loop
16+while( true )
17+{
18+ // modulate
19+ cf + (index * m.last()) => c.freq;
20+ // advance time by 1 samp
21+ 1::samp => now;
22+}
examples/basic/fm2.ck+17−0
@@ -0,0 +1,17 @@
1+// basic FM synthesis using SinOsc (2 => .sync; also see fm3.ck)
2+
3+// modulator to carrier
4+SinOsc m => SinOsc c => dac;
5+
6+// carrier frequency
7+440 => c.freq;
8+// modulator frequency
9+110 => m.freq;
10+// index of modulation
11+300 => m.gain;
12+
13+// phase modulation is FM synthesis (sync is 2)
14+2 => c.sync;
15+
16+// time-loop
17+while( true ) 1::second => now;
examples/basic/fm3.ck+16−0
@@ -0,0 +1,16 @@
1+// FM synthesis (using Step instead of .sync == 2; see fm2.ck)
2+
3+// modulator to carrier
4+SinOsc m => SinOsc c => dac;
5+// step function, add to modulator output
6+Step step => c;
7+
8+// carrier frequency
9+440 => step.next;
10+// modulator frequency
11+110 => m.freq;
12+// index of modulation
13+300 => m.gain;
14+
15+// time-loop
16+while( true ) 1::second => now;
examples/basic/foo.ck+17−0
@@ -0,0 +1,17 @@
1+// hello everyone.
2+// a chuck is born...
3+// its first words:
4+
5+SinOsc s => JCRev r => dac;
6+.2 => s.gain;
7+.1 => r.mix;
8+
9+// an array
10+[ 0, 2, 4, 7, 9, 11 ] @=> int hi[];
11+
12+while( true )
13+{
14+ Std.mtof( 45 + Math.random2(0,3) * 12 +
15+ hi[Math.random2(0,hi.size()-1)] ) => s.freq;
16+ 100::ms => now;
17+}
examples/basic/foo2.ck+38−0
@@ -0,0 +1,38 @@
1+// bandlimited ugens (Blit, BlitSaw, BlitSquare)
2+Blit s => Pan2 p;
3+p.left => JCRev r1 => dac.left;
4+p.right => JCRev r2 => dac.right;
5+
6+// initial settings
7+.5 => s.gain;
8+.1 => r1.mix;
9+.1 => r2.mix;
10+
11+// an array
12+[ 0, 2, 4, 7, 9, 11 ] @=> int hi[];
13+
14+// set the harmonic
15+4 => s.harmonics;
16+
17+// spork the pan control
18+spork ~ dopan();
19+
20+// infinite time loop
21+while( true )
22+{
23+ Std.mtof( 33 + Math.random2(0,3) * 12 +
24+ hi[Math.random2(0,hi.size()-1)] ) => s.freq;
25+ 120::ms => now;
26+}
27+
28+// pan control
29+fun void dopan()
30+{
31+ float t;
32+ while( true )
33+ {
34+ .7 * Math.sin(t) => p.pan;
35+ .005 +=> t;
36+ 10::ms => now;
37+ }
38+}
examples/basic/func.ck+36−0
@@ -0,0 +1,36 @@
1+8 => int a;
2+
3+fun int abs( int v )
4+{
5+ if( v < 0 ) return -v;
6+ return v;
7+}
8+
9+fun void args( int y, int b )
10+{
11+ 4 => a;
12+ <<<b>>>;
13+}
14+
15+fun float sum( float a, float b )
16+{
17+ return a + b;
18+}
19+
20+fun void go( int a )
21+{
22+ <<<abs(a)>>>;
23+ if( a == 0 )
24+ return;
25+
26+ go( abs(a)-1 );
27+}
28+
29+int i;
30+for( 0 => i; i < 10; i + 1 => i )
31+ go( 1000 );
32+<<<abs(-1)>>>;
33+args( 1, 2 );
34+<<<sum( 1.0, 2.0 )>>>;
35+<<<a>>>;
36+
examples/basic/i-robot.ck+17−0
@@ -0,0 +1,17 @@
1+// take me to your leader (talk into the mic)
2+// gewang, prc
3+
4+// our patch - feedforward part
5+adc => Gain g => DelayL d => dac;
6+adc => Gain g2 => dac;
7+// feedback
8+d => Gain g3 => d;
9+
10+// set parameters
11+15::ms => d.delay;
12+0.05 => g.gain;
13+0.05 => g2.gain;
14+0.95 => g3.gain;
15+
16+// time loop
17+while( true ) 100::ms => now;
examples/basic/imp.ck+18−0
@@ -0,0 +1,18 @@
1+// impulse generator is cool...
2+// this demo is not
3+
4+// connect impulse generator
5+Impulse i => dac;
6+.5 => i.gain;
7+
8+// emit impulse every so often
9+2000 => int a;
10+while( 1 )
11+{
12+ // set the next sample
13+ 1.0 => i.next;
14+
15+ // advance time
16+ a::samp => now;
17+ a - 8 => a; if( a <= 0 ) 2000 => a;
18+}
examples/basic/infnan.ck+16−0
@@ -0,0 +1,16 @@
1+// big number
2+1000000000000000000000000000.0 => float n;
3+// overflow it
4+repeat( 20 ) n *=> n;
5+// test it
6+<<< Math.isinf( n ) >>>;
7+// bye sanity
8+0 *=> n;
9+// test it
10+<<< Math.isnan( n ) >>>;
11+
12+// more
13+<<< 1.0 / 0.0 => Math.isinf >>>;
14+<<< 0.0 / 0.0 => Math.isnan >>>;
15+<<< Math.INFINITY, -Math.INFINITY >>>;
16+<<< Math.INFINITY => Math.isinf >>>;
examples/basic/larry++.ck+40−0
@@ -0,0 +1,40 @@
1+// run each stooge, or run three stooges concurrently
2+// %> chuck moe++ larry++ curly++
3+
4+// impulse to filter to dac
5+SndBuf i => BiQuad f => Gain g => JCRev r => dac;
6+// second formant
7+i => BiQuad f2 => g;
8+// third formant
9+i => BiQuad f3 => g;
10+
11+// set the filter's pole radius
12+0.800 => f.prad; .995 => f2.prad; .995 => f3.prad;
13+// set equal gain zeroes
14+1 => f.eqzs; 1 => f2.eqzs; 1 => f3.eqzs;
15+// initialize float variable
16+0.0 => float v => float v2;
17+// set filter gain
18+.1 => f.gain; .1 => f2.gain; .01 => f3.gain;
19+0.05 => r.mix;
20+// load glottal pop
21+"special:glot_pop" => i.read;
22+// play
23+1.0 => i.rate;
24+
25+// infinite time-loop
26+while( true )
27+{
28+ // set the current sample/impulse
29+ 0 => i.pos;
30+ // sweep the filter resonant frequency
31+ 250.0 + Math.sin(v*100.0)*20.0 => v2 => f.pfreq;
32+ 2290.0 + Math.sin(v*200.0)*50.0 => f2.pfreq;
33+ 3010.0 + Math.sin(v*300.0)*80.0 => f3.pfreq;
34+ // increment v
35+ v + .05 => v;
36+ // gain
37+ 0.2 + Math.sin(v)*.1 => g.gain;
38+ // advance time
39+ (1000.0 + Math.random2f(-100.0, 100.0))::ms => now;
40+}
examples/basic/larry.ck+27−0
@@ -0,0 +1,27 @@
1+// run each stooge, or run three stooges concurrently
2+// %> chuck moe larry curly
3+
4+// impulse to filter to dac
5+Impulse i => BiQuad f => dac;
6+// set the filter's pole radius
7+.99 => f.prad;
8+// set equal gain zeros
9+1 => f.eqzs;
10+// initialize float variable
11+0.0 => float v;
12+// set filter gain
13+.5 => f.gain;
14+
15+// infinite time-loop
16+while( true )
17+{
18+ // set the current sample/impulse
19+ 1.0 => i.next;
20+ // sweep the filter resonant frequency
21+ Std.fabs(Math.sin(v)) * 4000.0 => f.pfreq;
22+ // increment v
23+ v + .1 => v;
24+ // advance time
25+ 99::ms => now;
26+}
27+
examples/basic/lfo.ck+13−0
@@ -0,0 +1,13 @@
1+// using SinOsc.period (alternative to .freq)
2+
3+// sinosc
4+SinOsc lfo => dac;
5+// set period
6+1::second => lfo.period;
7+
8+// infinite time loop
9+while( true )
10+{
11+ <<< lfo.last(), "" >>>;
12+ 50::ms => now;
13+}
examples/basic/moe++.ck+42−0
@@ -0,0 +1,42 @@
1+// run each stooge, or run three stooges concurrently
2+// %> chuck moe++ larry++ curly++
3+
4+// source to filter to dac
5+SndBuf i => BiQuad f => Gain g => dac;
6+// second formant
7+i => BiQuad f2 => g;
8+// third formant
9+i => BiQuad f3 => g;
10+
11+// set the filter's pole radius
12+.995 => f.prad; .995 => f2.prad; .995 => f3.prad;
13+// set equal gain zeros
14+1 => f.eqzs; 1 => f2.eqzs; 1 => f3.eqzs;
15+// initialize float variable
16+1.5 * 3.14 => float v;
17+// set filter gain
18+.2 => f.gain; .04 => f2.gain; .01 => f3.gain;
19+// load glottal pop
20+"special:glot_pop" => i.read;
21+// play
22+1.0 => i.rate;
23+
24+
25+// infinite time-loop
26+while( true )
27+{
28+ // set the current pos
29+ 0 => i.pos;
30+
31+ // sweep the filter resonant frequency
32+ 660.0 + Math.sin(v)*80.0 => f.pfreq;
33+ 1780.0 + Math.sin(v*.5)*50.0 => f2.pfreq;
34+ 2410.0 + Math.sin(v*.25)*150.0 => f3.pfreq;
35+
36+ // increment v
37+ v + .05 => v;
38+ // gain
39+ 0.2 + Math.sin(v)*.2 => g.gain;
40+ // advance time
41+ (80.0 + Math.sin(v*2.0)*10.0)::ms => now;
42+}
examples/basic/moe.ck+27−0
@@ -0,0 +1,27 @@
1+// run each stooge, or run three stooges concurrently
2+// %> chuck moe larry curly
3+
4+// impulse to filter to dac
5+Impulse i => BiQuad f => dac;
6+// set the filter's pole radius
7+.99 => f.prad;
8+// set equal gain zeros
9+1 => f.eqzs;
10+// initialize float variable
11+0.0 => float v;
12+// set filter gain
13+.5 => f.gain;
14+
15+// infinite time-loop
16+while( true )
17+{
18+ // set the current sample/impulse
19+ 1.0 => i.next;
20+ // sweep the filter resonant frequency
21+ Std.fabs(Math.sin(v)) * 4000.0 => f.pfreq;
22+ // increment v
23+ v + .1 => v;
24+ // advance time
25+ 100::ms => now;
26+}
27+
examples/basic/rec-auto-stereo.ck+29−0
@@ -0,0 +1,29 @@
1+// chuck this with other shreds to record to file
2+// example> chuck foo.ck bar.ck rec (see also rec2.ck)
3+
4+// pull samples from the dac
5+// WvOut2 -> stereo operation
6+dac => WvOut2 w => blackhole;
7+
8+// set the prefix, which will prepended to the filename
9+// do this if you want the file to appear automatically
10+// in another directory. if this isn't set, the file
11+// should appear in the directory you run chuck from
12+// with only the date and time.
13+"chuck-session" => w.autoPrefix;
14+
15+// this is the output file name
16+"special:auto" => w.wavFilename;
17+
18+// print it out
19+<<<"writing to file: ", w.filename()>>>;
20+
21+// any gain you want for the output
22+.5 => w.fileGain;
23+
24+// temporary workaround to automatically close file on remove-shred
25+null @=> w;
26+
27+// infinite time loop...
28+// ctrl-c will stop it, or modify to desired duration
29+while( true ) 1::second => now;
examples/basic/rec-auto.ck+28−0
@@ -0,0 +1,28 @@
1+// chuck this with other shreds to record to file
2+// example> chuck foo.ck bar.ck rec (see also rec2.ck)
3+
4+// pull samples from the dac
5+dac => Gain g => WvOut w => blackhole;
6+
7+// set the prefix, which will prepended to the filename
8+// do this if you want the file to appear automatically
9+// in another directory. if this isn't set, the file
10+// should appear in the directory you run chuck from
11+// with only the date and time.
12+"chuck-session" => w.autoPrefix;
13+
14+// this is the output file name
15+"special:auto" => w.wavFilename;
16+
17+// print it out
18+<<<"writing to file: ", w.filename()>>>;
19+
20+// any gain you want for the output
21+.5 => g.gain;
22+
23+// temporary workaround to automatically close file on remove-shred
24+null @=> w;
25+
26+// infinite time loop...
27+// ctrl-c will stop it, or modify to desired duration
28+while( true ) 1::second => now;
examples/basic/rec.ck+23−0
@@ -0,0 +1,23 @@
1+// chuck this with other shreds to record to file
2+// example> chuck foo.ck bar.ck rec (see also rec2.ck)
3+
4+// arguments: rec:<filename>
5+
6+// get name
7+me.arg(0) => string filename;
8+if( filename.length() == 0 ) "foo.wav" => filename;
9+
10+// pull samples from the dac
11+dac => Gain g => WvOut w => blackhole;
12+// this is the output file name
13+filename => w.wavFilename;
14+<<<"writing to file:", "'" + w.filename() + "'">>>;
15+// any gain you want for the output
16+.5 => g.gain;
17+
18+// temporary workaround to automatically close file on remove-shred
19+null @=> w;
20+
21+// infinite time loop...
22+// ctrl-c will stop it, or modify to desired duration
23+while( true ) 1::second => now;
examples/basic/ring.ck+26−0
@@ -0,0 +1,26 @@
1+//--------------------------------------------
2+// simple ring modulation
3+//
4+// any ugen has .op:
5+// ---
6+// -1 pass through the input
7+// 0 stop input
8+// 1 add inputs (default)
9+// 2 subtract from first input
10+// 3 multiply inputs
11+// 4 divide from first input
12+//--------------------------------------------
13+
14+// the patch
15+adc => Gain g => dac;
16+SinOsc s => g;
17+
18+// multiply inputs at g
19+3 => g.op;
20+
21+// presets
22+400.0 => s.freq;
23+
24+// time loop
25+while( true )
26+ 1::second => now;
examples/basic/sndbuf.ck+17−0
@@ -0,0 +1,17 @@
1+// sound file
2+me.dir() + "/../data/snare.wav" => string filename;
3+if( me.args() ) me.arg(0) => filename;
4+
5+// the patch
6+SndBuf buf => dac;
7+// load the file
8+filename => buf.read;
9+
10+// time loop
11+while( true )
12+{
13+ 0 => buf.pos;
14+ Math.random2f(.2,.5) => buf.gain;
15+ Math.random2f(.5,1.5) => buf.rate;
16+ 100::ms => now;
17+}
examples/basic/step.ck+13−0
@@ -0,0 +1,13 @@
1+// step gen to dac
2+Step s => dac;
3+.5 => float v;
4+
5+// infinite time-loop
6+while( 1 )
7+{
8+ // advance time
9+ 1::ms => now;
10+ // set value
11+ v => s.next;
12+ -v => v;
13+}
examples/basic/tick.ck+9−0
@@ -0,0 +1,9 @@
1+// tick tock
2+
3+// infinite time loop
4+while( true )
5+{
6+ // print now in seconds
7+ <<< "tick:", (now / second), "seconds" >>>;
8+ 1::second => now;
9+}
examples/basic/tick2.ck+12−0
@@ -0,0 +1,12 @@
1+// tick tock
2+
3+// wait until the start of the next second
4+second - (now % second) => now;
5+
6+// infinite time loop
7+while( true )
8+{
9+ // print now in seconds
10+ <<< "tick:", (now / second) $ int, "seconds" >>>;
11+ 1::second => now;
12+}
examples/basic/unchuck.ck+41−0
@@ -0,0 +1,41 @@
1+// noise generator, biquad filter, dac (audio output)
2+Noise n => BiQuad f => dac;
3+// set biquad pole radius
4+.99 => f.prad;
5+// set biquad gain
6+.025 => f.gain;
7+// set equal zeros
8+1 => f.eqzs;
9+// our float
10+0.0 => float t;
11+
12+3::second + now => time later;
13+// time-loop
14+while( now < later )
15+{
16+ // sweep the filter resonant frequency
17+ 100.0 + Std.fabs(Math.sin(t)) * 1000.0 => f.pfreq;
18+ t + .05 => t;
19+ // advance time
20+ 100::ms => now;
21+}
22+
23+// unlink the ugen f from dac
24+f =< dac;
25+
26+// let more time pass
27+3::second => now;
28+
29+// relink
30+f => dac;
31+
32+// time-loop
33+3::second + now => later;
34+while( now < later )
35+{
36+ // resume sweep
37+ 100.0 + Std.fabs(Math.sin(t)) * 1000.0 => f.pfreq;
38+ t + .05 => t;
39+ // advance time
40+ 100::ms => now;
41+}
examples/basic/valueat.ck+24−0
@@ -0,0 +1,24 @@
1+// (see sndbuf.ck or otf_01.ck for non-insane usage of sndbuf)
2+SndBuf buf;
3+me.dir() + "/../data/kick.wav" => buf.read;
4+
5+// the patch (no sndbuf involved)
6+Impulse i => dac;
7+
8+// infinite time-loop
9+while( true )
10+{
11+ // index
12+ int pos;
13+
14+ // repeat this many times
15+ repeat( buf.samples() )
16+ {
17+ // set next sample
18+ buf.valueAt( pos ) => i.next;
19+ // increment index
20+ pos++;
21+ // advance time by one samp
22+ 1::samp => now;
23+ }
24+}
examples/basic/whirl.ck+16−0
@@ -0,0 +1,16 @@
1+// sine to dac
2+SinOsc s => dac;
3+// let's turn down gain, for this can be loud and annoying
4+.15 => s.gain;
5+
6+// infinite time loop
7+0.0 => float t;
8+while( true )
9+{
10+ // modulate
11+ 30 + ( Math.sin(t) + 1.0 ) * 10000.0 => s.sfreq;
12+ t + .004 => t;
13+
14+ // advance time
15+ 1::ms => now;
16+}
examples/basic/whole.ck+30−0
@@ -0,0 +1,30 @@
1+// another candidate for lamest demo
2+
3+// patch
4+SinOsc s => JCRev r => dac;
5+.5 => r.gain;
6+.075 => r.mix;
7+
8+// note number
9+20 => float note;
10+
11+// go up to 127
12+while( note < 128 )
13+{
14+ // convert MIDI note to hz
15+ Std.mtof( note ) => s.freq;
16+ // turn down the volume gradually
17+ .5 - (note/256.0) => s.gain;
18+
19+ // move up by whole step
20+ note + 2 => note;
21+
22+ // advance time
23+ .125::second => now;
24+}
25+
26+// turn off s
27+0 => s.gain;
28+// wait a bit
29+2::second => now;
30+
examples/basic/wind.ck+20−0
@@ -0,0 +1,20 @@
1+// noise generator, biquad filter, dac (audio output)
2+Noise n => BiQuad f => dac;
3+// set biquad pole radius
4+.99 => f.prad;
5+// set biquad gain
6+.05 => f.gain;
7+// set equal zeros
8+1 => f.eqzs;
9+// our float
10+0.0 => float t;
11+
12+// infinite time-loop
13+while( true )
14+{
15+ // sweep the filter resonant frequency
16+ 100.0 + Std.fabs(Math.sin(t)) * 15000.0 => f.pfreq;
17+ t + .01 => t;
18+ // advance time
19+ 5::ms => now;
20+}
examples/basic/wind2.ck+37−0
@@ -0,0 +1,37 @@
1+// noise generator, biquad filter, dac (audio output)
2+Noise n => BiQuad f => dac;
3+// set biquad pole radius
4+.99 => f.prad;
5+// set biquad gain
6+.05 => f.gain;
7+// set equal zeros
8+1 => f.eqzs;
9+// our float
10+0.0 => float t;
11+
12+// concurrent control
13+fun void wind_gain( )
14+{
15+ 0.0 => float g;
16+
17+ // time loop to ramp up the gain / oscillate
18+ while( true )
19+ {
20+ Std.fabs( Math.sin( g ) ) => n.gain;
21+ g + .001 => g;
22+ 10::ms => now;
23+ }
24+}
25+
26+// run wind_gain on anothre shred
27+spork ~ wind_gain();
28+
29+// infinite time-loop
30+while( true )
31+{
32+ // sweep the filter resonant frequency
33+ 100.0 + Std.fabs(Math.sin(t)) * 15000.0 => f.pfreq;
34+ t + .01 => t;
35+ // advance time
36+ 100::ms => now;
37+}
examples/basic/zerox.ck+14−0
@@ -0,0 +1,14 @@
1+// step generator, zero crossing detector, dac
2+Step s => ZeroX z => dac;
3+1.0 => float v;
4+
5+// infnite time-loop
6+while( true )
7+{
8+ // set the step value
9+ v => s.next;
10+ // change step value
11+ -v => v;
12+ // advance time
13+ 100::ms => now;
14+}

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