XNA C# SoundEffectInstance - 没有声音
我试图在游戏中播放加载的 .wav 文件的 SoundEffectInstances,但我听不到任何声音。
我有一个“ETSound”课程;每个对象都有一个声音。因此,一个 ETSound 对象可能保存“菜单打开”声音,另一个可能保存“坦克开火”声音...等等。
无论如何,ETSound 构造函数如下所示:
public ETSound(SoundEffect se, float volume, float pitch, bool looped, int soundPriority) {
soundTemplate = se;
this.volume = volume;
this.pitch = pitch;
this.looped = looped;
if (soundPriority > 0) {
if (soundPriority > 64) soundPriority = 64;
instanceArray = new SoundEffectInstance[soundPriority];
nextInstanceIndex = 0;
for (int i = 0; i < soundPriority; ++i) {
SoundEffectInstance sei = soundTemplate.CreateInstance();
sei.Volume = volume;
sei.Pitch = pitch;
instanceArray[i] = sei;
}
}
}
这基本上设置了一些参数,并创建了一组声音根据提供的 SoundEffect 的效果实例。
然后,我调用 ETSound 的 Play() 函数:
public void Play() {
if (instanceArray[nextInstanceIndex].State != SoundState.Stopped) instanceArray[nextInstanceIndex].Stop();
instanceArray[nextInstanceIndex].Play();
if (++nextInstanceIndex >= instanceArray.Length) nextInstanceIndex = 0;
}
但是,什么也没有发生。我什么也没听到。
谁能告诉我出了什么问题吗?谢谢。
I'm trying to play SoundEffectInstances of loaded .wav files in my game, but I hear no sound whatsoever.
I have a class "ETSound"; for which each object holds one sound. So one ETSound object might hold the 'menu open' sound, and another might hold the 'tank firing' sound... Etc.
Anyway, the ETSound constructor looks like this:
public ETSound(SoundEffect se, float volume, float pitch, bool looped, int soundPriority) {
soundTemplate = se;
this.volume = volume;
this.pitch = pitch;
this.looped = looped;
if (soundPriority > 0) {
if (soundPriority > 64) soundPriority = 64;
instanceArray = new SoundEffectInstance[soundPriority];
nextInstanceIndex = 0;
for (int i = 0; i < soundPriority; ++i) {
SoundEffectInstance sei = soundTemplate.CreateInstance();
sei.Volume = volume;
sei.Pitch = pitch;
instanceArray[i] = sei;
}
}
}
This basically sets up some parameters, and creates an array of sound effect instances according to the supplied SoundEffect.
Then, I'm calling the Play() function of ETSound:
public void Play() {
if (instanceArray[nextInstanceIndex].State != SoundState.Stopped) instanceArray[nextInstanceIndex].Stop();
instanceArray[nextInstanceIndex].Play();
if (++nextInstanceIndex >= instanceArray.Length) nextInstanceIndex = 0;
}
However, nothing happens. I hear nothing.
Can anyone tell me what's going wrong? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,大家...原来我用来测试的 .wav 文件已损坏...这是一个很难找到的错误,但我明白了。不管怎样,谢谢。
Sorry, everyone... Turns out the .wav file I was using to test was corrupt... A tough bug to find, but I got it. Thanks anyway.