Subject: Re: How does one update a view position during a core audio render callback?
To: "Patrick J. Collins" <
The simplest way to do is to just set a variable to your current time in your render callback. And then employ a repeating timer to check that value and update your view on the main thread.
@implementation MyObject{
float currentTime;
}
OSStatus myRenderCallback{
MyObject *object = (MyObject *)inRefCon;
object->currentTime = CalculateTimeOnRenderThread(); //with no Obj-C messaging!
}
-(void)myTimerCallback{
self.playhead.position = currentTime;
}
If you want it to refresh the currentTime faster than the render callback you should get the mach_absolute_time() at the start of playing and again in your timer and calculate the difference.
@implementation MyObject{
UInt64 startMachTime;
}
// if you need accuracy get the mHostTime from your render callback
// otherwise do this
-(void)startAudio{
startMachTime = mach_absolute_time();
}
-(void)myTimerCallback{
UInt64 ticksSinceStart = mach_absolute_time() - startMachTime;
self.playhead.position = convertTicksToSeconds(ticksSinceStart);
}
A CADisplyLink is an excellent timer for this