| 1 |
// tubebell-algo5.ck |
| 2 |
// 4-operator FM instrument Tubular Bell example |
| 3 |
// Perry Cook, 2024 (after STK tubebell example) |
| 4 |
Gain mixer[2] => NRev rev[2] => dac; // stereo |
| 5 |
9 => int numBells; // round robin and stereo |
| 6 |
TubeBell bell[numBells]; |
| 7 |
Pan2 pan[numBells]; |
| 8 |
for (int i; i < numBells; i++) { |
| 9 |
bell[i] => pan[i] => mixer; |
| 10 |
bell[i].opADSR(0,0.01,0.4,0.0,0.04); // short envelopes for |
| 11 |
bell[i].opADSR(2,0.01,0.4,0.0,0.04); // more rapid articulation |
| 12 |
-1.0 + 0.25*i => pan[i].pan; // stereo bell spread |
| 13 |
} |
| 14 |
TubeBell bassBell => Pan2 bbPan => mixer; // occasional pedal tone |
| 15 |
0.05 => rev[0].mix => rev[1].mix; |
| 16 |
bell => Delay del => Pan2 dpan => rev; // cool echo |
| 17 |
del => del; |
| 18 |
0.6 => del.gain; |
| 19 |
0.2::second => dur T; |
| 20 |
17*T => del.max => del.delay; |
| 21 |
|
| 22 |
// Tubular Bells, Michael Oldfield (Excorcist Theme) |
| 23 |
[64,72,64,74,64,71,72,64,71,64,69,64,71,64,67,69] @=> int pat1[]; |
| 24 |
[64,72,64,74,64,71,72,64,69,64,71,64,67,69] @=> int pat2[]; |
| 25 |
|
| 26 |
0 => int round; |
| 27 |
|
| 28 |
<<< "FM Bell", "Sine waves yield inharmonic spectrum!!">>>; |
| 29 |
<<< "Long Bell Ding!!", "110 Hz" >>>; |
| 30 |
110 => bassBell.freq; // pedal A note (occasionally) |
| 31 |
1 => bassBell.noteOn; |
| 32 |
2*second => now; |
| 33 |
<<< "Dong!!", "220 Hz" >>>; |
| 34 |
220 => bassBell.freq; // pedal A note (occasionally) |
| 35 |
1 => bassBell.noteOn; |
| 36 |
2*second => now; |
| 37 |
<<< "Dang!!", "330 Hz" >>>; |
| 38 |
330 => bassBell.freq; // pedal A note (occasionally) |
| 39 |
1 => bassBell.noteOn; |
| 40 |
2*second => now; |
| 41 |
110 => bassBell.freq; // pedal A note (occasionally) |
| 42 |
1 => bassBell.noteOn; |
| 43 |
|
| 44 |
<<< "Melody on shorter envelope bells", "" >>>; |
| 45 |
while (1) { |
| 46 |
int pat[]; |
| 47 |
if (maybe) { |
| 48 |
playPattern(pat1); |
| 49 |
<<< "Pattern 1", "" >>>; |
| 50 |
} |
| 51 |
else { |
| 52 |
playPattern(pat2); |
| 53 |
<<< "Pattern 2", "" >>>; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
fun void playPattern(int pat[]) { |
| 58 |
1 => int oct; |
| 59 |
if (maybe*maybe) { |
| 60 |
2 => oct; // occasional octave higher |
| 61 |
<<< "Octave higher", "" >>>; |
| 62 |
} |
| 63 |
for (0 => int i; i < pat.cap(); i++) { |
| 64 |
Std.mtof(pat[i])*oct => bell[round].freq; |
| 65 |
if (i == 1 && maybe*maybe) { |
| 66 |
1 => bassBell.noteOn; |
| 67 |
<<< "Dong!", "" >>>; |
| 68 |
} |
| 69 |
1 => bell[round].noteOn; |
| 70 |
round++; |
| 71 |
if (round == numBells) 0 => round; |
| 72 |
T => now; |
| 73 |
} |
| 74 |
} |
| 75 |
|