UIKit 更改按钮状态会中断音频
我有一个 iPhone 应用程序,它使用 140 个 UIButton(PNG 图像),每个按钮都会触发合成的正弦音(最多 10 个音调)。正弦音调是使用高度优化的 C 代码(使用 AudioToolbox API)生成的。 10 个正弦音消耗约 50% CPU(44100hz)。
我有预设可以关闭 10 种音调,并打开 10 种新的不同音调。这也会导致 UIButtons 的状态从“选定”更改为“正常”。
我的问题是,当 10 个(共 140 个)UIButton 更改状态(全部同时)时,它会导致音频出现故障(即使音频仅占用 50% 的 cpu)。那么,由于更改而导致 CPU 出现大幅峰值,
有什么办法可以处理这个问题吗?我可以优先考虑 AudioQueue 而不是 GUI 吗?是因为我有 140 个 PNG 图片作为按钮吗?是否可以创建非按钮的多点触控区域?我只是在寻找任何建议来减少 GUI 对音频处理的影响。
I've got an iPhone app that uses 140 UIButtons (PNG images), each triggering synthesised Sine tones (maximum of 10 tones). The Sine tones are generated using highly optimised C code (using AudioToolbox API). 10 Sine tones chews about 50% CPU (at 44100hz).
I have presets that turn off 10 tones, and turn on 10 new different tones. This also causes the UIButtons to change state from Selected to Normal.
My problem is that when 10 (out of 140) UIButtons change state (all at the same time) it causes a glitch in the audio (even though the audio only chews 50% cpu). So there is a big spike in CPU caused by changing
Is there a way I can handle this? Can I prioritise AudioQueue over the GUI? Is it because I have 140 PNG images as buttons? Is it possible to create multi-touch zones that are not buttons? I'm just looking for any advice to reduce the GUI's impact on audio processing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果正在开发音频合成应用程序,则 Apple 的建议是使用 AudioUnit API 而不是 AudioToolbox 层。 Apple 表示使用 AudioUnit API 的原因之一是:
默认情况下,其线程具有非常高的优先级。 AudioToolbox 线程的优先级较低。最好迁移到使用 AudioUnit API,而不是强制 AudioToolbox 的线程优先级。
If one is developing audio synthesis applications, then the recommendation from Apple is to use the AudioUnit API instead of the AudioToolbox layer. Apple says one of the reasons to use the AudioUnit API is for:
Its threads have very high priority by default. The AudioToolbox threads have a low priority. Would be better to migrate to using the AudioUnit API rather than forcing thread priorities for the AudioToolbox.
您必须在单独的线程中执行音频播放。您可以使用 setThreadPriority:。
You have to perform audio playback in a separate thread. You can set priority for the newly created thread using setThreadPriority:.