Learn creative coding writing simple programs

132. Change volume and pitch with SinOsc.kr

Classes that generate sound in SuperCollider (like SinOsc) often have .ar (audio rate) and .kr (control rate) methods. The .ar method uses more cpu power and it is used for generating sound. The .kr method uses less cpu power and is used to control properties of other oscillators.
For humans, hearing is normally limited to frequencies between about 20 Hz and 20,000 Hz. In recent episodes we have listened to frequencies between 60 and 600 Hz, inside the audible range. That's why we used .ar.
In this episode we want properties to change slowly, up to 1 time per second (or 1 Hz). That's below the audible range, so we use .kr instead.
In this episode we combine several sine oscillators. One at audio rate to generate sound, and several at control rate to control the pitch and the volume of the sound (making the volume and the pitch go up and down).

If it sounds confusing, don't worry, I will review all concepts again in the next episodes.

Tags: supercollider, control rate, kr, sinosc

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
  Do `float` and `int` smell similar?
To highlight code blocks, use ```processing and ``` like this:
  void setup() {
    size(600, 600);