Difference between revisions of "ChucK/foo.ck"

From CSWiki
Jump to: navigation, search
(Boolean_Quartet.ck)
m (formatting)
 
Line 1: Line 1:
// Boolean_Quartet.ck
+
// Boolean_Quartet.ck
// copyright 2007 Les Hall
+
// copyright 2007 Les Hall
// This software released under the GNU General Protective License
+
// This software released under the GNU General Protective License
// experiments with creating music from base n sequences
+
// experiments with creating music from base n sequences
// four instruments in Boolean logic sequence
+
// four instruments in Boolean logic sequence
 
+
// control variables
+
// control variables
150 => float frequency;
+
150 => float frequency;
0.25 => float gain1;  // SinOsc
+
0.25 => float gain1;  // SinOsc
0.25 => float gain2;  // HF plucked
+
0.25 => float gain2;  // HF plucked
0.25 => float gain3;  // LF plucked
+
0.25 => float gain3;  // LF plucked
0.15 => float gain4;  // guitar
+
0.15 => float gain4;  // guitar
2 => int n; // numeric base of the sequence
+
2 => int n; // numeric base of the sequence
 
+
// gain of each instrument
+
// gain of each instrument
Gain g1;
+
Gain g1;
Gain g2;
+
Gain g2;
Gain g3;
+
Gain g3;
Gain g4;
+
Gain g4;
gain1 => g1.gain;  // binary count SinOsc's
+
gain1 => g1.gain;  // binary count SinOsc's
gain2 => g2.gain;  // high frequency plucked instrument
+
gain2 => g2.gain;  // high frequency plucked instrument
gain3 => g3.gain;  // low frequency plucked instrument
+
gain3 => g3.gain;  // low frequency plucked instrument
gain4 => g4.gain;  // screaming guitar instrument
+
gain4 => g4.gain;  // screaming guitar instrument
 
+
// the background oscillators
+
// the background oscillators
SinOsc s[5];
+
SinOsc s[5];
for (0 => int i; i<5; i++) {
+
for (0 => int i; i<5; i++) {
    // the patches
+
    // the patches
    s[i] => g1 => dac;
+
    s[i] => g1 => dac;
    // the frequencies
+
    // the frequencies
    (5 - i) * frequency => s[i].freq;
+
    (5 - i) * frequency => s[i].freq;
}
+
}
 
+
// The plucked treble instrument
+
// The plucked treble instrument
Impulse i1;
+
Impulse i1;
JCRev r1;
+
JCRev r1;
r1.mix(0.02);
+
r1.mix(0.02);
BPF f[5];
+
BPF f[5];
i1 => f[0] => r1 => g2 => dac;
+
i1 => f[0] => r1 => g2 => dac;
i1 => f[1] => r1 => g2 => dac;
+
i1 => f[1] => r1 => g2 => dac;
i1 => f[2] => r1 => g2 => dac;
+
i1 => f[2] => r1 => g2 => dac;
i1 => f[3] => r1 => g2 => dac;
+
i1 => f[3] => r1 => g2 => dac;
i1 => f[4] => r1 => g2 => dac;
+
i1 => f[4] => r1 => g2 => dac;
for (0 => int i; i < 5; i++) {
+
for (0 => int i; i < 5; i++) {
    // the patches
+
    // the patches
    //i1 => BPF f[i] => r1 => dac;
+
    //i1 => BPF f[i] => r1 => dac;
    // the quality factors
+
    // the quality factors
    100 => f[i].Q;
+
    100 => f[i].Q;
    // the frequencies
+
    // the frequencies
    (i + 1) * frequency => f[i].freq;
+
    (i + 1) * frequency => f[i].freq;
}
+
}
// the gains
+
// the gains
0.5 => f[0].gain;
+
0.5 => f[0].gain;
1.0 => f[1].gain;
+
1.0 => f[1].gain;
0.5 => f[2].gain;
+
0.5 => f[2].gain;
0.5 => f[3].gain;
+
0.5 => f[3].gain;
0.4 => f[4].gain;
+
0.4 => f[4].gain;
 
+
// the plucked bass instrument
+
// the plucked bass instrument
Impulse i2;
+
Impulse i2;
JCRev r2;
+
JCRev r2;
r2.mix(0.05);
+
r2.mix(0.05);
BPF fb[5];
+
BPF fb[5];
// the patches
+
// the patches
i2 => fb[0] => r2 => g3 => dac;
+
i2 => fb[0] => r2 => g3 => dac;
i2 => fb[1] => r2 => g3 => dac;
+
i2 => fb[1] => r2 => g3 => dac;
i2 => fb[2] => r2 => g3 => dac;
+
i2 => fb[2] => r2 => g3 => dac;
i2 => fb[3] => r2 => g3 => dac;
+
i2 => fb[3] => r2 => g3 => dac;
i2 => fb[4] => r2 => g3 => dac;
+
i2 => fb[4] => r2 => g3 => dac;
for (0 => int i; i < 5; i++) {
+
for (0 => int i; i < 5; i++) {
    // the quality factors
+
    // the quality factors
    200 => fb[i].Q;
+
    200 => fb[i].Q;
    // the frequencies
+
    // the frequencies
    (i + 1) * frequency => f[i].freq;
+
    (i + 1) * frequency => f[i].freq;
    // the gains
+
    // the gains
    2.0 / (i + 1) => f[i].gain;
+
    2.0 / (i + 1) => f[i].gain;
}
+
}
 
+
// the screaming guitar instrument
+
// the screaming guitar instrument
SinOsc sg[5];
+
SinOsc sg[5];
JCRev rg;
+
JCRev rg;
0.20 => rg.mix;
+
0.20 => rg.mix;
for (0 => int i; i<5; i++) {
+
for (0 => int i; i<5; i++) {
    // the patches
+
    // the patches
    sg[i] => rg => g4 => dac;
+
    sg[i] => rg => g4 => dac;
    // the frequencies
+
    // the frequencies
    (i + 1) * frequency => sg[i].freq;
+
    (i + 1) * frequency => sg[i].freq;
}
+
}
// the gains
+
// the gains
1.0 => sg[0].gain;
+
1.0 => sg[0].gain;
0.8 => sg[1].gain;
+
0.8 => sg[1].gain;
0.6 => sg[2].gain;
+
0.6 => sg[2].gain;
0.4 => sg[3].gain;
+
0.4 => sg[3].gain;
0.2 => sg[4].gain;
+
0.2 => sg[4].gain;
 
+
 
+
// time loop
+
// time loop
while (true) {
+
while (true) {
    // print the base for each sequence
+
    // print the base for each sequence
    <<< "base", n >>>;
+
    <<< "base", n >>>;
 
+
    // calculate the logic threshold
+
    // calculate the logic threshold
    (n-1) / 2.0 => float t;
+
    (n-1) / 2.0 => float t;
 
+
    // loop in a 5-bit binary sequence and pluck the strings
+
    // loop in a 5-bit binary sequence and pluck the strings
    for (0 => int j1; j1 < n; j1++) {
+
    for (0 => int j1; j1 < n; j1++) {
        j1 / 16.0 / (n-1) => s[0].gain;
+
        j1 / 16.0 / (n-1) => s[0].gain;
        for (0 => int j2; j2 < n; j2++) {
+
        for (0 => int j2; j2 < n; j2++) {
            j2 / 8.0 / (n-1) => s[1].gain;
+
            j2 / 8.0 / (n-1) => s[1].gain;
            for (0 => int j3; j3 < n; j3++) {
+
            for (0 => int j3; j3 < n; j3++) {
                j3 / 4.0 / (n-1) => s[2].gain;
+
                j3 / 4.0 / (n-1) => s[2].gain;
                for (0 => int j4; j4 < n; j4++) {
+
                for (0 => int j4; j4 < n; j4++) {
                    j4 / 2.0 / (n-1) => s[3].gain;
+
                    j4 / 2.0 / (n-1) => s[3].gain;
                    if (j4 > t) {
+
                    if (j4 > t) {
                        // the low frequency plucked instrument
+
                        // the low frequency plucked instrument
                        (1.5 * (2 * (n - 1) + j3) / (3 *(n - 1))) * frequency => float freq;
+
                        (1.5 * (2 * (n - 1) + j3) / (3 *(n - 1))) * frequency => float freq;
                        for (0 => int i; i < 5; i++) {
+
                        for (0 => int i; i < 5; i++) {
                            (i + 1) * freq => fb[i].freq;
+
                            (i + 1) * freq => fb[i].freq;
                        }
+
                        }
                        1000.0 => i2.next;
+
                        1000.0 => i2.next;
                    }
+
                    }
                    for (0 => int j5; j5 < n; j5++) {
+
                    for (0 => int j5; j5 < n; j5++) {
                        j5 / 1.0 / (n-1) => s[4].gain;
+
                        j5 / 1.0 / (n-1) => s[4].gain;
                        // the high frequency plucked instrument
+
                        // the high frequency plucked instrument
                        if ((j2 > t) && (j4 > t) || (j5 > t) && (j3 > t)) {
+
                        if ((j2 > t) && (j4 > t) || (j5 > t) && (j3 > t)) {
                            (2 * (j1 + j2 + j3 + j4 + j5) / (5 * (n - 1))) * frequency => float f
+
                            (2 * (j1 + j2 + j3 + j4 + j5) / (5 * (n - 1))) * frequency => float freq;
req;
+
                            for (0 => int i; i < 5; i++) {
                            for (0 => int i; i < 5; i++) {
+
                                (i + 1) * freq => f[i].freq;
                                (i + 1) * freq => f[i].freq;
+
                            }
                            }
+
                            300.0 => i1.next;
                            300.0 => i1.next;
+
                        }
                        }
+
                        // the screaming guitar
                        // the screaming guitar
+
                        if ((j3 > t) && (j4 > t)) {
                        if ((j3 > t) && (j4 > t)) {
+
                            (0.5 * ((j1 > t) + (j2 > t) + (j3 > t) + (j4 > t) + (j5 > t))) * frequency => float freq;
                            (0.5 * ((j1 > t) + (j2 > t) + (j3 > t) + (j4 > t) + (j5 > t))) * freq
+
                            for (0 => int i; i<5; i++) {
uency => float freq;
+
                                (i + 1) * freq => sg[i].freq;
                            for (0 => int i; i<5; i++) {
+
                            }
                                (i + 1) * freq => sg[i].freq;
+
                        }
                            }
+
                        (n - j5) / (n $ float) * gain4 => g4.gain;
                        }
+
                        100::ms => now; // advance time
                        (n - j5) / (n $ float) * gain4 => g4.gain;
+
                    }
                        100::ms => now; // advance time
+
                }
                    }
+
            }
                }
+
        }
            }
+
    }
        }
+
    }
+
    // shut off the oscillators
 
+
    for (0 => int i; i < 5; i++) {
    // shut off the oscillators
+
        0 => s[i].gain;
    for (0 => int i; i < 5; i++) {
+
    }
        0 => s[i].gain;
+
    0 => g4.gain;
    }
+
    0 => g4.gain;
+
    // increment the base number
 
+
    n++;
    // increment the base number
+
    n++;
+
    // advance time between binary counts
 
+
    <<< "pause" >>>;
    // advance time between binary counts
+
    3::second => now;
    <<< "pause" >>>;
+
}
    3::second => now;
 
}
 

Latest revision as of 10:54, 5 September 2008

// Boolean_Quartet.ck
// copyright 2007 Les Hall
// This software released under the GNU General Protective License
// experiments with creating music from base n sequences
// four instruments in Boolean logic sequence

// control variables
150 => float frequency;
0.25 => float gain1;  // SinOsc
0.25 => float gain2;  // HF plucked
0.25 => float gain3;  // LF plucked
0.15 => float gain4;  // guitar
2 => int n; // numeric base of the sequence

// gain of each instrument
Gain g1;
Gain g2;
Gain g3;
Gain g4;
gain1 => g1.gain;  // binary count SinOsc's
gain2 => g2.gain;  // high frequency plucked instrument
gain3 => g3.gain;  // low frequency plucked instrument
gain4 => g4.gain;  // screaming guitar instrument

// the background oscillators
SinOsc s[5];
for (0 => int i; i<5; i++) {
    // the patches
    s[i] => g1 => dac;
    // the frequencies
    (5 - i) * frequency => s[i].freq;
}

// The plucked treble instrument
Impulse i1;
JCRev r1;
r1.mix(0.02);
BPF f[5];
i1 => f[0] => r1 => g2 => dac;
i1 => f[1] => r1 => g2 => dac;
i1 => f[2] => r1 => g2 => dac;
i1 => f[3] => r1 => g2 => dac;
i1 => f[4] => r1 => g2 => dac;
for (0 => int i; i < 5; i++) {
    // the patches
    //i1 => BPF f[i] => r1 => dac;
    // the quality factors
    100 => f[i].Q;
    // the frequencies
    (i + 1) * frequency => f[i].freq;
}
// the gains
0.5 => f[0].gain;
1.0 => f[1].gain;
0.5 => f[2].gain;
0.5 => f[3].gain;
0.4 => f[4].gain;

// the plucked bass instrument
Impulse i2;
JCRev r2;
r2.mix(0.05);
BPF fb[5];
// the patches
i2 => fb[0] => r2 => g3 => dac;
i2 => fb[1] => r2 => g3 => dac;
i2 => fb[2] => r2 => g3 => dac;
i2 => fb[3] => r2 => g3 => dac;
i2 => fb[4] => r2 => g3 => dac;
for (0 => int i; i < 5; i++) {
    // the quality factors
    200 => fb[i].Q;
    // the frequencies
    (i + 1) * frequency => f[i].freq;
    // the gains
    2.0 / (i + 1) => f[i].gain;
}

// the screaming guitar instrument
SinOsc sg[5];
JCRev rg;
0.20 => rg.mix;
for (0 => int i; i<5; i++) {
    // the patches
    sg[i] => rg => g4 => dac;
    // the frequencies
    (i + 1) * frequency => sg[i].freq;
}
// the gains
1.0 => sg[0].gain;
0.8 => sg[1].gain;
0.6 => sg[2].gain;
0.4 => sg[3].gain;
0.2 => sg[4].gain;


// time loop
while (true) {
    // print the base for each sequence
    <<< "base", n >>>;

    // calculate the logic threshold
    (n-1) / 2.0 => float t;

    // loop in a 5-bit binary sequence and pluck the strings
    for (0 => int j1; j1 < n; j1++) {
        j1 / 16.0 / (n-1) => s[0].gain;
        for (0 => int j2; j2 < n; j2++) {
            j2 / 8.0 / (n-1) => s[1].gain;
            for (0 => int j3; j3 < n; j3++) {
                j3 / 4.0 / (n-1) => s[2].gain;
                for (0 => int j4; j4 < n; j4++) {
                    j4 / 2.0 / (n-1) => s[3].gain;
                    if (j4 > t) {
                        // the low frequency plucked instrument
                        (1.5 * (2 * (n - 1) + j3) / (3 *(n - 1))) * frequency => float freq;
                        for (0 => int i; i < 5; i++) {
                            (i + 1) * freq => fb[i].freq;
                        }
                        1000.0 => i2.next;
                    }
                    for (0 => int j5; j5 < n; j5++) {
                        j5 / 1.0 / (n-1) => s[4].gain;
                        // the high frequency plucked instrument
                        if ((j2 > t) && (j4 > t) || (j5 > t) && (j3 > t)) {
                            (2 * (j1 + j2 + j3 + j4 + j5) / (5 * (n - 1))) * frequency => float freq;
                            for (0 => int i; i < 5; i++) {
                                (i + 1) * freq => f[i].freq;
                            }
                            300.0 => i1.next;
                        }
                        // the screaming guitar
                        if ((j3 > t) && (j4 > t)) {
                            (0.5 * ((j1 > t) + (j2 > t) + (j3 > t) + (j4 > t) + (j5 > t))) * frequency => float freq;
                            for (0 => int i; i<5; i++) {
                                (i + 1) * freq => sg[i].freq;
                            }
                        }
                        (n - j5) / (n $ float) * gain4 => g4.gain;
                        100::ms => now; // advance time
                    }
                }
            }
        }
    }

    // shut off the oscillators
    for (0 => int i; i < 5; i++) {
        0 => s[i].gain;
    }
    0 => g4.gain;

    // increment the base number
    n++;

    // advance time between binary counts
    <<< "pause" >>>;
    3::second => now;
}