Sound Basics

Starting Up

To start sound in SuperCollider, you need to boot the audio server from sclang. This starts up the server and establishes a network connection between sclang and the server. The quickest way to start the server is using s.boot. By default, sound will be outputted through your default settings.

Creating A Sine Wave

A sine wave intended as audio can be created by using the class SinOsc.ar. SinOsc.ar can take several arguments.

The documentation for SinOsc can be found here. If the intent is to playback the sine wave as audio, one should always use the class method .ar. When we use sine waves to modulate other waves in later classes, it can be more efficient to use .kr.

To actually play the sine wave, we wrap the wave in a function and use the .play method.

To stop the sound, run the command below. Equivalently, if you are in the SuperCollider IDE, hit CMD+PERIOD if on a Mac or Ctrl+PERIOD on a PC.

Stereo Sine Wave

If you noticed, the above code only plays out of the left speaker. If we want to hear audio out of both speakers, we need to create an array of sine waves. Python users will recognize the array notation in SuperCollider as similar to the list notation of Python.

Below is an array of two sine waves so we can here audio out of both speakers.

SuperCollider offers a shorthand to create arrays for stereo sound called multichannel expansion. If you pass an array into the input, the signal will be converted into an array of audio signals that can be played out of different speakers.

Play a sine wave of frequency 430Hz out of the left speaker and 440 out of the right speaker.

Pitch vs. Rhythm

As an experiment, run the code below with different frequencies. The frequency range of human hearing is from approximately 20-20000Hz. A pulse wave is simply a blip of sound at regular intervals.

Execute the cell below to sweep through the audible frequency range of human hearing. This function uses a new UGen called XLine. In this example, XLine ramps from 10 to 20000 exponentially over the course of 6 seconds. The XLine is passed to the frequency argument of Pulse to modulated the frequency of the pulse wave.

Exercise: printHarmonics

Below write a function called ~printHarmonics that accepts two arguments: a fundamental frequency called fundFreq and a number of harmonics called numHarmonics. ~printHarmonics should print out numHarmonics from the harmonic series of the given fundamental fundFreq. Assume that the fundamental frequency has a default value of 40 and numHarmonics has a default value of 20.

Play the Harmonic Series

The below code plays 20 harmonics from the harmonic series of the fundamental fundFreq. Listen to how the "distance" of the notes gets shorter and shorter.

Experiment 1: All Partials with Same Amplitude

Listen carefully and think about whether you hear the sound as one single unit or twenty distinct harmonics.

Aside: the ! operator

As a side note, the ! operator in sclang takes a value on the left and duplicates it by the number of times of the integer on the right, storing those values in an array.

Therefore, writing SinOsc.ar(harmFreq ! 2, 0, 0.04) is equivalent to SinOsc.ar([harmFreq, harmFreq], 0, 0.04). Recall that an array inside a UGen like SinOsc will be expanded through multichannel expansion to an array of two sine waves, allowing us to hear the waves out of both the left and right speakers.

Experiment 2: All Partials have progressively smaller amplitudes

Listen carefully and think about whether you hear the sound as one single unit or twenty distinct harmonics. How did reducing the amplitude of the harmonics change the perception of the sound?

Experiment 3: Accentuate Two Partials

The previous two experiments showed that our brains attempt to fuse harmonics from the harmonic series into a single sound with the fundamental as the pitch we perceive. Let's try and "break" our perception by strongly accentuating two partials to see if we can hear them as distinct sounds. Here we will make the amplitude of the two partials much larger than the rest. Play around with the numbers and see what you can determine.

Experiment 4: Missing Fundamental

This experiment is exactly the same as experiment 2 except now the fundamental is not included. Do we still perceive the fundamental as the pitch of the note or not? Compare to experiment 2. What sounds the same? What sounds different?

Phase of a Sine Wave

Below are two sine waves that are out of phase by $\pi/2$. Do we perceive a difference between each sine wave?

In-Phase Sine Waves

Compare the volume of two sine waves in phase vs. a single sine wave. Which sounds louder?

Out-of-phase Sine Waves

Compare the volume of two sine waves perfectly out of phase vs. a single sine wave. Which sounds louder?

Octave Equation

Below is a snippet of code to play some frequency and a frequence numOctaves above it. Change the value of freq or numOctaves to hear the differences.