如何播放声音以创建弹奏效果?

发布于 2024-12-17 20:02:31 字数 245 浏览 1 评论 0原文

我想实现一把简单的吉他。如您所知,吉他有六根弦,当您拨动其中一根弦时,就会发出相应的声音。为了解决这个问题,我在 viewDidLoad 中初始化了六个 avaudioplayers 并使用了一个 mp3 文件。在 touchesMoved 中,我检查哪个字符串被触摸,然后播放相应的声音。但当我将手指从第二弦快速移动到第六弦时,结果不太好。仅播放第一个声音(即第二根弦)。有人可以分享任何想法吗?

I want to implement a simple guitar. As you know, a guitar has six strings and when you pluck one of them, the corresponding sound will play. To address the problem, I initialized six avaudioplayers in viewDidLoad and used an mp3 file. In touchesMoved, I check which string is touched and then play the corresponding sound. But the result is not so good when I move my finger from the second string to the sixth string quickly. Only the first 1st sound plays (i.e. the second string). Can anyone share any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(1

还不是爱你 2024-12-24 20:02:31
  • 1 - 不要使用 MP3 压缩声音,而使用纯 PCM。

iOS 在硬件加速播放中仅同时处理一种 MP4/MP3 声音 - 另外一种声音将使用软件解码器播放。

  • 2 - 使用 OpenAL 播放声音。

OpenAL 易于使用,文档齐全,并且在 iOS 上可以同时处理 (AFAIK) 32 个语音,没有更大的缺点。

  • 1 - Do not use MP3 compressed sounds but plain PCM.

iOS handles only one MP4/MP3 sound concurrently in hardware accelerated playback - additional one would be played using a software decoder.

  • 2 - Use OpenAL for playing the sounds.

OpenAL is easy to use, well documented and on iOS handles (AFAIK) 32 voices concurrently without bigger drawbacks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文