play two sounds simultaneously iphone sdk

play two sounds simultaneously iphone sdk

酷到爆炸 发布于 2021-11-28 字数 345 浏览 706 回复 2 原文

I am trying to make a small music app on the iphone. I want to have an octave a piano which will respond to touches and play the key or keys that the user touches. How would i be able to get two or more sounds to play at the same time so it sounds like a chord? I tried using AVFoundation but the two sounds just play one after the other.

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

給妳壹絲溫柔 2022-06-07 2 楼

If you create multiple AVAudioPlayers you can play them at the same time, and they will mix per the restrictions outlined in the documentation (not all file types can be played simultaneously).

If you allocate them first, then play them in order, they will play at virtually the same time.

If you need absolutely perfect timing, use the AudioQueue as described above or use OpenAL.

夏夜暖风 2022-06-07 1 楼

You would have to use AudioQueueServices. The docs are here:

Apple.com - AudioQueueServices Reference

Essentially you would have to write some code to open up multiple outputs, and then prime the queue and have them block before AudioQueueStart(AudioQueueRef aq) until everything was primed and ready and then let them go.

AVAudioPlayer isn't really good enough for this sort of thing, unfortunately.