Consider an imaginary touch-based slider control for use in an audio app: you drag your finger up and down the control (let’s imagine it’s a vertical slider) and some aspect of the sound changes in direct response to the movements of your finger.
But if you lift your finger and touch down again some distance from your previous touch – that is, you cause the control to make a jump in values – the control’s display gently but swiftly animates to that new value… and so does the audio!
So how would you do something like that?
With Core Animation of course!
CAReplicatorLayer is one of the more interesting toys in the Core Animation toolbox: feed it one or more sublayers (an image, a rendered shape, whatever) and it will copy – replicate – those sublayers and then do stuff with the copies in time and space.
I happen to think replicator layers are particularly well suited to audio-related interfaces because their visual properties in many ways parallel the cylical nature of music and sound.
There’s one thing, however, that CAReplicatorLayer can’t do, and that’s: provide you with direct access to the copies it creates. If that’s something your app requires, you’re going to have to roll your own version.
In our last post, we looked at how to access iPod Library tracks and stream them from disk in real time, using Apple’s Extended Audio File Services and Audio Unit APIs. We also speculated about the possibility of modifying our code to allow for reverse playback of those streams – you know, so you can hear what stuff sounds like when you play it backwards. Let’s look at how we might go about that now.
There are two questions that often arise for iOS developers new to Apple’s audio frameworks: (1) How do I play tracks from the iPod Library using the low level Core Audio APIs (as opposed to using an AVAudioPlayer or MPMediaPlayer) and (2) How do I play those tracks without first loading them into memory?
Apple, of course, already provides us with a number of options for accessing and playing iPod Library files. And loading those files into memory before playing them is certainly the easy way to go.
But: sometimes it’s not enough.
Of the many changes introduced with Xcode 4, one of the least talked about is its new template format. But while most of the existing 3.x templates were converted to the new format, somewhere during the rollout of OS X 10.7 (“Lion”) the Audio Unit templates got yanked. Fortunately, reverse-engineering the new format from existing templates isn’t all that difficult. And: once you have a grip on how the new format works, it’s a pretty straight shot to restoring the AU templates, updating them to compile with Lion and Mountain Lion, and maybe even making a few tweaky improvements while you’re at it.
Last time around we got our feet wet with SuperColliderAU, working our way through some example code and building a simple Audio Unit plug-in from scratch. This time we’re going to attempt something a little bit more ambitious: designing, prototyping and building a full blown tremolo audio effect plug-in. We won’t be taking the straight ‘do this then do that’ tutorial approach, however: our focus will be on process and tools as much as on actual building, and we’ll begin quite simply by imagining how to go about creating a tremolo effect. Then we’ll construct a suitable algorithm through trial and error, testing our ideas along the way using SuperCollider’s graph-plotting capabilities.
The combination of SuperColliderAU and AudioUnitBuilder is a wonderfully useful tool for quickly sketching out and prototyping working audio effect plug-ins. In this installment we’ll jump-start our SuperCollider setup by installing AudioUnitBuilder, tweaking it for Lion / Mountain Lion / SuperCollider 3.5 compatibility and taking a walk-through of one of the example AU projects. Then we’ll knuckle down and build our first custom plug-in.
Programming your own audio plug-ins, let’s face it, is not a casual undertaking. To even begin playing the game you need a solid grounding in DSP – along with some serious C, C++ and math chops – all tucked neatly into your belt. And that’s before you start diving into the frameworks of whichever platform it is you’re developing for. Wouldn’t it be neat if there was a kinder, gentler way into this world of streaming ones and zeros, even for reluctant programmers? Well there is, at least for Mac users.