I am using CADisplayLink to perform synchronization between sound and animations. The synchronization needs to be really precise and currently running CADisplayLink at frameInterval of 1 does not call the selector often enough.
Is there a way to increase it's granularity? (frameInterval is an integer property so I obviously cannot go below 1)
Old question, but it raises interesting points, so I'll give my 2 cents.
As stated by the documentation,
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
CADisplayLinkrefresh 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
NSTimerwith a repeat interval that suits you, instead of aCADisplayLink.The other things you are gonna need are :
CACurrentMediaTime()function, which returns the time used by Core Animation at the time it is calledCAAnimation'sbeginTimeproperty (which it gets from theCAMediaTimingprotocol)Setting
beginTimeas an offset fromCACurrentMediaTimewill 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 theCACurrentMediaTimeat the end of the runloop, resulting in less controlled timing.You can also read
beginTimefrom a runningCAAnimationto know the exact time at which it started, which may not be the exact time you added it the the layer (see above).