ChucK/kijjaz-utility-classes.ck

From CSWiki
Jump to: navigation, search

kijjaz's clipper 01: a class for doing the linear digital clipping, built only from Step, Gain, HalfRect. Connect the desired signal to .input and chuck out from .output to have the calculated result.

class kjzClipper01 // clip signal within -1 to 1 with simple UGens
{
   Gain input; // chuck input signal to this
   Gain output; // chuck this out to have the result
   
   Step one; 1 => one.next;
   input => HalfRect a;
   one => a; // calculate a from HalfRect(input + 1)
   one => Gain two; 2 => two.gain;
   -1 => a.gain;
   a => HalfRect b;
   two => b; // calculate b from HalfRect(2 - HalfRect(input + 1))
   -1 => b.gain;
   one => output;
   b => output; // the result we want: 1 - HalfRect(2 - HalfRect(input + 1))
}

kijjaz's TanOsc 01: a class to work as a tangent oscillator, created by dividing two SinOscs that are 90 degree out of phase. Adjust .input just like you do to a basic oscillator, or chuck into .input to control by syncing.

class kjzTanOsc01
{
   Phasor input => SinOsc s1; // sync the input phasor to Sine Wave s1's phase
   input => SinOsc s2; // also to the s2's
   1 => s1.sync => s2.sync;
   Step PhaseDifference => s2;
   .25 => PhaseDifference.next; // but at 90 degree to s2's phase
   s1 => Gain output;
   s2 => output;
   4 => output.op; // calculate output from s1/s2
}