Menu

Sound Synthesis with LÖVE Part II – Sine Waves

In the first Part we discussed some basics of LPCM and sound synthesis. This time we want get more practical and generate a sine wave tone.

Beep

Since we use LÖVE for this we want to write all the following code in the love.load() callback so it only get’s executed once.

First we initialize set up some variables in the love.load() callback:

function love.load()
len =2
rate =44100
bits =16
channel =1end

We need this in order to set up the soundData object. The length of the sound we are about to generate is specified by the len variable in seconds. 44100 Hertz and 16 bit is a common format of LPCM Data. For the sake of this tutorial we will use one channel, meaning that our sound will be mono.

Next we set up a soundData object with these settings and write a loop to fill in the samples. At last we generate a Source object and play it. The love.load() will then look like this:

The advantage of this method is that we can generate as many oscillators as we want – which may also be useful for modulating the signal later on. We also don’t have to bother about managing the oscillating variables. Using this in our love.load() from above: