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.