Modifying Basic Patches

by Adam Tindale

We have a basic patch running in ChucK but it still doesn’t sound very good. In this chapter we will cover some simple ways to rectify that problem. ChucK allows one to quickly make modifications to patches that can drastically change the sound.

First what we can do is change the type of our oscillator. There are many different oscillators available to use: SinOsc (sine wave), SawOsc (sawtooth), SqrOsc (square wave) and PulseOsc (pulse wave). We can simply change the type of oscillator just like below.

SawOsc s => dac;

Try changing the oscillator to all of the different types and a get a feel for how they sound. When changing the different Ugens always be sure to check the rest of your patches so that the parameter calls are valid. If you were to use the .width method of PulseOsc and others on a SinOsc ChucK will complain. You can comment out lines that are temporarily broken by using double slashes (//).

Now let’s add some effects to our patch. ChucK has many different standard effects that can be added to Ugen chains. The simplest effect we can add is an amplifier. In ChucK, this object is Gain.

SawOsc s => Gain g => dac;

Now we can change the parameters of our effect. Gain has a parameter .gain that can be used to change the gain of signals passing through the object. Let’s go about changing the gain.

.5 => g.gain;

This is redundant. All Ugens have the ability to change their gain in a similar manner. (See the UGEN section in Reference for more information about UGEN parameters.)

.5 => s.gain;

However, this is useful when we have multiple Ugens connect to one place. If we were to connect 2 oscillators to the dac then we will get distortion. By default, these oscillators oscillate between -1 and 1. When they are connected to the same input they are added, so now they go between -2 and 2. This will clip our output. What to do? Gain to the rescue!

SinOsc s1 => Gain g => dac; 
SinOsc s2 => g; 
.5 => g.gain;

Now our oscillators are scaled between -1 and 1 and everything is right in the world.

More effects were promised, now you will see some in action. Again, one of the wonders of ChucK is how easy it is to change Ugens. We can take the above patch and change ‘Gain’ for ‘PRCRev’.

SinOsc s1 => PRCRev g => dac; 
SinOsc s2 => g; 
.5 => g.gain; 

The Gain Ugen has been replaced by a reverb and the output is scaled by using the ‘.gain’ parameter that all Ugens posess. Now we can add a few spices to the recipe. ‘PRCRev’ has a ‘.mix’ parameter that can be changed between 0. and 1. If we wanted to have this parameter set to the same value as what we are ChucKing to g.gain we can chain it along. After assignment a Ugen will return the value that was ChucKed to it. We can use this method to propogate paramters to our oscillators.

.5 => g.gain => g.mix; 
500 => s1.freq => s2.freq;

Another technique for setting parameters is to read a parameter, then modify it and then ChucK it back to itself. Accessing parameters requires the addition of brackets () after the name of the parameter. Here is an example of doubling the frequency of an oscillator.

s1.freq() * 2 => s1.freq;

Let’s change the type of oscillators for some more fun. We can simply replace ‘SinOsc’ with any other type of oscillator. Check the Ugen section in the reference for ideas. Try changing the frequency of the oscillators and the mix parameter of the reverb for each type of oscillator you try. Endless fun!