OpenAL 中加载声音问题

发布于 2024-11-29 02:58:07 字数 1435 浏览 2 评论 0原文

我在使用 OpenAL 加载声音时遇到问题:

// in SoundManager.cs
public void LoadSound(string soundId, string path)
        {
            // Generate a buffer.
            int buffer = -1;
            Al.alGenBuffers(1, out buffer);
            int errorCode = Al.alGetError();
            System.Diagnostics.Debug.Assert(errorCode == Al.AL_NO_ERROR);
            int format;
            float frequency;
            int size;
            System.Diagnostics.Debug.Assert(File.Exists(path));
            IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size,
            out frequency);
            System.Diagnostics.Debug.Assert(data != IntPtr.Zero, "Problem");
            // Load wav data into the generated buffer.
            Al.alBufferData(buffer, format, data, size, (int)frequency);
            // Everything seems ok, add it to the library.
            _soundIdentifier.Add(soundId, new SoundSource(buffer, path));
        }

// Form.cs
 private void InitializeSounds()
        {            
            _soundManager.LoadSound("effect", "soundA.wav");            
        }
  1. soundIdentifier 是一个字典,在 SoundSource 中我保留声音的信息,第一个字符串是声音的正常名称,如“cow”、“horse”或其他名称。< /p>

  2. 我从 Form.cs 调用 InitializeSounds,LoadSound 是声音管理器的方法。

  3. Alut.alutLoadMemoryFromFile 导致错误,由于某种原因返回空指针。

  4. 剩下的都是简单的代码,希望您能理解。

我使用 Tai.OpenAL 进行 C# 工作。

I have problem loading a sound with OpenAL:

// in SoundManager.cs
public void LoadSound(string soundId, string path)
        {
            // Generate a buffer.
            int buffer = -1;
            Al.alGenBuffers(1, out buffer);
            int errorCode = Al.alGetError();
            System.Diagnostics.Debug.Assert(errorCode == Al.AL_NO_ERROR);
            int format;
            float frequency;
            int size;
            System.Diagnostics.Debug.Assert(File.Exists(path));
            IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size,
            out frequency);
            System.Diagnostics.Debug.Assert(data != IntPtr.Zero, "Problem");
            // Load wav data into the generated buffer.
            Al.alBufferData(buffer, format, data, size, (int)frequency);
            // Everything seems ok, add it to the library.
            _soundIdentifier.Add(soundId, new SoundSource(buffer, path));
        }

// Form.cs
 private void InitializeSounds()
        {            
            _soundManager.LoadSound("effect", "soundA.wav");            
        }
  1. soundIdentifier is a Dictionary, in SoundSource i keep information for a sound, and the first string is a normal name for the sound like "cow", "horse", or whatever.

  2. I call InitializeSounds from Form.cs and LoadSound is method for a sound manager.

  3. Alut.alutLoadMemoryFromFile causes the error, for some reason returns a null pointer.

  4. The rest is simple code hope you can understand.

I work in c# with Tao.OpenAL.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

絕版丫頭 2024-12-06 02:58:07

您需要重新安装 open al。到这里重新安装。

http://connect.creativelabs.com/openal/Downloads/Forms/AllItems.aspx

You need to re-install open al. Go here to re-install.

http://connect.creativelabs.com/openal/Downloads/Forms/AllItems.aspx

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