Fundamental Waves

Boot the server to get started!

Additive Synthesis with Arrays

Using Arrays for Additive Synthesis

To construct a wave of multiple sine waves, we first need some knowledge about how addition of arrays work in SuperCollider. In Python, if we add two lists those lists are concatenated. For example, [1, 2] + [3, 4] produces a new list of [1, 2, 3, 4]. Observe though the behavior in sclang.

Notice how the elements of the two arrays are added together pointwise. We can use the same strategy to add sine waves together.

Here's a slightly more compact version of the same thing using multichannel expansion.

Aside: Be Careful using UGens outside the function definition

You might think the code below is reasonable. Functions have access to variables in their outer context but nevertheless this code will fail silently and we won't hear anything. This is a common mistake for first-time users of SuperCollider.

The solution to this problem is to simply define UGens like SinOsc within the scope of the function definition.

Full Confession: This is an issue that has long bothered me about the language and in my opinion is a design flaw. Suffice it to say, functions that are intended to be played have special requirements. We'll encounter other such quirks as we go. This is something to watch out for though.

Sawtooth Wave

Creating a Sawtooth Wave with Sine Waves

We can build a sine wave by summing sine waves. A true sawtooth wave is an infinite sum of sine waves. Because computers can only perform finite calculations, our sine wave below will be capped. Adding up around 25-30 sine waves should give us a good approximation.

Recall that we can mathematically write the expression for a sawtooth wave $g(t)$ as:

$$g(t) = \sum_{n=1}^{\infty}\frac{A}{n}\sin(2\pi fnt) $$

Note that the distinctive characteristic of the sine wave is that the amplitude of each successive sine wave is $1/n$ times smaller than the fundamental where $n$ is the harmonic number of the sine wave.

In SuperCollider, you need not build up your own sawtooth wave using the additive synthesis technique above. SuperCollider comes with two UGens to produce sine waves: LFSaw and Saw. LFSaw is a pure sawtooth wave in that contains every partial. It has a perfectly straight ramp. Because it contains all partials we say that the oscillator is non-bandlimited. LFSaw contains a finite number of partials and is similar to the additive synthesis sawtooth we made above. Because it contains only a finite number of partials we say that the oscillator is bandlimited. There are good reasons why you might want to use one over the other. But we need to save that discussion until we discuss aliasing.

Triangle Wave

A triangle wave also sums harmonics from the harmonic series. It has several distinct characteristics:

The equation for a triangle wave $g(t)$ can be written as follows where $n = 2i - 1$:

$$g(t) = \sum_{i = 1}^{\infty}(-1)^i\frac{A}{n^2}\sin(2\pi fnt)$$

Note that this equation accomplishes the phase shift by making use of the fact that $-\sin(x) = \sin(x + \pi)$.

SuperCollider comes with a UGen for a triangle wave called LFTri. Like LFSaw, LFTri is non-bandlimited. It is a pure triangle wave with all partials and has a perfectly smooth ramp up and down.

Square Wave

A square wave has the following properties:

The equation for a square wave $g(t)$ can be written as follows where $n = 2i - 1$:

$$g(t) = \sum_{i = 1}^{\infty}\frac{A}{n}\sin(2\pi nft)$$

SuperCollider has bandlimited and non-bandlimited UGens for creating square waves. See the discussion of Pulse Waves below for examples.

Pulse Wave

A square wave is a special instance of a pulse wave (also called a rectangle wave). There is not a succinct set of criteria to describe the pulse wave as there are for the other waves because the scaling of each harmonic is more complicated.

Like the other waves, the pulse wave is also created from a sum of harmonic sinusoids.

$$g(t)=dA + \sum _{n=1}^{\infty }\frac {2A}{\pi n}\sin(\pi dn)\cos(2\pi fnt)$$

Notice that the sine is not a function of time. It serves as a scaling factor for the amplitude of a series of cosine waves. The $d$ in this equation is called the duty cycle. The duty cycle is the percentage of the period where the pulse wave is high. Therefore, a duty cycle of 0.5 is equivalent to a square wave.

SuperCollider has a bandlimited pulse wave called Pulse and a non-bandlimited pulse wave called LFPulse. We can use these two UGens to create any pulse wave including a square wave.

Play With A Keyboard

Below you can hook up a MIDI keyboard and try and play some of these waves. You can change the wave type by adjusting the UGen set to sig in the code below. We'll talk more about how this code works at a later date.