In my last post I wrote some code to find all the files containing the Audio library classes comprising the public API, while ignoring all of the additional files in the package. Now I'd like to take you on a brief overview of what all the Audio library contains at a high level. It is important to note that while the Audio System Design Tool provided by the Audio library author is for these built-in classes, you are free to write your own classes as well. These built-ins do contain a lot of great stuff, though, that makes it easy to get started making audio effects.
The header files in the Audio library are divided into the following categories:
- analyze - analysis of audio signals such as spectrum analysis and note tuning
- control - configuration of external audio codec chips such as the SGTL5000
- effect - audio processing effects such as chorus and delay
- filter - various audio filtering algorithms
- input - audio input sources such as I2S and analog ADC
- mixer - there is just one mixer header file, it mixes multiple channels of audio
- output - audio output sinks such as I2S and analog DAC
- play - sample playback such as from memory or from an SD card
- synth - audio synthesis such as sine waves or string physics modeling
There is a lot here, and not all of it is used in examples. Code which is not used in examples (and some code which IS used in examples) is not guaranteed to work, particular in the port of the Audio library from the Teensy to the M4 processor. Therefore, I feel it is prudent to start with only providing the most essential parts of the library. If I miss anything important, I'm sure that people will complain on github and I can add the missing pieces later. Narrowing down the scope of the project helps ensure that we get somewhere useful quickly.
For analysis, I have found FFT1024 to be the most useful. This is a fast fourier transform (FFT) analysis of the spectrum of an audio signal into 1024 different "bins". For control, there are a bunch of audio codecs here, but the project we are working on uses the SGTL5000, so that is the only one that is useful. For effects, they all seem great. However, I have personally never managed to get the envelope effect to work. We could spend a lot of time on these, so just to get started I think that the chorus is the simplest effect to pick because it is easy to tell if it's working. For filters, of course we have to go with the classic ladder filter, so cool. As far as inputs and outputs, I have only ever seen the I2S and analog inputs and outputs used in examples. The I2S stuff was broken on the M4 port and we spent a lot of time fixing it, so I really only care about I2S input and output at this point. For play, memory playback is the easiest, so we'll go with that.
For synth, I obviously you're going to want all or most of it. I have had the best luck getting the string modeling to work, but it doesn't sound good for bass notes. I have been trying to make a sine wave bass, but you really need a working envelope effect for that. So I think the best plan is to throw musicality aside for now and start with the good old tone sweep effect because I know it works. It is limited in use musically, but it's easy to tell if you have it working, and that's the most important thing at this stage.
So that's the plan, to get just one thing from each category working. Since most things in a category bear some similarity to each other, it will be easier to add more items from a category than to add a new category.
In terms of order of implementation, this most important bits are output and control. The Audio library requires you to have an output in the signal processing chain, or else nothing happens. The control lets you turn on the audio codec chip, which is necessary to get the output to work. So the minimal viable example would have a control, an output, and some sort of sound source: input, play, or synth. Analysis, effect, filter, and mixer are all optional add-ons. You might be wondering, what if I just want to analyze an input signal, do I still need an output? My understanding is that you do, that's just how the Audio library is constructed.
Each of these categories deserves its own in-depth examination, but the first step is to get the components working. For me, the simplest demo is a synth tonesweep to an I2S output, and of course you need the SGTL5000 control to turn on audio output. In our next post, we'll take a look at some tonesweep demo code and write some Swift code to parser header files to extract information about the available API.