The hello world of audio
This program produces a 440Hz sine tone, the Hello World of embedded interactive audio.
It’s not just a phase
A sine tone is a simple digital signal: It starts at 0 and on each audio frame we increases until we reach 1, then decreases down to -1, and finally returns to 0, over and over. The process of going from 0 to 1, down to -1, and back to 0 is called a period, and the length of this period - or the number of times that this travel from 0 to 1 to -1 and back to 0 happens - is the frequency. Frequency determines the pitch of the resulting sound.
Phase is a crucial part of generating digital signals, and refers to where we are in the process of going from 0 to 1 to -1 and back to 0.
render() function processes groups of audio frames called blocks. These blocks contain 16 frames by default, but may be larger or smaller.
Where we are in the process of travel is called the phase. Any time we generate a signal we have to remember the phase that we ended on, so we can pick up again at the right point.
First, we include our libraries and make some global variables that will help us
Producing your first bleep!
This sketch is the hello world of embedded interactive audio. Better known as bleep, it produces a sine tone.
The frequency of the sine tone is determined by a global variable,
The sine tone is produced by incrementing the phase of a sin function
on every audio frame.
In render() you’ll see a nested for loop structure. You’ll see this in all Bela projects. The first for loop cycles through ‘audioFrames’, the second through ‘audioChannels’ (in this case left 0 and right 1). It is good to familiarise yourself with this structure as it’s fundamental to producing sound with the system. */