XNA C# SoundEffectInstance - 没有声音

发布于 2024-11-25 00:45:02 字数 1436 浏览 4 评论 0原文

我试图在游戏中播放加载的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疧_╮線 2024-12-02 00:45:02

抱歉,大家...原来我用来测试的 .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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文