*** empty log message ***
[chuck-blob.git] / v2 / examples / stk / stif-o-karp.ck
blob50b6c1d76ff19e728e0f99a7eaebd71368049d5c
1 ch//---------------|
2 // karp-o-matic!
3 // by: Ge Wang (gewang@cs.princeton.edu)
4 //     Perry R. Cook (prc@cs.princeton.edu)
5 //------------------|
7 // our patch
8 StifKarp karp => JCRev r => Echo a => Echo b => Echo c => dac;
9 // set the gain
10 .95 => r.gain;
11 // set the reverb mix
12 .1 => r.mix;
13 // set max delay for echo
14 1000::ms => a.max => b.max => c.max;
15 // set delay for echo
16 750::ms => a.delay => b.delay => c.delay;
17 // set the initial effect mix
18 0.0 => a.mix => b.mix => c.mix;
20 // shred to modulate the mix
21 fun void echo_Shred( )
23     0.0 => float decider => float mix => float old => float inc;
25     // time loop
26     while( true )
27     {
28         Std.rand2f(0.0,1.0) => decider;
29         if( decider < .35 ) 0.0 => mix;
30         else if( decider < .55 ) .08 => mix;
31         else if( decider < .8 ) .5 => mix;
32         else .15 => mix;
34         // find the increment
35         (mix-old)/1000.0 => inc; 1000 => int n;
36         // time loop
37         while( n-- )
38         {
39             // set the mix for a, b, c
40             old + inc => old => a.mix => b.mix => c.mix;
41             1::ms => now;
42         }
43         // remember the old
44         mix => old;
45         // let time pass until the next iteration
46         Std.rand2(2,6)::second => now;
47     }
50 // let echo shred go
51 spork ~ echo_Shred();
53 // scale
54 [ 0, 2, 4, 7, 9 ] @=> int scale[];
56 // our main loop
57 while( true )
59     // position
60     Std.rand2f( 0.2, 0.8 ) => karp.pickupPosition;
61     // frequency...
62     scale[Std.rand2(0,scale.cap()-1)] => int freq;
63     220.0 * Math.pow( 1.05946, (Std.rand2(0,2)*12)
64                       +freq ) => karp.freq;
65     // pluck it!
66     0.0 => karp.stretch;
67     Std.rand2f( 0.2, 0.9 ) => karp.pluck;
69     if( Std.randf() > 0.8 )
70     { 500::ms => now; }
71     else if( Std.randf() > .85 )
72     { 250::ms => now; }
73     else if( Std.randf() > -0.9 )
74     { .125::second => now; }
75     else
76     {
77         1 => int i => int pick_dir;
78         // how many times
79         4 * Std.rand2( 1, 5 ) => int pick;
80         0.0 => float pluck;
81         0.7 / pick => float inc;
82         // time loop
83         for( ; i < pick; i++ )
84         {
85             75::ms => now;
86             Std.rand2f(.2,.3) + i*inc => pluck;
87             i * 0.025 => karp.stretch;
88             pluck + -.2 * pick_dir => karp.pluck;
89             // simulate pluck direction
90             !pick_dir => pick_dir;
91         }
92         // let time pass for final pluck
93         75::ms => now;
94     }