为了在 iPhone 上保持一致的节奏,还有比系统声音更好的解决方案吗?

发布于 2024-08-08 20:38:29 字数 375 浏览 10 评论 0原文

我开发节拍器应用程序已经有一段时间了。在 Apple 的示例 Metronome 应用程序之后,我一直在(高优先级)后台线程上使用计时器来播放系统声音。我的结果还不错,但远非完美。我面临的一些问题是:

  • 该应用程序并没有真正保持时间,尽管听起来好像确实如此,
  • 当声音线程运行时,我无法在主线程上做太多事情,因为它会变得非常缓慢
  • 如果我按下锁定按钮或设备上的音量按钮,节奏变得混乱。
  • 手机静音时系统声音不播放

我昨天在应用商店购买了一个节拍器,发现这个应用程序没有上述任何问题。它没有使用系统声音,因为将 iPhone 静音并不会停止播放。

现在,我想知道是否有人可以指导我为这项任务找到一个更好、更强大的框架?

I've been working on a metronome app for quite some time now. Following Apple'e sample Metronome application, I've been using a timer on a (high priority) background thread to play system sounds. My results are okay but far from perfect. Some issues that I face are:

  • the app doesn't really keep time, although it sounds like it does
  • I can't do much on the main thread while the sound thread is running as it gets really sluggish
  • If I press the lock button or volume buttons on the device, the tempo goes haywire.
  • system sounds don't play when the phone is silent

I purchased a metronome on the app store yesterday and found that this app didn't have any of the above issues. It wasn't using system sounds as muting the iPhone didn't stop playback.

Now, I'm wondering if anyone can guide me towards a better, more robust framework for this task?

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

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

发布评论

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

评论(3

作妖 2024-08-15 20:38:29

OSX 音频库称为“Core Audio”。有几种不同的方式与音频硬件和核心音频框架进行交互。 OpenAL(如另一条评论中提到的)是一种跨平台的音频标准方法,就像 OpenGL 用于图形一样。还有音频单元,它是一个基于回调的接口,直接连接到音频硬件,允许您实时提供原始 PCM 音频。音频单元的时间极其有限,因此如果您正在寻找节拍节奏,音频单元可以为您做到这一点。音频单元之上还有一个称为 AudioQueue 的层,它允许您安排实时播放的音频流。 AudioQueue 的好处之一是它可以自动解码 MP3 或 AAC 等压缩格式。

在文档中搜索“核心音频概述”,了解有关 iPhone 的各种音频框架的更多信息。

The OSX audio libraries are referred to as "Core Audio". There are a few different ways of interacting with the audio hardware and the Core Audio frameworks. There's OpenAL (as mentioned in another comment) which is a cross-platform standard approach to audio much like OpenGL is for graphics. There is also Audio Unit which is a callback-based interface directly to the audio hardware which allows you to supply raw PCM audio in real-time. Audio Units are extremely time-constrained, so if you're looking for metronomic rhythm, Audio Units can do that for you. There's also a layer on top of Audio Units known as AudioQueue which allows you to schedule a stream of audio for play in real-time. One of the benefits of AudioQueue is that it can automatically decode compressed formats such as MP3 or AAC.

Search on "Core Audio Overview" in the docs to learn more about the various audio frameworks for iPhone.

ペ泪落弦音 2024-08-15 20:38:29

您可以使用 OpenAL 来处理声音。它使用低级 API 并且运行速度快。您还应该阅读 Apple 的 AudioSessionProgrammingGuide。在那里您会找到有关您可能提出的问题的许多答案。

You can use OpenAL to work with sound. It uses low-level API and works fast. Also you should read Apple's AudioSessionProgrammingGuide. There you will find many answers on your possible questions.

你是我的挚爱i 2024-08-15 20:38:29

我要在这里点燃火焰,所以如果你不喜欢这个评论,那就继续吧。但你真的看过苹果给你提供的文档吗?

文档“音频入门”页面列出了多种播放音频的方法,其中一种明确指出“以最低的 I/O 延迟播放声音,或提供同步音频输入和输出,...”(我可能违反了一些规定)无论如何,这里有保密协议)

在您在这里提问之前至少先阅读文档

I am going to start a flame here, so if you don't like this comment have at it. But did you actually look at the documentation that apple provides for you?

The documentation the "Getting Started with Audio" page lists multiple ways to play audio, one explicitely states "To play sounds with lowest I/O latency, or to provide simultaneous audio input and output, ..." (I am probably violating some NDA here whatever)

At least peak at the docs before you ask a question here

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