Accurate timing in iOS

后端 未结 7 1365
生来不讨喜
生来不讨喜 2020-12-01 02:32

I am looking at the \'Metronome\' sample code from the iOS SDK (http://developer.apple.com/library/ios/#samplecode/Metronome/Introduction/Intro.html). I am running the metro

7条回答
  •  一整个雨季
    2020-12-01 03:00

    Using a while loop and sleep to time a metronome is not a robust way to solve this problem as it is likely to produce timing that is jittery and that drifts, as you have seen. I believe the standard way to solve this problem is to use Core Audio (in one way or another) to feed a continuous audio stream containing your metronome ticks separated by the correct amount of silence between them, depending on the tempo. Because you know the exact sample rate, you can time your ticks very accurately. Unfortunately, generating the audio yourself is quite a bit more difficult than what you're attempting to do, but this Stackoverflow question might get you started.

提交回复
热议问题