Debian Codegraph @

examples/effects/reverb.ck

raw
1 //------------------------------------------------------------------------------
2 // name: stk_reverb
3 // desc: use keyboard keys <1, 2, 3> to listen to the built-in stk Reverb UGens!
4 // change DEVICE_ID to the appropriate number if this script isn't picking
5 // up your keyboard input
6 //
7 // 1: JCRev. John Chowning's reverberator class.
8 // 6 comb filters in parallel, followed by 3 allpass filters, a lowpass filter,
9 // and another allpass in series, followed by two allpass filters in parallel
10 // with corresponding right and left outputs.
11 //
12 // 2. NRev. CCRMA's NRev reverberator class.
13 // This class is derived from the CLM NRev function, which is based on the use of
14 // networks of simple allpass and comb delay filters.
15 //
16 // 3. PRCRev. Perry's simple reverberator class.
17 // The least-expensive reverb, but also maybe the lowest quality...
18 //
19 // Usage: use the .mix() method to control wet/gain ratio!
20 // E.g. `.mix(.05)` sets the reverb UGen's output to be 5% wet and 95% dry.
21 //
22 // Performance: Reverbs tend to be very computationally expensive. Good practice
23 // is to gather all your signals and pipe them through a single main reverb UGen,
24 // rather than having a separate reverb for each signal.
25 //
26 // author: azaday
27 // date: Spring 2023
28 //------------------------------------------------------------------------------
29 0 => int DEVICE_ID; // CHANGE ME IF KEYBOARD NOT FOUND
30
31 // Setup UGen graph
32 SndBuf buf => JCRev jcRev => dac;
33 buf => NRev nRev => dac;
34 buf => PRCRev prcRev => dac;
35
36 // set wet/dry ratio
37 .5 => float revMix;
38 revMix => jcRev.mix;
39 revMix => nRev.mix;
40 revMix => prcRev.mix;
41
42 // start with jcRev
43 <<< "playing audio through JCRev" >>>;
44 1.0 => jcRev.gain;
45 0.0 => nRev.gain;
46 0.0 => prcRev.gain;
47
48 // "Dope" will be our source audio signal
49 "special:dope" => buf.read;
50
51 fun void looper(SndBuf @ buf) {
52 while (true) {
53 buf.length() => now;
54 200::ms => now;
55 0 => buf.pos;
56 }
57 } spork ~ looper(buf);
58
59 // 3 => int playCount; // number of times before swapping to next reverb
60 fun void keyboardListener(int device) {
61 Hid hi;
62 HidMsg msg;
63
64 0x1e => int KEY_1; // Keyboard 1 and !
65 0x1f => int KEY_2; // Keyboard 2 and @
66 0x20 => int KEY_3; // Keyboard 3 and #
67
68 // open keyboard (get device number from command line)
69 if( !hi.openKeyboard( device ) ) {
70 cherr <= "keyboard " + device + " not found" <= IO.newline();
71 me.exit();
72 }
73 <<< "keyboard '" + hi.name() + "' ready", "" >>>;
74
75 while( true ) {
76 hi => now;
77 while( hi.recv( msg ) ) {
78 if( msg.isButtonDown() ) {
79 if (msg.key == KEY_1) {
80 <<< "switching to JCRev" >>>;
81 1.0 => jcRev.gain;
82 0.0 => nRev.gain;
83 0.0 => prcRev.gain;
84 }
85
86 if (msg.key == KEY_2) {
87 <<< "switching to NRev" >>>;
88 0.0 => jcRev.gain;
89 1.0 => nRev.gain;
90 0.0 => prcRev.gain;
91 }
92
93 if (msg.key == KEY_3) {
94 <<< "switching to PRCRev" >>>;
95 0.0 => jcRev.gain;
96 0.0 => nRev.gain;
97 1.0 => prcRev.gain;
98 }
99
100 }
101 }
102 }
103 } spork ~ keyboardListener(DEVICE_ID);
104
105 // keey main shred alive
106 while (1::second => now) {}