What is the best way to play sound quickly upon fast button presses Xcode?(在快速按下 Xcode 按钮时快速播放声音的最佳方法是什么?)
问题描述
我有一个音板它只是一个带有大约 8 个按钮的屏幕.每个单独的按钮都有自己的声音,在按钮按下时播放有几种方法可以播放声音,例如使用 SystemSound 或 AVAudioPlayer到目前为止,系统声音似乎具有最快的响应时间,avaudioplayer 很慢,如果用户真的快速点击按钮,它就跟不上,我为每个声音都创建了一个音频播放器,这很混乱.这就是我现在播放声音的方式.h 文件
I have a soundboard it's just a screen with about 8 buttons. each individual button will have its own sound which will be played upon button press There are a couple of ways I could play the sound, such as using SystemSound or AVAudioPlayer system sound so far seems have the quickest response times, avaudioplayer is quite slow, it cant keep up if the user taps on the buttons really fast, I created an audio player for each sound which was quite messy. this is how I'm playing the sounds at the moment the .h file
@interface MainScreenViewController : UIViewController <AVAudioPlayerDelegate, UITabBarControllerDelegate> {
AVAudioPlayer *player;
CFURLRef keNURL;
SystemSoundID keNObject;
//KE LOUD
CFURLRef keLURL;
SystemSoundID keLObject;
//GE NORMAL
CFURLRef geNURL;
SystemSoundID geNObject;
//GE LOUD
CFURLRef geLURL;
SystemSoundID geLObject;
//NA NORMAL
CFURLRef naNURL;
SystemSoundID naNObject;
//NA LOUD
CFURLRef naLURL;
SystemSoundID naLObject;
//RA
CFURLRef raURL;
SystemSoundID raObject;
//DAGGA CLICK
CFURLRef daCURL;
SystemSoundID daCObject;
//TILLI CLICK
CFURLRef tiCURL;
SystemSoundID tiCObject;
}
@property (nonatomic, retain) AVAudioPlayer *player;
@property (readwrite) CFURLRef keNURL;
@property (readonly) SystemSoundID keNObject;
@property (readwrite) CFURLRef keLURL;
@property (readonly) SystemSoundID keLObject;
@property (readwrite) CFURLRef geNURL;
@property (readonly) SystemSoundID geNObject;
@property (readwrite) CFURLRef geLURL;
@property (readonly) SystemSoundID geLObject;
@property (readwrite) CFURLRef naNURL;
@property (readonly) SystemSoundID naNObject;
@property (readwrite) CFURLRef naLURL;
@property (readonly) SystemSoundID naLObject;
@property (readwrite) CFURLRef raURL;
@property (readonly) SystemSoundID raObject;
@property (readwrite) CFURLRef daCURL;
@property (readonly) SystemSoundID daCObject;
@property (readwrite) CFURLRef tiCURL;
@property (readonly) SystemSoundID tiCObject;
}
然后播放个人声音的动作
then the actions that play the individual sounds
然后是.m文件,在导入.h文件和正确的框架工作并综合所有变量后,编写动作代码这就是个人行动中的内容.
then the .m file, after importing the .h file and the right frame works and synthesizing all the variables, write the code for the action and this is what's in the individual actions.
-(IBAction)geSound{
AudioServicesPlaySystemSound (self.geNObject);
}
我只是想知道 systemsound 是否是我创建音板的前进方向.尤其是当用户在节拍之间快速交替敲击板时..如果不是,播放响应非常好的声音的最佳方式是什么?
I just wanted to know if systemsound is the way forward for me to create a soundboard. thanks especially when the user will tap on the board really fast alternating between beats. . if not what is the best way to play the sound which responds really well?
推荐答案
22/03/2014 - 更新:摆脱我过于兴奋的帖子(很久以前写的)并更新以描绘更多适当的答案.
我必须对音频进行精细控制,因此选择使用 OpenAL.WOW是总结它的一种方式.我一开始自己使用 OpenAL,这需要一些额外的工作,实现所有必需的方法并设置所有内容;我发现自己几乎没有明显的延迟.我对出色的结果感到非常满意.
I had to achieve fine control over audio so opted to use OpenAL. WOW is one way to sum it up. As soon as I took it upon myself to use OpenAL which required a bit of extra leg work, getting all the required methods implemented and setting everything up; I found myself with practically no noticeable latency at all. I was absolutely pleased with the excellent results.
我能够实现良好的控制并且完全没有延迟.我记得当我让它工作的时候高兴得跳起来.
I was able to achieve both fine control and no latency at all. I remember jumping in joy at the time when I had it working.
以下是我使用的资源,有助于简化首次实施 OpenAL 的工作:
Here are the resources I used that helped ease the endeavor of implementing OpenAL for the first time:
- iPhone 上的 OpenAL李>
- 这是因为
这个链接这个视频教程 我能够创建一个出色的声音管理器单身人士.这让我可以在几乎没有声音管理的情况下从任何我想要的课程中播放我需要的所有声音,单身人士会为我处理一切.
- OpenAL on the iPhone
- It was because of
this linkthis video tutorial that I was able to create an excellent sound manager singleton. This allowed me to play all the sounds that I needed from any class that I wanted with little sound management, the singleton took care of everything for me.
如果您需要对音频进行精细控制,更重要的是,如果您需要低延迟的点播音频,我谦虚地建议每个人都使用 OpenAL,尤其是当您需要确保在该处播放声音以及何时播放的游戏时您需要并期望它,例如基于音频的应用程序.
I humbly suggest everyone to use OpenAL if you require fine control over your audio, and more importantly if you require a low-latency on-demand audio, specially for games when you need to make sure sound is played there and then when you require and expect it to, an audio based application for example.
这篇关于在快速按下 Xcode 按钮时快速播放声音的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在快速按下 Xcode 按钮时快速播放声音的最佳方法是什么?
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01