在 MonoTouch 中创建声音效果的单个实例,为什么音频对性能如此糟糕?
我想做的是创建一个可重用的音频类,它不会分配/取消分配整数初始化/销毁之外的资源。
因此,诸如此类的课程:
class SoundInst
{
public SoundInst(string sounddir);
public bool IsPlaying;
public void Play(float volume);
public void Stop();
}
我要求这样的事情的原因是我发现在运行时创建音频是一件极其缓慢的事情。我的游戏在没有音频的情况下以稳定的 60 fps 运行,但如果有音频,即使在同一帧中创建和播放一两个声音,它也会下降到 15 fps 以下。
我发现,并不是声音本身减慢了速度,而是声音本身造成了速度。我可以同时运行许多声音并使它们保持循环,这对性能没有影响。
关于解决我的这个问题有什么想法吗?
What I'd like to do is create a re-usable audio class which doesn't allocate/deallocate resources beyond ints initialization/destruction.
So a class such as:
class SoundInst
{
public SoundInst(string sounddir);
public bool IsPlaying;
public void Play(float volume);
public void Stop();
}
The reason I ask for such a thing is that I'm finding creating audio on the run is a prohibitively slow affair. My game runs at a solid 60fps without audio but with audio it drops to below 15fps when even one or two sounds are created and played in the same frame.
What I found is that it's not the sounds themselves which are slowing things down but rather creating them. I can run many sounds simultaneously and keep them on loop and it has no impact on performance.
Any ideas on solving this problem of mine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定单声道触摸,但如果您只是在游戏中使用音频,我会查看 av 基础框架,更具体地说是 avaudioplayer。这就是我在游戏中使用的。它将允许您异步加载音乐,这将有助于解决性能下降问题。
框架的链接:http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVFoundationFramework/_index.html%23//apple_ref/doc/uid/TP40008072
I am not sure about mono touch but if you are just using audio in a game i would look at the av foundation framework and more specifically the avaudioplayer. This is what i use for my games. It will allow you to load your music asynchronously which should help to fix your performance drop issues.
A link to the framework: http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVFoundationFramework/_index.html%23//apple_ref/doc/uid/TP40008072