如何在monodroid中使用OpenAL创建音频上下文

本文关键字:OpenAL 创建 音频 上下文 monodroid | 更新日期: 2023-09-27 18:26:03

每当我试图在monodroid中创建新的音频上下文时,它都会告诉我缺少openal32.dll;这自然是没有意义的,因为这是monodroid,而openal是作为OpenTK的一部分包含的。

我只能假设我做错了什么,但我以前在windows下使用过OpenTK/OpenAL,并且用类似的代码处理得很好。

无论如何,这是一个有问题的代码:

        public Audio()
    {
        if (Loaded == false)
        {
            Loaded = true;
            try
            {
                try {Console.WriteLine ("Current: " + AudioContext.CurrentContext.ToString());} catch { Console.WriteLine ("no current context"); }
                try {Console.WriteLine ("Default: " + AudioContext.DefaultDevice);} catch { Console.WriteLine ("no default device"); }
                Context = new AudioContext();
                ValidContext = true; //we have a valid audio context!
            }
            catch (Exception ex)
            {
                Console.WriteLine ("Loading the audio context failed.");
                Console.WriteLine (ex.ToString ());
                Console.WriteLine (ex.Message);
                ValidContext = false; //Loading the audio context failed :(
            }
        }
    }

这是输出:

I/monodroid-gc(24762): environment supports jni NewWeakGlobalRef
D/AndroidGameView(24762): SurfaceCreated
D/libEGL  (24762): egl.cfg not found, using default config
D/libEGL  (24762): loaded /system/lib/egl/libGLES_android.so
I/mono-stdout(24762): no current context
I/mono-stdout(24762): no default device
I/mono-stdout(24762): Loading the audio context failed.
I/mono-stdout(24762): System.TypeInitializationException: An exception was thrown by the type initializer for OpenTK.Audio.AudioContext ---> System.TypeInitializationException: An exception was thrown by the type initializer for OpenTK.Audio.AudioDeviceEnumerator ---> System.DllNotFoundException: openal32.dll
I/mono-stdout(24762):   at (wrapper managed-to-native) OpenTK.Audio.OpenAL.Alc:MakeContextCurrent (intptr)
I/mono-stdout(24762):   at OpenTK.Audio.OpenAL.Alc.MakeContextCurrent (ContextHandle context) [0x00000] in <filename unknown>:0 
I/mono-stdout(24762):   at OpenTK.Audio.AudioDeviceEnumerator..cctor () [0x00000] in <filename unknown>:0 
I/mono-stdout(24762):   --- End of inner exception stack trace ---
I/mono-stdout(24762):   at OpenTK.Audio.AudioContext..cctor () [0x00000] in <filename unknown>:0 
I/mono-stdout(24762):   --- End of inner exception stack trace ---
I/mono-stdout(24762):   at Hardware.Audio..ctor () [0x00000] in <filename unknown>:0 
I/mono-stdout(24762): An exception was thrown by the type initializer for OpenTK.Audio.AudioContext
I/ARMAssembler(24762): generated scanline__00000177:03545444_00009001_00000000 [159 ipp] (215 ins) at [0x4fc138:0x4fc494] in 4168381 ns

如何在monodroid中使用OpenAL创建音频上下文

openal32.dll未作为OpenTK的一部分包含。OpenTK只有针对OpenAL的绑定。就像图形卡驱动程序中包含的opengl32.dll一样,openal32.dll必须通过声卡驱动程序(或其软件实现)安装。

快速搜索后,您似乎需要编译一个适用于Android的OpenAL软件实现:http://pielot.org/2010/12/14/openal-on-android/

编辑:看起来Android更喜欢使用更新的OpenSL ES。如果你手头有一点时间,你可以尝试让OpenTK的生成器为你生成OpenSL ES绑定。

另一个StackOverflow问题还有一些使用OpenSL的其他选项。