Debian Codegraph @

examples/deep/shepard.ck

raw
1 //--------------------------------------------------------------------
2 // name: shepard.ck
3 // desc: continuous shepard-risset tone generator;
4 // ascending but can easily made to descend
5 //
6 // author: Ge Wang (https://ccrma.stanford.edu/~ge/)
7 // date: spring 2016
8 //--------------------------------------------------------------------
9
10 // mean for normal intensity curve
11 66 => float MU;
12 // standard deviation for normal intensity curve
13 42 => float SIGMA;
14 // normalize to 1.0 at x==MU
15 1 / Math.gauss(MU, MU, SIGMA) => float SCALE;
16 // increment per unit time (use negative for descending)
17 .004 => float INC;
18 // unit time (change interval)
19 1::ms => dur T;
20
21 // starting pitches (in MIDI note numbers, octaves apart)
22 [ 12.0, 24, 36, 48, 60, 72, 84, 96, 108 ] @=> float pitches[];
23 // number of tones
24 pitches.size() => int N;
25 // bank of tones
26 TriOsc tones[N];
27 // overall gain
28 Gain gain => dac; 1.0/N => gain.gain;
29 // connect to dac
30 for( int i; i < N; i++ ) { tones[i] => gain; }
31
32 // infinite time loop
33 while( true )
34 {
35 for( int i; i < N; i++ )
36 {
37 // set frequency from pitch
38 pitches[i] => Std.mtof => tones[i].freq;
39 // compute loundess for each tone
40 Math.gauss( pitches[i], MU, SIGMA ) * SCALE => float intensity;
41 // map intensity to amplitude
42 intensity*96 => Math.dbtorms => tones[i].gain;
43 // increment pitch
44 INC +=> pitches[i];
45 // wrap (for positive INC)
46 if( pitches[i] > 120 ) 108 -=> pitches[i];
47 // wrap (for negative INC)
48 else if( pitches[i] < 12 ) 108 +=> pitches[i];
49 }
50
51 // advance time
52 T => now;
53 }