0

How can I accurately time "click" intervals in Swift/iOS? My online search suggests it's not as trivial as I'd anticipated.

Using iOS 13 and Swift 5, I have an array of Doubles representing time intervals in seconds. I want to generate a series of sounds (clicks?) separated by each of these intervals in sequence.

I found a couple of relatively old threads about metronomes, etc.:

that suggest that using timers isn't that accurate. These threads are a decade old and often use a repeated interval versus reading from an array.

Where should I be looking? Timer? Date? DispatchQueue.main.asyncAfter??

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
  • Merely repeats the earlier question(s). The answers remain the same, and asking again adds nothing to the mix. https://stackoverflow.com/a/4496345/341994 is an especially good summary of what you'd need to know. Even if you have an accurate _timer_ (for which CADisplayLink is going to be the best bet for short intervals), actually _emitting_ the sound without latency is a tricky business; you need to get really low-level, and that answer talks about that. The only "newer" technology to consider is AVAudioEngine, I suppose (eg construct a buffer and loop it); see 2nd link above. – matt Feb 14 '20 at 16:37
  • Apologies, but thanks for your answer. It appeared beyond my skill level to judge by answers I had found and I wanted to check if anything significant had changed in the many years since - feels like there should be a simple, high-level solution to producing well timed sounds. Apparently not - an unsatisfying end to my first app. Will explore AVAudioEngine and/or divert to a different project. – John Sinclair Feb 14 '20 at 21:04

0 Answers0