OpenAl and Alut for making a Sound Manager

ⅰ亾dé卋堺 提交于 2019-12-13 04:51:45

问题


I have been at this for quite a while. I am using C# for Serious Game Programing, and am working on the SoundManager code found in Chapter 9 of the book, if you want an exact reference. The Code is setting up a sound manager using OpenAl, and I am having a problem with the Alut interface (if that is the right word for what it is). Here is the code that I am working on:

public void LoadSound(string soundId, string path)
    {
        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);


        int errorCode2 = Alut.alutGetError();
        //string errorCodeString = Alut.alutGetErrorString(errorCode2);
        //System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR);
            //System.Diagnostics.Debug.Assert(data != IntPtr.Zero));
            //System.Diagnostics.Debug.Write(errorCode2);

        Al.alBufferData(buffer, format, data, size, (int)frequency);
        _soundIdentifier.Add(soundId, new SoundSource(buffer, path));
    }

The issue is this line right here: System.Diagnostics.Debug.Assert(data != IntPtr.Zero));. When this line is not commented out, it always fails. I did have it work, and do not know what I did to change it, and it stopped working. I have posted about this on another post here: Load sound problem in OpenAL

I have looked all over, and from what I can gather, the issue is with the way that OpenAl is working on my system. To that end, I have uninstalled the Tao Framework that I am using to run OpenAl, and reinstalled. I have also done a system restore to as many points as I have back. I have thought about nuking my whole system, and starting fresh, but a want to avoid this if I can.

I Also have found this link http://distro.ibiblio.org/rootlinux/rootlinux-ports/more/freealut/freealut-1.1.0/doc/alut.html#ErrorHandling that has helped me understand more about Alut, but have been unable to get an alut.dll from it, and cannot get any errors to display. This code:

int errorCode2 = Alut.alutGetError();
        //string errorCodeString = Alut.alutGetErrorString(errorCode2);
        //System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR);
        System.Diagnostics.Debug.Write(errorCode2);

Is my attempt to find out the exact error. If I write the code like:

int errorCode2 = Alut.alutGetError();
        //string errorCodeString = Alut.alutGetErrorString(errorCode2);
        System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR);
            System.Diagnostics.Debug.Write(errorCode2);

I may be using the code all wrong to the find the exact error, as I am still learning c#.

Here is what I am looking for:

1)Is this a syntax error or an error with my system 2)If it is an error in my system, are there files that I am not removing when I try to do an uninstall of OpenAL to refresh all the files. 3)How do I get the alutGetError() code to display in such a way that I can actually read what it is.

Thank you for any help beforehand.


回答1:


I recently ran into the same problem while going through that book and was able to figure it out by logging the error to the output window, notice I through the console.writeline in there. After doing that I checked the output window which gave me the error code 519. After looking all over I saw a few forum posts recommending I re-install openAl to fix this issue which did the trick, all the links I found didn't work to the download so I had to hunt around but softTonic had the one that worked for me on my windows 7 machine http://openal.en.softonic.com/download

IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency);

       var error= Alut.alutGetError();
       Console.WriteLine(error);

        //System.Diagnostics.Debug.Assert(data != IntPtr.Zero);

Hope this helps, helpdevelop



来源:https://stackoverflow.com/questions/19470857/openal-and-alut-for-making-a-sound-manager

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!