Old question, but it raises interesting points, so I'll give my 2 cents.
As stated by the documentation,
A CADisplayLink object is a timer object that allows your application to synchronize its drawing to the refresh rate of the display.
Thus you won't be able to get updates more frequent than 60 times per second, the LCD screen display rate. Animations do not have a refresh rate per se, they represent a continuous movement that just happens to be visible every time the screen updates.
I do not have much experience on sound playback, but I'm surprised that the CADisplayLink
refresh rate is not enough. Does 1/60 of a second really make a difference to the user's ear ?
Maybe the method you are using for sound playback induces some kind of lag ?
Anyway, if you want to sync sound more finely with your animations, I would suggest setting up an NSTimer
with a repeat interval that suits you, instead of a CADisplayLink
.
The other things you are gonna need are :
- the
CACurrentMediaTime()
function, which returns the time used by Core Animation at the time it is called
- the
CAAnimation
's beginTime
property (which it gets from the CAMediaTiming
protocol)
Setting beginTime
as an offset from CACurrentMediaTime
will allow you to create animations that start at a very precise and controlled time. If you leave it to 0 (the default) when you add an animation to a layer, it will be automatically set to the CACurrentMediaTime
at the end of the runloop, resulting in less controlled timing.
You can also read beginTime
from a running CAAnimation
to know the exact time at which it started, which may not be the exact time you added it the the layer (see above).