| 1 |
//-------------------------------------------------------------------- |
| 2 |
// name: thx.ck |
| 3 |
// desc: emulation of the original THX Deep Note |
| 4 |
// (by Dr. James Andy Moorer) |
| 5 |
// |
| 6 |
// author: Perry R. Cook (https://www.cs.princeton.edu/~prc/) |
| 7 |
// Ge Wang (https://ccrma.stanford.edu/~ge/) |
| 8 |
// |
| 9 |
// Perry R. Cook (Jan 8, 2007) -- original ChucK version |
| 10 |
// Ge Wang -- modified final chord to align with original Deep Note |
| 11 |
// -- added beginning "chaotic" section |
| 12 |
// -- time-driven loops (was counter-driven loops) |
| 13 |
// |
| 14 |
// THX resources from /Artful Design/: |
| 15 |
// https://artful.design/thx/ |
| 16 |
// |
| 17 |
// Andy Moorer's personal account |
| 18 |
//. http://www.jamminpower.org/THX.html |
| 19 |
// |
| 20 |
// ------------------------------------------------------------------- |
| 21 |
// Ge, Fall 2017: from Andy Mooorer: |
| 22 |
// ------------------------------------------------------------------- |
| 23 |
// OK - I dug out the original program. Here are the frequency |
| 24 |
// bounds of the cluster: |
| 25 |
// #define LOCLUST 40.0 |
| 26 |
// #define HICLUST 350.0 |
| 27 |
// |
| 28 |
// I had started with them in a more narrow range, but then |
| 29 |
// widened it. With the randomness, they never get anywhere |
| 30 |
// near the limits. And here are the pitches in the final |
| 31 |
// chord for all 30 voices: |
| 32 |
// |
| 33 |
// double freqs[NOSCS], initialfreqs[NOSCS], |
| 34 |
// finalfreqs[] = |
| 35 |
// { 1800.0, 1800.0, 1800.0, |
| 36 |
// 1500.0, 1500.0, |
| 37 |
// 1200.0, 1200.0, 1200.0, 1200.0, |
| 38 |
// 900.0, 900.0, 900.0, 900.0, |
| 39 |
// 600.0, 600.0, 600.0, |
| 40 |
// 300.0, 300.0, 300.0, 300.0, |
| 41 |
// 150.0, 150.0, 150.0, 150.0, |
| 42 |
// 75.0, 75.0, 75.0 |
| 43 |
// 37.5, 37.5, 37.5, |
| 44 |
// }; |
| 45 |
// |
| 46 |
// Note that in the final chord, they are detuned a bit by |
| 47 |
// injecting a bit of randomness to make sure they don't fuse |
| 48 |
// totally. Several people have commented that the chord |
| 49 |
// sounds "bigger" than an equivalent orchestra or organ |
| 50 |
// chord (like the big chord in the Bm fugue which was my |
| 51 |
// inspiration). I believe this is because of the just |
| 52 |
// temperament of the chord. Moving the thirds and fifths |
| 53 |
// to equal temperament just doesn't have the same impact. |
| 54 |
// |
| 55 |
// Let me know if you have any other questions. I am really |
| 56 |
// excited to see your new book. It looks like great fun! |
| 57 |
// -A |
| 58 |
//-------------------------------------------------------------------- |
| 59 |
|
| 60 |
// 30 target frequencies, corresponding to pitches in a big chord: |
| 61 |
// D1, D2, D3, D4, D5, A5, D6, F#6, A6 |
| 62 |
[ 37.5, 75, 150, 300, 600, 900, 1200, 1500, 1800, |
| 63 |
37.5, 75, 150, 300, 600, 900, 1200, 1500, 1800, |
| 64 |
37.5, 75, 150, 300, 600, 900, 1200, 1800, |
| 65 |
150, 300, 900, 1200 |
| 66 |
] @=> float targets[]; |
| 67 |
|
| 68 |
// initial frequencies |
| 69 |
float initials[30]; |
| 70 |
// for the initial "wavering" in the steady state |
| 71 |
float initialsBase[30]; |
| 72 |
float randomRates[30]; |
| 73 |
|
| 74 |
// parameters (play with these to control timing) |
| 75 |
12.5::second => dur initialHold; // initial steady segment |
| 76 |
6.0::second => dur sweepTime; // duration over which to change freq |
| 77 |
5.5::second => dur targetHold; // duration to hold target chord |
| 78 |
6.0::second => dur decayTime; // duration for reverb tail to decay to 0 |
| 79 |
|
| 80 |
// sound objects |
| 81 |
SawOsc saw[30]; // sawtooth waveform (30 of them) |
| 82 |
Gain gainL[30]; // left gain (volume) |
| 83 |
Gain gainR[30]; // right gain (volume) |
| 84 |
// connect stereo reverberators to output |
| 85 |
NRev reverbL => dac.left; |
| 86 |
NRev reverbR => dac.right; |
| 87 |
// set the amount of reverb |
| 88 |
0.075 => reverbL.mix => reverbR.mix; |
| 89 |
|
| 90 |
// for each sawtooth: connect, compute frequency trajectory |
| 91 |
for( 0 => int i; i < 30; i++ ) |
| 92 |
{ |
| 93 |
// connect sound objects (left channel) |
| 94 |
saw[i] => gainL[i] => reverbL; |
| 95 |
// connect sound objects (right channel) |
| 96 |
saw[i] => gainR[i] => reverbR; |
| 97 |
// randomize initial frequencies |
| 98 |
Math.random2f( 160.0, 360.0 ) => initials[i] |
| 99 |
=> initialsBase[i] => saw[i].freq; |
| 100 |
// initial gain for each sawtooth generator |
| 101 |
0.1 => saw[i].gain; |
| 102 |
// randomize gain (volume) |
| 103 |
Math.random2f( 0.0, 1.0 ) => gainL[i].gain; |
| 104 |
// right.gain is 1-left.gain -- effectively panning in stereo |
| 105 |
1.0 - gainL[i].gain() => gainR[i].gain; |
| 106 |
// rate at which to waver the initial voices |
| 107 |
Math.random2f(.1,1) => randomRates[i]; |
| 108 |
} |
| 109 |
|
| 110 |
// hold steady cluster (initial chaotic random frequencies) |
| 111 |
now + initialHold => time end; |
| 112 |
// fade in from silence |
| 113 |
while( now < end ) |
| 114 |
{ |
| 115 |
// percentage (should go from 0 to 1) |
| 116 |
1 - (end-now) / initialHold => float progress; |
| 117 |
// for each sawtooth |
| 118 |
for( 0 => int i; i < 30; i++ ) { |
| 119 |
// set gradually decaying values to volume |
| 120 |
0.1 * Math.pow(progress,3) => saw[i].gain; |
| 121 |
// waver the voices |
| 122 |
initialsBase[i] + (1.25-progress)*.5*initialsBase[i]*Math.sin(now/second*randomRates[i]) |
| 123 |
=> initials[i] => saw[i].freq; |
| 124 |
} |
| 125 |
// advance time |
| 126 |
10::ms => now; |
| 127 |
} |
| 128 |
|
| 129 |
// when to stop |
| 130 |
now + sweepTime => end; |
| 131 |
// sweep freqs towards target freqs |
| 132 |
while( now < end ) |
| 133 |
{ |
| 134 |
// percentage (should go from 0 to 1) |
| 135 |
1 - (end-now)/sweepTime => float progress; |
| 136 |
// for each sawtooth |
| 137 |
for( 0 => int i; i < 30; i++ ) { |
| 138 |
// update frequency by delta, towards target |
| 139 |
initials[i] + (targets[i]-initials[i])*progress => saw[i].freq; |
| 140 |
} |
| 141 |
// advance time |
| 142 |
10::ms => now; |
| 143 |
} |
| 144 |
|
| 145 |
// at this point: reached target freqs; briefly hold |
| 146 |
targetHold => now; |
| 147 |
|
| 148 |
// when to stop |
| 149 |
now + decayTime => end; |
| 150 |
// chord decay (fade to silence) |
| 151 |
while( now < end ) |
| 152 |
{ |
| 153 |
// percentage (should go from 1 to 0) |
| 154 |
(end-now) / decayTime => float progress; |
| 155 |
// for each sawtooth |
| 156 |
for( 0 => int i; i < 30; i++ ) { |
| 157 |
// set gradually decaying values to volume |
| 158 |
0.1 * progress => saw[i].gain; |
| 159 |
} |
| 160 |
// advance time |
| 161 |
10::ms => now; |
| 162 |
} |
| 163 |
|
| 164 |
// wait for reverb tail before ending |
| 165 |
5::second => now; |