Using AVAudioEngine to schedule sounds for low-latency metronome

后端 未结 3 2059
我寻月下人不归
我寻月下人不归 2021-02-05 19:49

I am creating a metronome as part of a larger app and I have a few very short wav files to use as the individual sounds. I would like to use AVAudioEngine because NSTimer has si

3条回答
  •  既然无缘
    2021-02-05 20:08

    I think that one of possible ways to have sounds played at with lowest possible time error is providing audio samples directly via callback. In iOS you could do this with AudioUnit.

    In this callback you could track sample count and know at what sample you are now. From sample counter you could go to time value (using sample rate) and use it for your high level tasks like metronome. If you see that it is time to play metronome sound then you just starting to copy audio samples from that sound to buffer.

    This is a theoretic part without any code, but you could find many examples of AudioUnit and callback technique.

提交回复
热议问题