ChucK/kijjaz-friends-sounds.ck

From CSWiki
Revision as of 13:29, 5 November 2009 by Kijjaz (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Kijjaz and Inventor's Thunder:

// mini Thunder v. 1.0.2 (for ChucK programming language) 
// Copyright (C) 2009 Kijjasak Triyanond (kijjaz@gmail.com), Inventor (Les)

/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    For GNU General Public License, see http://www.gnu.org/licenses
*/

// A Thunder made from a low-pass-filtered Noise,
// enveloped by a random (but slow-changing) signal (which is a verylow-pass-filtered Noise),
// overdrived (by a SinOsc = by using Sine function waveshaping),
// reverbed (with NRev),
// and low-pass-filtered.
class Thundarr {

    Noise a => LPF b => Gain b_env => SinOsc c => NRev d => LPF e => Dyno limiter => Pan2 panner => dac;
    3 => b_env.op;
    1 => c.sync;

    limiter.limit();
    0.8 => limiter.thresh;
    10::ms => limiter.attackTime;
    5::second => limiter.releaseTime;

    Noise f => LPF g => b_env;

    // adjust these values for different sounds:
    b.set(80, 5); // filtering the main signal noise
    3.0 => c.gain; // thunder volumn (default = 1.0)
    40 => b.gain; // Drive parameter (default = 0.25)
    e.set(800, .75); // final filtering
    g.set(1, 0.5); // variation rate in envelope

    fun void thunder()
    {
        Math.rand2f(0.1, 0.5) => d.mix;
        Math.rand2f(-1, 1) => panner.pan;
        for (int i; i < Math.rand2(1, 5); i++) {
            Math.rand2f(0, 5) => a.gain;
            Math.rand2f(10, 300)::ms => now;
            0 => a.gain;
            Math.rand2f(100, 500)::ms => now;
        }
    }

    fun void update()
    {
        while(ms => now)
        {
            Std.fabs(g.last()) * 1000 + 1 => b.freq;
        }
    }
    spork ~ update();
}


Thundarr thundarr;

while (true) {
    thundarr.thunder();
    Math.rand2f(1, 5)::second => now;
}

Kijjaz's miniCannon v. 0.1.0

// mini Cannon v. 0.1.0 (for ChucK programming language) 
// Copyright (C) 2009 Kijjasak Triyanond (kijjaz@gmail.com)

/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    For GNU General Public License, see http://www.gnu.org/licenses
*/


class miniCannon010
{
    // init values
    200 => float baseFreq;
    0.0 => float envelope1 => float envelope2;
    
    5.0 => float driveGain; // default = 0.25
    0.2 => float revMix;
    
    1 => float minDur; // in ms
    5 => float maxDur; // in ms
    1.5 => float decayRate1; // in percent = for freq and osc decay
    1.0 => float decayRate2; // in percent = for overall amp decay
    
    // the patch
    SinOsc osc => Gain oscEnv => TriOsc drive => Gain ampEnv => NRev reverb => Gain output;
    1 => drive.sync;    
    
    revMix => reverb.mix;
    
    spork ~ update();
    
    fun void update() // updating mechanism
    {
        while(true) 
        {
            envelope1 * baseFreq * Std.rand2f(0, 1) => osc.freq; // update freq
            envelope1 => ampEnv.gain; // update amp envelope
            envelope2 * driveGain => oscEnv.gain; // update osc envelope        
            
            envelope1 * (1 - decayRate1/100) => envelope1; // make envelope decay
            envelope2 * (1 - decayRate2/100) => envelope2; // make envelope decay
            
            Std.rand2f(minDur, maxDur)::ms => now;
         }
     }
     
    
    fun void hit(float velocity) // use this to trigger with velocity (default is between 0 to 1 but can be any other if desired)
    {
        velocity => envelope1 => envelope2;
    }
}

// test code:

miniCannon010 foo;

foo.output => Dyno limiter => dac;
limiter.limit();
999999 => limiter.ratio;
.8 => limiter.thresh;

.1 => foo.output.gain;

while(true)
{
    foo.hit(Std.rand2f(.25, 1));
    4::second => now;
}