简体   繁体   English

Monotouch C# 通过音量控制同时播放许多声音

[英]Monotouch C# play many sounds simultaneously with volume control

I'm making a War Game for iOS using Monotouch and C#.我正在使用 Monotouch 和 C# 为 iOS 制作战争游戏。 I'm running into some problem with the audio sound effects.我在音频音效方面遇到了一些问题。

Here's what I require : The ability to play many sound effects simultaneously (possibly up to 10-20 at once) and the ability to adjust volume (for example, if the user zooms in on the battlefield the gun shot volume gets louder).这就是我的要求:同时播放多种音效的能力(一次可能多达 10-20 个)和调节音量的能力(例如,如果用户放大战场,枪声的音量会变大)。

Here are my problems:这是我的问题:

With AVAudioPlayer, I can adjust volume but I can only play 1 sound per thread.使用 AVAudioPlayer,我可以调节音量,但每个线程只能播放 1 个声音。 So if I want to play multiple sounds I have to have dozens and dozens of threads going just incase they overlap... This is a war game, picture 20 soldiers on the battlefield.所以如果我想播放多个声音,我必须有几十个线程,以防它们重叠......这是一个战争游戏,在战场上描绘 20 名士兵。 Each soldier would have a "sound thread" to play gun fire sounds when they shoot because It is possible that every soldier could just happen to fire at the same exact time.每个士兵都会有一个“声音线程”来在他们射击时播放枪声,因为每个士兵都有可能恰好在同一时间开火。 I don't have a problem with making lots of threads, but my game already has dozens of threads running all the time and adding dozens more could get me into trouble... right?我制作大量线程没有问题,但我的游戏已经有几十个线程一直在运行,添加更多线程可能会给我带来麻烦......对吗? So I'd rather not go this road of adding dozens of more threads unless i have too...所以我宁愿不走这条添加更多线程的道路,除非我也有......

With SystemSound, I can play as many sounds as I want in the same thread, but I can't adjust the volume.... So my work around here is, for every sound effect i have - save it like 4 times at 4 different volumes.使用 SystemSound,我可以在同一个线程中播放任意数量的声音,但我无法调整音量......所以我在这里的工作是,对于我拥有的每个声音效果 - 在 4 时保存 4 次不同的卷。 That is a big pain... Any way to adjust volume with SystemSounds??这是一个很大的痛苦......有什么方法可以用SystemSounds调节音量??

Both of these answer some of my requirements, but neither seems to be a seamless fit.这两个都满足了我的一些要求,但似乎都不是天衣无缝的。 Should I just go the AVAudioPlayer multi-threading nightmare road?我应该走AVAudioPlayer多线程噩梦之路吗? Or the SystemSound multi-file-with-different-volume-levels nightmare road?还是 SystemSound 多文件不同音量级别的噩梦之路? Or is there a better way to do this?或者有没有更好的方法来做到这一点?

Thanks in advance.提前致谢。

Finally found the solution to my problem.终于找到了我的问题的解决方案。 AVAudioPlayer IS capable of playiing multiple sounds at once but only with certain file formats... The details are available in this link. AVAudioPlayer 能够同时播放多个声音,但只能使用某些文件格式...详细信息可在此链接中找到。 The reason why I couldn't play my sound effects simultaneously was because the file format was compressed and the iphone only has 1 hardware decompressor.不能同时播放音效的原因是文件格式被压缩了,iphone只有1个硬件解压器。

http://brainwashinc.wordpress.com/2009/08/14/iphone-playing-2-sounds-at-once/ http://brainwashinc.wordpress.com/2009/08/14/iphone-playing-2-sounds-at-once/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM