OpenAL 中加载声音问题
我在使用 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");
}
soundIdentifier 是一个字典,在 SoundSource 中我保留声音的信息,第一个字符串是声音的正常名称,如“cow”、“horse”或其他名称。< /p>
我从 Form.cs 调用 InitializeSounds,LoadSound 是声音管理器的方法。
Alut.alutLoadMemoryFromFile 导致错误,由于某种原因返回空指针。
剩下的都是简单的代码,希望您能理解。
我使用 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");
}
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.
I call InitializeSounds from Form.cs and LoadSound is method for a sound manager.
Alut.alutLoadMemoryFromFile causes the error, for some reason returns a null pointer.
The rest is simple code hope you can understand.
I work in c# with Tao.OpenAL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要重新安装 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