Skip to content

Latest commit

 

History

History
64 lines (38 loc) · 4.47 KB

03-make-a-sound.org

File metadata and controls

64 lines (38 loc) · 4.47 KB

Make a Sound

First Sound

Once your Lisp and cl-collider environment is set up and loaded and the server booted, you can create sound! Here is the fastest way to make a sound with cl-collider:

(proxy :foo (sin-osc.ar 440 0 0.2))

When you evaluate this line, you should hear a sine wave from your left speaker.

The proxy function basically starts a synthesis process on the server for you. In order to refer back to the synth process, we give it a name: :foo. The next argument is the “body” of the proxy. This defines the sound that the proxy generates.

In order to define a sound we use unit generators, or “UGens” for short. A unit generator is the most basic building block of sound available to us in cl-collider. Each UGen is specialized to generate or affect sound in a particular way. In this case, sin-osc.ar means a sine wave oscillator (sin-osc) at audio rate (.ar). The arguments to the sin-osc are, in order: frequency (in cycles per second), phase, and an amount to multiply the sin-osc’s output by (commonly referred to as “mul”). In this case, we provide 0.2 to reduce the volume of the sin-osc from its default of 1. In addition, sin-osc.ar accepts another argument after mul, which is “add”–a number to add to the sin-osc’s output. It defaults to 0.

Change the Sound

If we want to change the sound being generated, we can simply edit the body of the proxy. For example, if we want to lower the frequency of the sin-osc, we can change the proxy to the following:

(proxy :foo (sin-osc.ar 300 0 0.2))

Evaluating the new snippet should result in the sound output being replaced with another sine wave of a lower pitch.

If you want to stop the sound, use nil for the body parameter:

(proxy :foo nil)

To restart the sound, just add the body back into the proxy and re-evaluate.

Aside from sin-osc, SuperCollider provides many other kinds of unit generators. For example, here’s a saw wave:

(proxy :foo (saw.ar 300 0.2))

The saw UGen doesn’t have a phase argument, so this time we only have to provide two: 300 for the frequency, and 0.2 for mul.

UGens Controlling UGens

It’s also possible to control the parameters of one UGen with another:

(proxy :foo (saw.ar (sin-osc.kr 0.5 0 150 300) 0.2))

In this case, instead of providing a number for the saw’s frequency, we supply a sin-osc. The sin-osc is set to have a frequency of 0.5. The mul is set to 150, which multiplies the sine wave’s output by 150. Then, since the add argument is 300, 300 is added. Since the default range of sin-osc is from -1 to 1, multiplying it by 150 changes its range to -150 to 150. Then adding 300 produces the final range of 150 to 450; thus the saw’s frequency is being modulated from 150 to 450.

If we want to actually start having fun, we can give ourselves more immediate control over the UGen by using the mouse-y UGen for one of its parameters:

(proxy :foo (saw.ar (mouse-y.kr 20 10000 :exponential) 0.2))

After evaluating this code, try moving your mouse up and down. You should hear that the pitch of the saw wave increases as you go up, and decreases as you go down. The parameters of mouse-y are the bottom of the range (20), the top of the range (10000), and the “warp” (:exponential). The first two should be self-explanatory: when the mouse is at the bottom of the screen, the mouse-y UGen outputs 20. When the mouse is at the top, mouse-y outputs 10000. The warp parameter specifies the slope of the range from the bottom to the top. Here we use :exponential because the human brain perceives pitch exponentially. If you want, you can change the warp to :linear instead, which is the default.

By now you may have noticed that some of the UGens we’ve been using have had .kr instead of .ar. As mentioned before, ar specifies to run the UGen at audio rate. kr, on the other hand, is for control rate, which means that the server processes that UGen less often, and thus uses less CPU power on them. Generally you would want to use .kr when the signal that the UGen is processing or generating isn’t going to be heard directly, and doesn’t exceed frequencies around 30Hz.

Note that not all UGens are available in both control- and audio-rate versions. mouse-x and mouse-y, for example, only provide control rate output. So mouse-x.ar is invalid and would give you an error.