110,579
社区成员
发帖
与我相关
我的任务
分享
public void LoadSound(string soundId, string path)
{
//Generate a buffer
int buffer = -1;
Al.alGenBuffers(2, 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);//这里报错
//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);
);
}
IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency);
后,点上断点,会发现format,size,frequency三个变量都还是0,这就说明问题是出在这个函数上。 int error = Alut.alutGetError();//this is new line
System.Windows.Forms.MessageBox.Show(error.ToString());//this is new line
加入断点,执行后得到的结果是error=519,这个数字代表什么呢?只要右键Alut,然后点击“转到定义”或按F12键,就可以查看Alut类的公共成员。使用查找命令,可以找到这么一个定义: //
public const int ALUT_ERROR_OPEN_DEVICE = 519;
//
那么就可以知道,519表示的就是ALUT_ERROR_OPEN_DEVICE这个错误。namespace Tao.OpenAl
{
// 摘要:
// OpenAL binding for .NET, implementing ALUT 1.1.
//
// 备注:
// ALUT is non-standard.
public static class Alut
{
//省略
}