From 92530a7544dfb84af24a538c66b0cbaf035728e9 Mon Sep 17 00:00:00 2001 From: emmaus Date: Tue, 19 Jun 2018 14:14:46 +0000 Subject: [PATCH] dynamically load openal libs using mellinoe's code --- src/OpenTK/Audio/OpenAL/AL/AL.cs | 310 ++++++++++++++++++----------- src/OpenTK/Audio/OpenAL/Alc/Alc.cs | 120 +++++------ src/OpenTK/Platform/SDL2/Sdl2.cs | 4 +- 3 files changed, 257 insertions(+), 177 deletions(-) diff --git a/src/OpenTK/Audio/OpenAL/AL/AL.cs b/src/OpenTK/Audio/OpenAL/AL/AL.cs index b00dc2c5..0d3189ea 100644 --- a/src/OpenTK/Audio/OpenAL/AL/AL.cs +++ b/src/OpenTK/Audio/OpenAL/AL/AL.cs @@ -67,30 +67,57 @@ namespace OpenTK.Audio.OpenAL public static partial class AL { - internal const string Lib = "openal32.dll"; - private const CallingConvention Style = CallingConvention.Cdecl; + internal static readonly NativeLibrary ALNativeLib = NativeLibrary.Load(AL.GetOpenALLibName()); + + internal static string GetOpenALLibName() + { +#if NETSTANDARD + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return "openal32.dll"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return "libopenal.so.1"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return "/System/Library/Frameworks/OpenAL.framework/OpenAL"; + } + else + { + return "openal32.dll"; + } +#else + return "openal32.dll"; +#endif + } + private unsafe delegate void alEnable_d(ALCapability capability); + private static alEnable_d alEnable_ptr = ALNativeLib.LoadFunctionPointer("alEnable"); /// This function enables a feature of the OpenAL driver. There are no capabilities defined in OpenAL 1.1 to be used with this function, but it may be used by an extension. /// The name of a capability to enable. - [DllImport(AL.Lib, EntryPoint = "alEnable", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void Enable(ALCapability capability); + public static void Enable(ALCapability capability) => alEnable_ptr(capability); //AL_API void AL_APIENTRY alEnable( ALenum capability ); + private unsafe delegate void alDisable_d(ALCapability capability); + private static alDisable_d alDisable_ptr = ALNativeLib.LoadFunctionPointer("alDisable"); /// This function disables a feature of the OpenAL driver. /// The name of a capability to disable. - [DllImport(AL.Lib, EntryPoint = "alDisable", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void Disable(ALCapability capability); - // AL_API void AL_APIENTRY alDisable( ALenum capability ); + public static void Disable(ALCapability capability) => alDisable_ptr(capability); + // AL_API void AL_APIENTRY alDisable( ALenum capability ); + private unsafe delegate bool IsEnabled_d(ALCapability capability); + private static IsEnabled_d alIsEnabled_ptr = ALNativeLib.LoadFunctionPointer("alIsEnabled"); /// This function returns a boolean indicating if a specific feature is enabled in the OpenAL driver. /// The name of a capability to enable. /// True if enabled, False if disabled. - [DllImport(AL.Lib, EntryPoint = "alIsEnabled", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern bool IsEnabled(ALCapability capability); + public static bool IsEnabled(ALCapability capability) => alIsEnabled_ptr(capability); // AL_API ALboolean AL_APIENTRY alIsEnabled( ALenum capability ); - [DllImport(AL.Lib, EntryPoint = "alGetString", ExactSpelling = true, CallingConvention = AL.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - private static extern IntPtr GetStringPrivate(ALGetString param); // accepts the enums AlError, AlContextString + private unsafe delegate IntPtr GetStringPrivate_d(ALGetString param); + private static GetStringPrivate_d alGetString_ptr = ALNativeLib.LoadFunctionPointer("alGetString"); + private static IntPtr GetStringPrivate(ALGetString param) => alGetString_ptr(param); // accepts the enums AlError, AlContextString // AL_API const ALchar* AL_APIENTRY alGetString( ALenum param ); /// This function retrieves an OpenAL string property. @@ -125,18 +152,20 @@ namespace OpenTK.Audio.OpenAL // AL_API ALboolean AL_APIENTRY alGetBoolean( ALenum param ); */ + private unsafe delegate int Get_d(ALGetInteger param); + private static Get_d alGetInteger_ptr = ALNativeLib.LoadFunctionPointer("alGetInteger"); /// This function returns an integer OpenAL state. /// the state to be queried: DistanceModel. /// The integer state described by param will be returned. - [DllImport(AL.Lib, EntryPoint = "alGetInteger", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern int Get(ALGetInteger param); + public static int Get(ALGetInteger param) => alGetInteger_ptr(param); // AL_API ALint AL_APIENTRY alGetInteger( ALenum param ); + private unsafe delegate float GetFloat_d(ALGetFloat param); + private static GetFloat_d alGetFloat_ptr = ALNativeLib.LoadFunctionPointer("alGetFloat"); /// This function returns a floating-point OpenAL state. /// the state to be queried: DopplerFactor, SpeedOfSound. /// The floating-point state described by param will be returned. - [DllImport(AL.Lib, EntryPoint = "alGetFloat", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern float Get(ALGetFloat param); + public static float Get(ALGetFloat param) => alGetFloat_ptr(param); // AL_API ALfloat AL_APIENTRY alGetFloat( ALenum param ); /* disabled due to no token using it @@ -148,31 +177,35 @@ namespace OpenTK.Audio.OpenAL // AL_API ALdouble AL_APIENTRY alGetDouble( ALenum param ); */ + private unsafe delegate ALError GetError_d(); + private static GetError_d alGetError_ptr = ALNativeLib.LoadFunctionPointer("alGetError"); /// Error support. Obtain the most recent error generated in the AL state machine. When an error is detected by AL, a flag is set and the error code is recorded. Further errors, if they occur, do not affect this recorded code. When alGetError is called, the code is returned and the flag is cleared, so that a further error will again record its code. /// The first error that occured. can be used with AL.GetString. Returns an Alenum representing the error state. When an OpenAL error occurs, the error state is set and will not be changed until the error state is retrieved using alGetError. Whenever alGetError is called, the error state is cleared and the last state (the current state when the call was made) is returned. To isolate error detection to a specific portion of code, alGetError should be called before the isolated section to clear the current error state. - [DllImport(AL.Lib, EntryPoint = "alGetError", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern ALError GetError(); + public static ALError GetError() => alGetError_ptr(); // AL_API ALenum AL_APIENTRY alGetError( void ); ///This function tests if a specific Extension is available for the OpenAL driver. /// A string naming the desired extension. Example: "EAX-RAM" /// Returns True if the Extension is available or False if not available. - [DllImport(AL.Lib, EntryPoint = "alIsExtensionPresent", ExactSpelling = true, CallingConvention = AL.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - public static extern bool IsExtensionPresent([In] string extname); + public static bool IsExtensionPresent([In] string extname) => IsExtensionPresent_dptr(extname); + private static IsExtensionPresent_d IsExtensionPresent_dptr = ALNativeLib.LoadFunctionPointer("alIsExtensionPresent"); + private unsafe delegate bool IsExtensionPresent_d([In] string extname); // AL_API ALboolean AL_APIENTRY alIsExtensionPresent( const ALchar* extname ); /// This function returns the address of an OpenAL extension function. Handle with care. /// A string containing the function name. /// The return value is a pointer to the specified function. The return value will be IntPtr.Zero if the function is not found. - [DllImport(AL.Lib, EntryPoint = "alGetProcAddress", ExactSpelling = true, CallingConvention = AL.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - public static extern IntPtr GetProcAddress([In] string fname); + public static IntPtr GetProcAddress([In] string fname) => GetProcAddress_dptr(fname); + private static GetProcAddress_d GetProcAddress_dptr = ALNativeLib.LoadFunctionPointer("alGetProcAddress"); + private unsafe delegate IntPtr GetProcAddress_d([In] string fname); // AL_API void* AL_APIENTRY alGetProcAddress( const ALchar* fname ); /// This function returns the enumeration value of an OpenAL token, described by a string. /// A string describing an OpenAL token. Example "AL_DISTANCE_MODEL" /// Returns the actual ALenum described by a string. Returns 0 if the string doesn’t describe a valid OpenAL token. - [DllImport(AL.Lib, EntryPoint = "alGetEnumValue", ExactSpelling = true, CallingConvention = AL.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - public static extern int GetEnumValue([In] string ename); + public static int GetEnumValue([In] string ename) => GetEnumValue_dptr(ename); + private static GetEnumValue_d GetEnumValue_dptr = ALNativeLib.LoadFunctionPointer("alGetEnumValue"); + private unsafe delegate int GetEnumValue_d([In] string ename); // AL_API ALenum AL_APIENTRY alGetEnumValue( const ALchar* ename ); /* Listener @@ -190,8 +223,9 @@ namespace OpenTK.Audio.OpenAL /// This function sets a floating-point property for the listener. /// The name of the attribute to be set: ALListenerf.Gain /// The float value to set the attribute to. - [DllImport(AL.Lib, EntryPoint = "alListenerf", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void Listener(ALListenerf param, float value); + public static void Listener(ALListenerf param, float value) => Listener_dptr(param, value); + private static Listener_d Listener_dptr = ALNativeLib.LoadFunctionPointer("alListenerf"); + private unsafe delegate void Listener_d(ALListenerf param, float value); // AL_API void AL_APIENTRY alListenerf( ALenum param, ALfloat value ); /// This function sets a floating-point property for the listener. @@ -199,8 +233,9 @@ namespace OpenTK.Audio.OpenAL /// The value to set the attribute to. /// The value to set the attribute to. /// The value to set the attribute to. - [DllImport(AL.Lib, EntryPoint = "alListener3f", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void Listener(ALListener3f param, float value1, float value2, float value3); + public static void Listener(ALListener3f param, float value1, float value2, float value3) => Listener3_dptr(param, value1, value2, value3); + private static Listener3_d Listener3_dptr = ALNativeLib.LoadFunctionPointer("alListener3f"); + private unsafe delegate void Listener3_d(ALListener3f param, float value1, float value2, float value3); // AL_API void AL_APIENTRY alListener3f( ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 ); /// This function sets a Math.Vector3 property for the listener. @@ -211,8 +246,9 @@ namespace OpenTK.Audio.OpenAL Listener(param, values.X, values.Y, values.Z); } - [DllImport(AL.Lib, EntryPoint = "alListenerfv", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - unsafe private static extern void ListenerPrivate(ALListenerfv param, float* values); + private unsafe delegate void ListenerPrivate_d(ALListenerfv param, float* values); + private static ListenerPrivate_d alListenerfv_ptr = ALNativeLib.LoadFunctionPointer("alListenerfv"); + unsafe private static void ListenerPrivate(ALListenerfv param, float* values) => alListenerfv_ptr(param, values); // AL_API void AL_APIENTRY alListenerfv( ALenum param, const ALfloat* values ); /// This function sets a floating-point vector property of the listener. @@ -262,8 +298,9 @@ namespace OpenTK.Audio.OpenAL /// This function retrieves a floating-point property of the listener. /// the name of the attribute to be retrieved: ALListenerf.Gain /// a pointer to the floating-point value being retrieved. - [DllImport(AL.Lib, EntryPoint = "alGetListenerf", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void GetListener(ALListenerf param, [Out] out float value); + public static void GetListener(ALListenerf param, [Out] out float value) => GetListener_dptr(param, out value); + private static GetListener_d GetListener_dptr = ALNativeLib.LoadFunctionPointer("alGetListenerf"); + private unsafe delegate void GetListener_d(ALListenerf param, [Out] out float value); // AL_API void AL_APIENTRY alGetListenerf( ALenum param, ALfloat* value ); /// This function retrieves a set of three floating-point values from a property of the listener. @@ -271,8 +308,9 @@ namespace OpenTK.Audio.OpenAL /// The first floating-point value being retrieved. /// The second floating-point value being retrieved. /// The third floating-point value being retrieved. - [DllImport(AL.Lib, EntryPoint = "alGetListener3f", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void GetListener(ALListener3f param, [Out] out float value1, [Out] out float value2, [Out] out float value3); + public static void GetListener(ALListener3f param, [Out] out float value1, [Out] out float value2, [Out] out float value3) => GetListener3_dptr(param, out value1, out value2, out value3); + private static GetListener3_d GetListener3_dptr = ALNativeLib.LoadFunctionPointer("alGetListener3f"); + private unsafe delegate void GetListener3_d(ALListener3f param, [Out] out float value1, [Out] out float value2, [Out] out float value3); // AL_API void AL_APIENTRY alGetListener3f( ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3 ); /// This function retrieves a Math.Vector3 from a property of the listener. @@ -286,8 +324,9 @@ namespace OpenTK.Audio.OpenAL /// This function retrieves a floating-point vector property of the listener. You must pin it manually. /// the name of the attribute to be retrieved: ALListener3f.Position, ALListener3f.Velocity, ALListenerfv.Orientation /// A pointer to the floating-point vector value being retrieved. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alGetListenerfv", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - unsafe public static extern void GetListener(ALListenerfv param, float* values); + unsafe public static void GetListener(ALListenerfv param, float* values) => GetListenerfv_dptr(param, values); + private static GetListenerfv_d GetListenerfv_dptr = ALNativeLib.LoadFunctionPointer("alGetListenerfv"); + private unsafe delegate void GetListenerfv_d(ALListenerfv param, float* values); // AL_API void AL_APIENTRY alGetListenerfv( ALenum param, ALfloat* values ); /// This function retrieves two Math.Vector3 properties of the listener. @@ -356,8 +395,9 @@ namespace OpenTK.Audio.OpenAL * Buffers Processed (Query only) AL_BUFFERS_PROCESSED ALint */ - [DllImport(AL.Lib, EntryPoint = "alGenSources", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - unsafe private static extern void GenSourcesPrivate(int n, [Out] uint* sources); + private unsafe delegate void GenSourcesPrivate_D(int n, [Out] uint* sources); + private static GenSourcesPrivate_D alGenSources_ptr = ALNativeLib.LoadFunctionPointer("alGenSources"); + unsafe private static void GenSourcesPrivate(int n, [Out] uint* sources) => alGenSources_ptr(n, sources); // AL_API void AL_APIENTRY alGenSources( ALsizei n, ALuint* Sources ); /// This function generates one or more sources. References to sources are uint values, which are used wherever a source reference is needed (in calls such as AL.DeleteSources and AL.Source with parameter ALSourcei). @@ -437,22 +477,25 @@ namespace OpenTK.Audio.OpenAL /// The number of sources to be deleted. /// Pointer to an array of source names identifying the sources to be deleted. [CLSCompliant(false)] - [DllImport(AL.Lib, EntryPoint = "alDeleteSources", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - unsafe public static extern void DeleteSources(int n, [In] uint* sources); // Delete Source objects - // AL_API void AL_APIENTRY alDeleteSources( ALsizei n, const ALuint* Sources ); + unsafe public static void DeleteSources(int n, [In] uint* sources) => DeleteSources_dptr(n, sources); + private static DeleteSources_d DeleteSources_dptr = ALNativeLib.LoadFunctionPointer("alDeleteSources"); + private unsafe delegate void DeleteSources_d(int n, [In] uint* sources); // Delete Source objects + // AL_API void AL_APIENTRY alDeleteSources( ALsizei n, const ALuint* Sources ); /// This function deletes one or more sources. /// The number of sources to be deleted. /// Reference to a single source, or an array of source names identifying the sources to be deleted. [CLSCompliant(false)] - [DllImport(AL.Lib, EntryPoint = "alDeleteSources", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void DeleteSources(int n, ref uint sources); + public static void DeleteSources(int n, ref uint sources) => DeleteSources1_dptr(n, ref sources); + private static DeleteSources1_d DeleteSources1_dptr = AL.ALNativeLib.LoadFunctionPointer("alDeleteSources"); + private delegate void DeleteSources1_d(int n, ref uint sources); /// This function deletes one or more sources. /// The number of sources to be deleted. /// Reference to a single source, or an array of source names identifying the sources to be deleted. - [DllImport(AL.Lib, EntryPoint = "alDeleteSources", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void DeleteSources(int n, ref int sources); + public static void DeleteSources(int n, ref int sources) => DeleteSources2_dptr(n, ref sources); + private static DeleteSources2_d DeleteSources2_dptr = AL.ALNativeLib.LoadFunctionPointer("alDeleteSources"); + private delegate void DeleteSources2_d(int n, ref int sources); /// This function deletes one or more sources. /// An array of source names identifying the sources to be deleted. @@ -503,8 +546,9 @@ namespace OpenTK.Audio.OpenAL /// This function tests if a source name is valid, returning True if valid and False if not. /// A source name to be tested for validity /// Success. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alIsSource", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern bool IsSource(uint sid); + public static bool IsSource(uint sid) => IsSource_dptr(sid); + private static IsSource_d IsSource_dptr = ALNativeLib.LoadFunctionPointer("alIsSource"); + private unsafe delegate bool IsSource_d(uint sid); // AL_API ALboolean AL_APIENTRY alIsSource( ALuint sid ); /// This function tests if a source name is valid, returning True if valid and False if not. @@ -519,8 +563,9 @@ namespace OpenTK.Audio.OpenAL /// Source name whose attribute is being set /// The name of the attribute to set: ALSourcef.Pitch, Gain, MinGain, MaxGain, MaxDistance, RolloffFactor, ConeOuterGain, ConeInnerAngle, ConeOuterAngle, ReferenceDistance, EfxAirAbsorptionFactor, EfxRoomRolloffFactor, EfxConeOuterGainHighFrequency. /// The value to set the attribute to. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourcef", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void Source(uint sid, ALSourcef param, float value); + public static void Source(uint sid, ALSourcef param, float value) => Source_dptr(sid, param, value); + private static Source_d Source_dptr = ALNativeLib.LoadFunctionPointer("alSourcef"); + private unsafe delegate void Source_d(uint sid, ALSourcef param, float value); // AL_API void AL_APIENTRY alSourcef( ALuint sid, ALenum param, ALfloat value ); /// This function sets a floating-point property of a source. @@ -538,8 +583,9 @@ namespace OpenTK.Audio.OpenAL /// The three ALfloat values which the attribute will be set to. /// The three ALfloat values which the attribute will be set to. /// The three ALfloat values which the attribute will be set to. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSource3f", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void Source(uint sid, ALSource3f param, float value1, float value2, float value3); + public static void Source(uint sid, ALSource3f param, float value1, float value2, float value3) => Source3_dptr(sid, param, value1, value2, value3); + private static Source3_d Source3_dptr = ALNativeLib.LoadFunctionPointer("alSource3f"); + private unsafe delegate void Source3_d(uint sid, ALSource3f param, float value1, float value2, float value3); // AL_API void AL_APIENTRY alSource3f( ALuint sid, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 ); /// This function sets a source property requiring three floating-point values. @@ -576,9 +622,10 @@ namespace OpenTK.Audio.OpenAL /// Source name whose attribute is being set. /// The name of the attribute to set: ALSourcei.SourceRelative, ConeInnerAngle, ConeOuterAngle, Looping, Buffer, SourceState. /// The value to set the attribute to. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourcei", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void Source(uint sid, ALSourcei param, int value); - // AL_API void AL_APIENTRY alSourcei( ALuint sid, ALenum param, ALint value ); + public static void Source(uint sid, ALSourcei param, int value) => Sourcei_dptr(sid, param, value); + private static Sourcei_d Sourcei_dptr = ALNativeLib.LoadFunctionPointer("alSourcei"); + private unsafe delegate void Sourcei_d(uint sid, ALSourcei param, int value); + // AL_API void AL_APIENTRY alSourcei( ALuint sid, ALenum param, ALint value ); /// This function sets an integer property of a source. /// Source name whose attribute is being set. @@ -631,9 +678,10 @@ namespace OpenTK.Audio.OpenAL /// The value to set the attribute to. (EFX Extension) The destination Auxiliary Effect Slot ID /// The value to set the attribute to. (EFX Extension) The Auxiliary Send number. ///The value to set the attribute to. (EFX Extension) optional Filter ID. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSource3i", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void Source(uint sid, ALSource3i param, int value1, int value2, int value3); - // AL_API void AL_APIENTRY alSource3i( ALuint sid, ALenum param, ALint value1, ALint value2, ALint value3 ); + public static void Source(uint sid, ALSource3i param, int value1, int value2, int value3) => Source3i_dptr(sid, param, value1, value2, value3); + private static Source3i_d Source3i_dptr = ALNativeLib.LoadFunctionPointer("alSource3i"); + private unsafe delegate void Source3i_d(uint sid, ALSource3i param, int value1, int value2, int value3); + // AL_API void AL_APIENTRY alSource3i( ALuint sid, ALenum param, ALint value1, ALint value2, ALint value3 ); /// This function sets 3 integer properties of a source. This property is used to establish connections between Sources and Auxiliary Effect Slots. /// Source name whose attribute is being set. @@ -654,8 +702,9 @@ namespace OpenTK.Audio.OpenAL /// Source name whose attribute is being retrieved. /// The name of the attribute to set: ALSourcef.Pitch, Gain, MinGain, MaxGain, MaxDistance, RolloffFactor, ConeOuterGain, ConeInnerAngle, ConeOuterAngle, ReferenceDistance, EfxAirAbsorptionFactor, EfxRoomRolloffFactor, EfxConeOuterGainHighFrequency. /// A pointer to the floating-point value being retrieved - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alGetSourcef", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void GetSource(uint sid, ALSourcef param, [Out] out float value); + public static void GetSource(uint sid, ALSourcef param, [Out] out float value) => GetSource_dptr(sid, param, out value); + private static GetSource_d GetSource_dptr = ALNativeLib.LoadFunctionPointer("alGetSourcef"); + private unsafe delegate void GetSource_d(uint sid, ALSourcef param, [Out] out float value); // AL_API void AL_APIENTRY alGetSourcef( ALuint sid, ALenum param, ALfloat* value ); /// This function retrieves a floating-point property of a source. @@ -673,8 +722,9 @@ namespace OpenTK.Audio.OpenAL /// Pointer to the value to retrieve. /// Pointer to the value to retrieve. /// Pointer to the value to retrieve. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alGetSource3f", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void GetSource(uint sid, ALSource3f param, [Out] out float value1, [Out] out float value2, [Out] out float value3); + public static void GetSource(uint sid, ALSource3f param, [Out] out float value1, [Out] out float value2, [Out] out float value3) => GetSource3_dptr(sid, param, out value1, out value2, out value3); + private static GetSource3_d GetSource3_dptr = ALNativeLib.LoadFunctionPointer("alGetSource3f"); + private unsafe delegate void GetSource3_d(uint sid, ALSource3f param, [Out] out float value1, [Out] out float value2, [Out] out float value3); // AL_API void AL_APIENTRY alGetSource3f( ALuint sid, ALenum param, ALfloat* value1, ALfloat* value2, ALfloat* value3); /// This function retrieves three floating-point values representing a property of a source. @@ -711,8 +761,9 @@ namespace OpenTK.Audio.OpenAL /// Source name whose attribute is being retrieved. /// The name of the attribute to retrieve: ALSourcei.SourceRelative, Buffer, SourceState, BuffersQueued, BuffersProcessed. /// A pointer to the integer value being retrieved. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alGetSourcei", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void GetSource(uint sid, ALGetSourcei param, [Out] out int value); + public static void GetSource(uint sid, ALGetSourcei param, [Out] out int value) => GetSourcei_dptr(sid, param, out value); + private static GetSourcei_d GetSourcei_dptr = ALNativeLib.LoadFunctionPointer("alGetSourcei"); + private unsafe delegate void GetSourcei_d(uint sid, ALGetSourcei param, [Out] out int value); // AL_API void AL_APIENTRY alGetSourcei( ALuint sid, ALenum param, ALint* value ); /// This function retrieves an integer property of a source. @@ -755,8 +806,9 @@ namespace OpenTK.Audio.OpenAL /// This function plays a set of sources. The playing sources will have their state changed to ALSourceState.Playing. When called on a source which is already playing, the source will restart at the beginning. When the attached buffer(s) are done playing, the source will progress to the ALSourceState.Stopped state. /// The number of sources to be played. /// A pointer to an array of sources to be played. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourcePlayv"), SuppressUnmanagedCodeSecurity] - unsafe public static extern void SourcePlay(int ns, [In] uint* sids); + unsafe public static void SourcePlay(int ns, [In] uint* sids) => SourcePlayv_dptr(ns, sids); + private static SourcePlayv_d SourcePlayv_dptr = ALNativeLib.LoadFunctionPointer("alSourcePlayv"); + private unsafe delegate void SourcePlayv_d(int ns, [In] uint* sids); // AL_API void AL_APIENTRY alSourcePlayv( ALsizei ns, const ALuint *sids ); /// This function plays a set of sources. The playing sources will have their state changed to ALSourceState.Playing. When called on a source which is already playing, the source will restart at the beginning. When the attached buffer(s) are done playing, the source will progress to the ALSourceState.Stopped state. @@ -805,8 +857,9 @@ namespace OpenTK.Audio.OpenAL /// This function stops a set of sources. The stopped sources will have their state changed to ALSourceState.Stopped. /// The number of sources to stop. /// A pointer to an array of sources to be stopped. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourceStopv"), SuppressUnmanagedCodeSecurity] - unsafe public static extern void SourceStop(int ns, [In] uint* sids); + unsafe public static void SourceStop(int ns, [In] uint* sids) => SourceStopv_dptr(ns, sids); + private static SourceStopv_d SourceStopv_dptr = ALNativeLib.LoadFunctionPointer("alSourceStopv"); + private unsafe delegate void SourceStopv_d(int ns, [In] uint* sids); // AL_API void AL_APIENTRY alSourceStopv( ALsizei ns, const ALuint *sids ); /// This function stops a set of sources. The stopped sources will have their state changed to ALSourceState.Stopped. @@ -855,8 +908,9 @@ namespace OpenTK.Audio.OpenAL /// This function stops a set of sources and sets all their states to ALSourceState.Initial. /// The number of sources to be rewound. /// A pointer to an array of sources to be rewound. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourceRewindv"), SuppressUnmanagedCodeSecurity] - unsafe public static extern void SourceRewind(int ns, [In] uint* sids); + unsafe public static void SourceRewind(int ns, [In] uint* sids) => SourceRewindv_dptr(ns, sids); + private static SourceRewindv_d SourceRewindv_dptr = ALNativeLib.LoadFunctionPointer("alSourceRewindv"); + private unsafe delegate void SourceRewindv_d(int ns, [In] uint* sids); // AL_API void AL_APIENTRY alSourceRewindv( ALsizei ns, const ALuint *sids ); /// This function stops a set of sources and sets all their states to ALSourceState.Initial. @@ -905,8 +959,9 @@ namespace OpenTK.Audio.OpenAL /// This function pauses a set of sources. The paused sources will have their state changed to ALSourceState.Paused. /// The number of sources to be paused. /// A pointer to an array of sources to be paused. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourcePausev"), SuppressUnmanagedCodeSecurity] - unsafe public static extern void SourcePause(int ns, [In] uint* sids); + unsafe public static void SourcePause(int ns, [In] uint* sids) => SourcePausev_dptr(ns, sids); + private static SourcePausev_d SourcePausev_dptr = ALNativeLib.LoadFunctionPointer("alSourcePausev"); + private unsafe delegate void SourcePausev_d(int ns, [In] uint* sids); // AL_API void AL_APIENTRY alSourcePausev( ALsizei ns, const ALuint *sids ); /// This function pauses a set of sources. The paused sources will have their state changed to ALSourceState.Paused. @@ -953,8 +1008,9 @@ namespace OpenTK.Audio.OpenAL /// This function plays, replays or resumes a source. The playing source will have it's state changed to ALSourceState.Playing. When called on a source which is already playing, the source will restart at the beginning. When the attached buffer(s) are done playing, the source will progress to the ALSourceState.Stopped state. /// The name of the source to be played. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourcePlay", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void SourcePlay(uint sid); + public static void SourcePlay(uint sid) => SourcePlay_dptr(sid); + private static SourcePlay_d SourcePlay_dptr = ALNativeLib.LoadFunctionPointer("alSourcePlay"); + private unsafe delegate void SourcePlay_d(uint sid); // AL_API void AL_APIENTRY alSourcePlay( ALuint sid ); /// This function plays, replays or resumes a source. The playing source will have it's state changed to ALSourceState.Playing. When called on a source which is already playing, the source will restart at the beginning. When the attached buffer(s) are done playing, the source will progress to the ALSourceState.Stopped state. @@ -963,11 +1019,12 @@ namespace OpenTK.Audio.OpenAL { SourcePlay((uint)sid); } - + /// This function stops a source. The stopped source will have it's state changed to ALSourceState.Stopped. /// The name of the source to be stopped. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourceStop", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void SourceStop(uint sid); + public static void SourceStop(uint sid) => SourceStop_dptr(sid); + private static SourceStop_d SourceStop_dptr = ALNativeLib.LoadFunctionPointer("alSourceStop"); + private unsafe delegate void SourceStop_d(uint sid); // AL_API void AL_APIENTRY alSourceStop( ALuint sid ); /// This function stops a source. The stopped source will have it's state changed to ALSourceState.Stopped. @@ -976,11 +1033,12 @@ namespace OpenTK.Audio.OpenAL { SourceStop((uint)sid); } - + /// This function stops the source and sets its state to ALSourceState.Initial. /// The name of the source to be rewound. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourceRewind", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void SourceRewind(uint sid); + public static void SourceRewind(uint sid) => SourceRewind_dptr(sid); + private static SourceRewind_d SourceRewind_dptr = ALNativeLib.LoadFunctionPointer("alSourceRewind"); + private unsafe delegate void SourceRewind_d(uint sid); // AL_API void AL_APIENTRY alSourceRewind( ALuint sid ); /// This function stops the source and sets its state to ALSourceState.Initial. @@ -992,8 +1050,9 @@ namespace OpenTK.Audio.OpenAL /// This function pauses a source. The paused source will have its state changed to ALSourceState.Paused. /// The name of the source to be paused. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourcePause", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void SourcePause(uint sid); + public static void SourcePause(uint sid) => SourcePause_dptr(sid); + private static SourcePause_d SourcePause_dptr = ALNativeLib.LoadFunctionPointer("alSourcePause"); + private unsafe delegate void SourcePause_d(uint sid); // AL_API void AL_APIENTRY alSourcePause( ALuint sid ); /// This function pauses a source. The paused source will have its state changed to ALSourceState.Paused. @@ -1007,8 +1066,9 @@ namespace OpenTK.Audio.OpenAL /// The name of the source to queue buffers onto. /// The number of buffers to be queued. /// A pointer to an array of buffer names to be queued. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourceQueueBuffers"), SuppressUnmanagedCodeSecurity] - unsafe public static extern void SourceQueueBuffers(uint sid, int numEntries, [In] uint* bids); + unsafe public static void SourceQueueBuffers(uint sid, int numEntries, [In] uint* bids) => SourceQueueBuffers_dptr(sid, numEntries, bids); + private static SourceQueueBuffers_d SourceQueueBuffers_dptr = ALNativeLib.LoadFunctionPointer("alSourceQueueBuffers"); + private unsafe delegate void SourceQueueBuffers_d(uint sid, int numEntries, [In] uint* bids); // AL_API void AL_APIENTRY alSourceQueueBuffers( ALuint sid, ALsizei numEntries, const ALuint *bids ); /// This function queues a set of buffers on a source. All buffers attached to a source will be played in sequence, and the number of processed buffers can be detected using AL.GetSource with parameter ALGetSourcei.BuffersProcessed. When first created, a source will be of type ALSourceType.Undetermined. A successful AL.SourceQueueBuffers call will change the source type to ALSourceType.Streaming. @@ -1069,8 +1129,9 @@ namespace OpenTK.Audio.OpenAL /// The name of the source to unqueue buffers from. /// The number of buffers to be unqueued. /// A pointer to an array of buffer names that were removed. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alSourceUnqueueBuffers"), SuppressUnmanagedCodeSecurity] - unsafe public static extern void SourceUnqueueBuffers(uint sid, int numEntries, [In] uint* bids); + unsafe public static void SourceUnqueueBuffers(uint sid, int numEntries, [In] uint* bids) => SourceUnqueueBuffers1_dptr(sid, numEntries, bids); + private static SourceUnqueueBuffers1_d SourceUnqueueBuffers1_dptr = ALNativeLib.LoadFunctionPointer("alSourceUnqueueBuffers"); + private unsafe delegate void SourceUnqueueBuffers1_d(uint sid, int numEntries, [In] uint* bids); // AL_API void AL_APIENTRY alSourceUnqueueBuffers( ALuint sid, ALsizei numEntries, ALuint *bids ); /// This function unqueues a set of buffers attached to a source. The number of processed buffers can be detected using AL.GetSource with parameter ALGetSourcei.BuffersProcessed, which is the maximum number of buffers that can be unqueued using this call. The unqueue operation will only take place if all n buffers can be removed from the queue. @@ -1078,30 +1139,34 @@ namespace OpenTK.Audio.OpenAL /// The number of buffers to be unqueued. /// A pointer to an array of buffer names that were removed. [CLSCompliant(false)] - [DllImport(AL.Lib, EntryPoint = "alSourceUnqueueBuffers"), SuppressUnmanagedCodeSecurity] - public static extern void SourceUnqueueBuffers(uint sid, int numEntries, [Out] uint[] bids); + public static void SourceUnqueueBuffers(uint sid, int numEntries, [Out] uint[] bids) => SourceUnqueueBuffers2_dptr(sid, numEntries, bids); + private static SourceUnqueueBuffers2_d SourceUnqueueBuffers2_dptr = ALNativeLib.LoadFunctionPointer("alSourceUnqueueBuffers"); + private delegate void SourceUnqueueBuffers2_d(uint sid, int numEntries, [Out] uint[] bids); /// This function unqueues a set of buffers attached to a source. The number of processed buffers can be detected using AL.GetSource with parameter ALGetSourcei.BuffersProcessed, which is the maximum number of buffers that can be unqueued using this call. The unqueue operation will only take place if all n buffers can be removed from the queue. /// The name of the source to unqueue buffers from. /// The number of buffers to be unqueued. /// A pointer to an array of buffer names that were removed. - [DllImport(AL.Lib, EntryPoint = "alSourceUnqueueBuffers"), SuppressUnmanagedCodeSecurity] - public static extern void SourceUnqueueBuffers(int sid, int numEntries, [Out] int[] bids); + public static void SourceUnqueueBuffers(int sid, int numEntries, [Out] int[] bids) => SourceUnqueueBuffers3_dptr(sid, numEntries, bids); + private static SourceUnqueueBuffers3_d SourceUnqueueBuffers3_dptr = ALNativeLib.LoadFunctionPointer("alSourceUnqueueBuffers"); + private delegate void SourceUnqueueBuffers3_d(int sid, int numEntries, [Out] int[] bids); /// This function unqueues a set of buffers attached to a source. The number of processed buffers can be detected using AL.GetSource with parameter ALGetSourcei.BuffersProcessed, which is the maximum number of buffers that can be unqueued using this call. The unqueue operation will only take place if all n buffers can be removed from the queue. /// The name of the source to unqueue buffers from. /// The number of buffers to be unqueued. /// A pointer to an array of buffer names that were removed. [CLSCompliant(false)] - [DllImport(AL.Lib, EntryPoint = "alSourceUnqueueBuffers"), SuppressUnmanagedCodeSecurity] - public static extern void SourceUnqueueBuffers(uint sid, int numEntries, ref uint bids); + public static void SourceUnqueueBuffers(uint sid, int numEntries, ref uint bids) => SourceUnqueueBuffers4_dptr(sid, numEntries, ref bids); + private static SourceUnqueueBuffers4_d SourceUnqueueBuffers4_dptr = ALNativeLib.LoadFunctionPointer("alSourceUnqueueBuffers"); + private delegate void SourceUnqueueBuffers4_d(uint sid, int numEntries, ref uint bids); /// This function unqueues a set of buffers attached to a source. The number of processed buffers can be detected using AL.GetSource with parameter ALGetSourcei.BuffersProcessed, which is the maximum number of buffers that can be unqueued using this call. The unqueue operation will only take place if all n buffers can be removed from the queue. /// The name of the source to unqueue buffers from. /// The number of buffers to be unqueued. /// A pointer to an array of buffer names that were removed. - [DllImport(AL.Lib, EntryPoint = "alSourceUnqueueBuffers"), SuppressUnmanagedCodeSecurity] - public static extern void SourceUnqueueBuffers(int sid, int numEntries, ref int bids); + public static void SourceUnqueueBuffers(int sid, int numEntries, ref int bids) => SourceUnqueueBuffers5_dptr(sid, numEntries, ref bids); + private static SourceUnqueueBuffers5_d SourceUnqueueBuffers5_dptr = ALNativeLib.LoadFunctionPointer("alSourceUnqueueBuffers"); + private delegate void SourceUnqueueBuffers5_d(int sid, int numEntries, ref int bids); /// This function unqueues a set of buffers attached to a source. The number of processed buffers can be detected using AL.GetSource with parameter ALGetSourcei.BuffersProcessed, which is the maximum number of buffers that can be unqueued using this call. The unqueue operation will only take place if all n buffers can be removed from the queue. /// The name of the source to unqueue buffers from. @@ -1144,16 +1209,14 @@ namespace OpenTK.Audio.OpenAL /// The number of buffers to be generated. /// Pointer to an array of uint values which will store the names of the new buffers. [CLSCompliant(false)] - [DllImport(AL.Lib, EntryPoint = "alGenBuffers", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity] - unsafe public static extern void GenBuffers(int n, [Out] uint* buffers); - // AL_API void AL_APIENTRY alGenBuffers( ALsizei n, ALuint* Buffers ); + unsafe public static void GenBuffers(int n, [Out] uint* buffers) => GenBuffers_dptr(n, buffers); + private static GenBuffers_d GenBuffers_dptr = ALNativeLib.LoadFunctionPointer("alGenBuffers"); + private unsafe delegate void GenBuffers_d(int n, [Out] uint* buffers); - /// This function generates one or more buffers, which contain audio buffer (see AL.BufferData). References to buffers are uint values, which are used wherever a buffer reference is needed (in calls such as AL.DeleteBuffers, AL.Source with parameter ALSourcei, AL.SourceQueueBuffers, and AL.SourceUnqueueBuffers). - /// The number of buffers to be generated. - /// Pointer to an array of uint values which will store the names of the new buffers. - [CLSCompliant(false)] - [DllImport(AL.Lib, EntryPoint = "alGenBuffers", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity] - unsafe public static extern void GenBuffers(int n, [Out] int* buffers); + unsafe public static void GenBuffers(int n, [Out] int* buffers) => GenBuffersS_dptr(n, buffers); + private static GenBuffersS_d GenBuffersS_dptr = ALNativeLib.LoadFunctionPointer("alGenBuffers"); + private unsafe delegate void GenBuffersS_d(int n, [Out] int* buffers); + // AL_API void AL_APIENTRY alGenBuffers( ALsizei n, ALuint* Buffers ); /// This function generates one or more buffers, which contain audio buffer (see AL.BufferData). References to buffers are uint values, which are used wherever a buffer reference is needed (in calls such as AL.DeleteBuffers, AL.Source with parameter ALSourcei, AL.SourceQueueBuffers, and AL.SourceUnqueueBuffers). /// The number of buffers to be generated. @@ -1215,16 +1278,18 @@ namespace OpenTK.Audio.OpenAL /// The number of buffers to be deleted. /// Pointer to an array of buffer names identifying the buffers to be deleted. [CLSCompliant(false)] - [DllImport(AL.Lib, EntryPoint = "alDeleteBuffers", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - unsafe public static extern void DeleteBuffers(int n, [In] uint* buffers); + unsafe public static void DeleteBuffers(int n, [In] uint* buffers) => DeleteBuffers_dptr(n, buffers); + private static DeleteBuffers_d DeleteBuffers_dptr = ALNativeLib.LoadFunctionPointer("alDeleteBuffers"); + private unsafe delegate void DeleteBuffers_d(int n, [In] uint* buffers); // AL_API void AL_APIENTRY alDeleteBuffers( ALsizei n, const ALuint* Buffers ); /// This function deletes one or more buffers, freeing the resources used by the buffer. Buffers which are attached to a source can not be deleted. See AL.Source (ALSourcei) and AL.SourceUnqueueBuffers for information on how to detach a buffer from a source. /// The number of buffers to be deleted. /// Pointer to an array of buffer names identifying the buffers to be deleted. [CLSCompliant(false)] - [DllImport(AL.Lib, EntryPoint = "alDeleteBuffers", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - unsafe public static extern void DeleteBuffers(int n, [In] int* buffers); + unsafe public static void DeleteBuffers(int n, [In] int* buffers) => DeleteBuffersS_dptr(n, buffers); + private static DeleteBuffersS_d DeleteBuffersS_dptr = ALNativeLib.LoadFunctionPointer("alDeleteBuffers"); + private unsafe delegate void DeleteBuffersS_d(int n, [In] int* buffers); /// This function deletes one or more buffers, freeing the resources used by the buffer. Buffers which are attached to a source can not be deleted. See AL.Source (ALSourcei) and AL.SourceUnqueueBuffers for information on how to detach a buffer from a source. /// The number of buffers to be deleted. @@ -1304,8 +1369,9 @@ namespace OpenTK.Audio.OpenAL /// This function tests if a buffer name is valid, returning True if valid, False if not. /// A buffer Handle previously allocated with . /// Success. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alIsBuffer", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern bool IsBuffer(uint bid); + public static bool IsBuffer(uint bid) => IsBuffer_dptr(bid); + private static IsBuffer_d IsBuffer_dptr = ALNativeLib.LoadFunctionPointer("alIsBuffer"); + private unsafe delegate bool IsBuffer_d(uint bid); // AL_API ALboolean AL_APIENTRY alIsBuffer( ALuint bid ); /// This function tests if a buffer name is valid, returning True if valid, False if not. @@ -1323,8 +1389,9 @@ namespace OpenTK.Audio.OpenAL /// Pointer to a pinned audio buffer. /// The size of the audio buffer in bytes. /// The frequency of the audio buffer. - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alBufferData", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void BufferData(uint bid, ALFormat format, IntPtr buffer, int size, int freq); + public static void BufferData(uint bid, ALFormat format, IntPtr buffer, int size, int freq) => BufferData_dptr(bid, format, buffer, size, freq); + private static BufferData_d BufferData_dptr = ALNativeLib.LoadFunctionPointer("alBufferData"); + private unsafe delegate void BufferData_d(uint bid, ALFormat format, IntPtr buffer, int size, int freq); // AL_API void AL_APIENTRY alBufferData( ALuint bid, ALenum format, const ALvoid* buffer, ALsizei size, ALsizei freq ); /// This function fills a buffer with audio buffer. All the pre-defined formats are PCM buffer, but this function may be used by extensions to load other buffer types as well. @@ -1383,8 +1450,9 @@ namespace OpenTK.Audio.OpenAL /// Buffer name whose attribute is being retrieved /// The name of the attribute to be retrieved: ALGetBufferi.Frequency, Bits, Channels, Size, and the currently hidden AL_DATA (dangerous). /// A pointer to an int to hold the retrieved buffer - [CLSCompliant(false), DllImport(AL.Lib, EntryPoint = "alGetBufferi", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void GetBuffer(uint bid, ALGetBufferi param, [Out] out int value); + public static void GetBuffer(uint bid, ALGetBufferi param, [Out] out int value) => GetBuffer_dptr(bid, param, out value); + private static GetBuffer_d GetBuffer_dptr = ALNativeLib.LoadFunctionPointer("alGetBufferi"); + private unsafe delegate void GetBuffer_d(uint bid, ALGetBufferi param, [Out] out int value); // AL_API void AL_APIENTRY alGetBufferi( ALuint bid, ALenum param, ALint* value ); /// This function retrieves an integer property of a buffer. @@ -1404,20 +1472,23 @@ namespace OpenTK.Audio.OpenAL /// AL.DopplerFactor is a simple scaling of source and listener velocities to exaggerate or deemphasize the Doppler (pitch) shift resulting from the calculation. /// A negative value will result in an error, the command is then ignored. The default value is 1f. The current setting can be queried using AL.Get with parameter ALGetFloat.SpeedOfSound. - [DllImport(AL.Lib, EntryPoint = "alDopplerFactor", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void DopplerFactor(float value); + public static void DopplerFactor(float value) => DopplerFactor_dptr(value); + private static DopplerFactor_d DopplerFactor_dptr = ALNativeLib.LoadFunctionPointer("alDopplerFactor"); + private unsafe delegate void DopplerFactor_d(float value); // AL_API void AL_APIENTRY alDopplerFactor( ALfloat value ); /// This function is deprecated and should not be used. /// The default is 1.0f. - [DllImport(AL.Lib, EntryPoint = "alDopplerVelocity", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void DopplerVelocity(float value); + public static void DopplerVelocity(float value) => DopplerVelocity_dptr(value); + private static DopplerVelocity_d DopplerVelocity_dptr = ALNativeLib.LoadFunctionPointer("alDopplerVelocity"); + private unsafe delegate void DopplerVelocity_d(float value); // AL_API void AL_APIENTRY alDopplerVelocity( ALfloat value ); /// AL.SpeedOfSound allows the application to change the reference (propagation) speed used in the Doppler calculation. The source and listener velocities should be expressed in the same units as the speed of sound. /// A negative or zero value will result in an error, and the command is ignored. Default: 343.3f (appropriate for velocity units of meters and air as the propagation medium). The current setting can be queried using AL.Get with parameter ALGetFloat.SpeedOfSound. - [DllImport(AL.Lib, EntryPoint = "alSpeedOfSound", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void SpeedOfSound(float value); + public static void SpeedOfSound(float value) => SpeedOfSound_dptr(value); + private static SpeedOfSound_d SpeedOfSound_dptr = ALNativeLib.LoadFunctionPointer("alSpeedOfSound"); + private unsafe delegate void SpeedOfSound_d(float value); // AL_API void AL_APIENTRY alSpeedOfSound( ALfloat value ); /// This function selects the OpenAL distance model – ALDistanceModel.InverseDistance, ALDistanceModel.InverseDistanceClamped, ALDistanceModel.LinearDistance, ALDistanceModel.LinearDistanceClamped, ALDistanceModel.ExponentDistance, ALDistanceModel.ExponentDistanceClamped, or ALDistanceModel.None. The default distance model in OpenAL is ALDistanceModel.InverseDistanceClamped. @@ -1451,8 +1522,9 @@ namespace OpenTK.Audio.OpenAL /// gain = 1f; /// /// - [DllImport(AL.Lib, EntryPoint = "alDistanceModel", ExactSpelling = true, CallingConvention = AL.Style), SuppressUnmanagedCodeSecurity()] - public static extern void DistanceModel(ALDistanceModel distancemodel); + public static void DistanceModel(ALDistanceModel distancemodel) => DistanceModel_dptr(distancemodel); + private static DistanceModel_d DistanceModel_dptr = ALNativeLib.LoadFunctionPointer("alDistanceModel"); + private unsafe delegate void DistanceModel_d(ALDistanceModel distancemodel); // AL_API void AL_APIENTRY alDistanceModel( ALenum distanceModel ); /// (Helper) Returns Source state information. diff --git a/src/OpenTK/Audio/OpenAL/Alc/Alc.cs b/src/OpenTK/Audio/OpenAL/Alc/Alc.cs index ef6d39a7..d52acc0c 100644 --- a/src/OpenTK/Audio/OpenAL/Alc/Alc.cs +++ b/src/OpenTK/Audio/OpenAL/Alc/Alc.cs @@ -71,11 +71,9 @@ namespace OpenTK.Audio.OpenAL /// Alc = Audio Library Context public static class Alc { - private const string Lib = AL.Lib; - private const CallingConvention Style = CallingConvention.Cdecl; - - [DllImport(Alc.Lib, EntryPoint = "alcCreateContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr sys_CreateContext([In] IntPtr device, [In] int* attrlist); + private unsafe delegate IntPtr d_alcCreateContext(IntPtr device, int* attrList); + private static d_alcCreateContext ptr_alcCreateContext = AL.ALNativeLib.LoadFunctionPointer("alcCreateContext"); + unsafe static IntPtr sys_CreateContext([In] IntPtr device, [In] int* attrlist) => ptr_alcCreateContext(device, attrlist); /// This function creates a context using a specified device. /// a pointer to a device @@ -105,20 +103,22 @@ namespace OpenTK.Audio.OpenAL } } - [DllImport(Alc.Lib, EntryPoint = "alcMakeContextCurrent", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - private static extern bool MakeContextCurrent(IntPtr context); + static bool MakeContextCurrent(IntPtr context) => MakeContextCurrent_dptr(context); + private static MakeContextCurrent_d MakeContextCurrent_dptr = AL.ALNativeLib.LoadFunctionPointer("alcMakeContextCurrent"); + private delegate bool MakeContextCurrent_d(IntPtr context); /// This function makes a specified context the current context. /// A pointer to the new context. /// Returns True on success, or False on failure. - public static bool MakeContextCurrent(ContextHandle context) + public static bool MakeContextCurrent(ContextHandle context) { return MakeContextCurrent(context.Handle); } // ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent( ALCcontext *context ); - [DllImport(Alc.Lib, EntryPoint = "alcProcessContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - private static extern void ProcessContext(IntPtr context); + static void ProcessContext(IntPtr context) => ProcessContext_dptr(context); + private static ProcessContext_d ProcessContext_dptr = AL.ALNativeLib.LoadFunctionPointer("alcProcessContext"); + private delegate void ProcessContext_d(IntPtr context); /// This function tells a context to begin processing. When a context is suspended, changes in OpenAL state will be accepted but will not be processed. alcSuspendContext can be used to suspend a context, and then all the OpenAL state changes can be applied at once, followed by a call to alcProcessContext to apply all the state changes immediately. In some cases, this procedure may be more efficient than application of properties in a non-suspended state. In some implementations, process and suspend calls are each a NOP. /// a pointer to the new context @@ -128,8 +128,9 @@ namespace OpenTK.Audio.OpenAL } // ALC_API void ALC_APIENTRY alcProcessContext( ALCcontext *context ); - [DllImport(Alc.Lib, EntryPoint = "alcSuspendContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - private static extern void SuspendContext(IntPtr context); + static void SuspendContext(IntPtr context) => SuspendContext_dptr(context); + private static SuspendContext_d SuspendContext_dptr = AL.ALNativeLib.LoadFunctionPointer("alcSuspendContext"); + private delegate void SuspendContext_d(IntPtr context); /// This function suspends processing on a specified context. When a context is suspended, changes in OpenAL state will be accepted but will not be processed. A typical use of alcSuspendContext would be to suspend a context, apply all the OpenAL state changes at once, and then call alcProcessContext to apply all the state changes at once. In some cases, this procedure may be more efficient than application of properties in a non-suspended state. In some implementations, process and suspend calls are each a NOP. /// a pointer to the context to be suspended. @@ -139,8 +140,9 @@ namespace OpenTK.Audio.OpenAL } // ALC_API void ALC_APIENTRY alcSuspendContext( ALCcontext *context ); - [DllImport(Alc.Lib, EntryPoint = "alcDestroyContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - private static extern void DestroyContext(IntPtr context); + static void DestroyContext(IntPtr context) => DestroyContext_dptr(context); + private static DestroyContext_d DestroyContext_dptr = AL.ALNativeLib.LoadFunctionPointer("alcDestroyContext"); + private delegate void DestroyContext_d(IntPtr context); /// This function destroys a context. /// a pointer to the new context. @@ -150,8 +152,9 @@ namespace OpenTK.Audio.OpenAL } // ALC_API void ALC_APIENTRY alcDestroyContext( ALCcontext *context ); - [DllImport(Alc.Lib, EntryPoint = "alcGetCurrentContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - private static extern IntPtr sys_GetCurrentContext(); + private static IntPtr sys_GetCurrentContext() => sys_GetCurrentContext_dptr(); + private static sys_GetCurrentContext_d sys_GetCurrentContext_dptr = AL.ALNativeLib.LoadFunctionPointer("alcGetCurrentContext"); + private delegate IntPtr sys_GetCurrentContext_d(); /// This function retrieves the current context. /// Returns a pointer to the current context. @@ -161,8 +164,9 @@ namespace OpenTK.Audio.OpenAL } // ALC_API ALCcontext * ALC_APIENTRY alcGetCurrentContext( void ); - [DllImport(Alc.Lib, EntryPoint = "alcGetContextsDevice", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - private static extern IntPtr GetContextsDevice(IntPtr context); + static IntPtr GetContextsDevice(IntPtr context) => GetContextsDevice_dptr(context); + private static GetContextsDevice_d GetContextsDevice_dptr = AL.ALNativeLib.LoadFunctionPointer("alcGetContextsDevice"); + private delegate IntPtr GetContextsDevice_d(IntPtr context); /// This function retrieves a context's device pointer. /// a pointer to a context. @@ -176,50 +180,57 @@ namespace OpenTK.Audio.OpenAL /// This function opens a device by name. /// a null-terminated string describing a device. /// Returns a pointer to the opened device. The return value will be NULL if there is an error. - [DllImport(Alc.Lib, EntryPoint = "alcOpenDevice", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - public static extern IntPtr OpenDevice([In] string devicename); + public static IntPtr OpenDevice([In] string devicename) => OpenDevice_dptr(devicename); + private static OpenDevice_d OpenDevice_dptr = AL.ALNativeLib.LoadFunctionPointer("alcOpenDevice"); + private delegate IntPtr OpenDevice_d([In] string devicename); // ALC_API ALCdevice * ALC_APIENTRY alcOpenDevice( const ALCchar *devicename ); /// This function closes a device by name. /// a pointer to an opened device /// True will be returned on success or False on failure. Closing a device will fail if the device contains any contexts or buffers. - [DllImport(Alc.Lib, EntryPoint = "alcCloseDevice", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - public static extern bool CloseDevice([In] IntPtr device); + public static bool CloseDevice([In] IntPtr device) => CloseDevice_dptr(device); + private static CloseDevice_d CloseDevice_dptr = AL.ALNativeLib.LoadFunctionPointer("alcCloseDevice"); + private delegate bool CloseDevice_d([In] IntPtr device); // ALC_API ALCboolean ALC_APIENTRY alcCloseDevice( ALCdevice *device ); /// This function retrieves the current context error state. /// a pointer to the device to retrieve the error state from /// Errorcode Int32. - [DllImport(Alc.Lib, EntryPoint = "alcGetError", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - public static extern AlcError GetError([In] IntPtr device); + public static AlcError GetError([In] IntPtr device) => GetError_dptr(device); + private static GetError_d GetError_dptr = AL.ALNativeLib.LoadFunctionPointer("alcGetError"); + private delegate AlcError GetError_d([In] IntPtr device); // ALC_API ALCenum ALC_APIENTRY alcGetError( ALCdevice *device ); /// This function queries if a specified context extension is available. /// a pointer to the device to be queried for an extension. /// a null-terminated string describing the extension. /// Returns True if the extension is available, False if the extension is not available. - [DllImport(Alc.Lib, EntryPoint = "alcIsExtensionPresent", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - public static extern bool IsExtensionPresent([In] IntPtr device, [In] string extname); + public static bool IsExtensionPresent([In] IntPtr device, [In] string extname) => IsExtensionPresent_dptr(device, extname); + private static IsExtensionPresent_d IsExtensionPresent_dptr = AL.ALNativeLib.LoadFunctionPointer("alcIsExtensionPresent"); + private delegate bool IsExtensionPresent_d([In] IntPtr device, [In] string extname); // ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent( ALCdevice *device, const ALCchar *extname ); /// This function retrieves the address of a specified context extension function. /// a pointer to the device to be queried for the function. /// a null-terminated string describing the function. /// Returns the address of the function, or NULL if it is not found. - [DllImport(Alc.Lib, EntryPoint = "alcGetProcAddress", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - public static extern IntPtr GetProcAddress([In] IntPtr device, [In] string funcname); + public static IntPtr GetProcAddress([In] IntPtr device, [In] string funcname) => GetProcAddress_dptr(device, funcname); + private static GetProcAddress_d GetProcAddress_dptr = AL.ALNativeLib.LoadFunctionPointer("alcGetProcAddress"); + private delegate IntPtr GetProcAddress_d([In] IntPtr device, [In] string funcname); // ALC_API void * ALC_APIENTRY alcGetProcAddress( ALCdevice *device, const ALCchar *funcname ); /// This function retrieves the enum value for a specified enumeration name. /// a pointer to the device to be queried. /// a null terminated string describing the enum value. /// Returns the enum value described by the enumName string. This is most often used for querying an enum value for an ALC extension. - [DllImport(Alc.Lib, EntryPoint = "alcGetEnumValue", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - public static extern int GetEnumValue([In] IntPtr device, [In] string enumname); + public static int GetEnumValue([In] IntPtr device, [In] string enumname) => GetEnumValue_dptr(device, enumname); + private static GetEnumValue_d GetEnumValue_dptr = AL.ALNativeLib.LoadFunctionPointer("alcGetEnumValue"); + private delegate int GetEnumValue_d([In] IntPtr device, [In] string enumname); // ALC_API ALCenum ALC_APIENTRY alcGetEnumValue( ALCdevice *device, const ALCchar *enumname ); - [DllImport(Alc.Lib, EntryPoint = "alcGetString", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - private static extern IntPtr GetStringPrivate([In] IntPtr device, AlcGetString param); + private delegate IntPtr GetStringPrivate_d([In] IntPtr device, AlcGetString param); + private static GetStringPrivate_d alcGetString_ptr = AL.ALNativeLib.LoadFunctionPointer("alcGetString"); + private static IntPtr GetStringPrivate([In] IntPtr device, AlcGetString param) => alcGetString_ptr(device, param); // ALC_API const ALCchar * ALC_APIENTRY alcGetString( ALCdevice *device, ALCenum param ); /// This function returns pointers to strings related to the context. @@ -306,8 +317,9 @@ namespace OpenTK.Audio.OpenAL return result; } - [DllImport(Alc.Lib, EntryPoint = "alcGetIntegerv", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - private unsafe static extern void GetInteger(IntPtr device, AlcGetInteger param, int size, int* data); + unsafe static void GetInteger(IntPtr device, AlcGetInteger param, int size, int* data) => GetInteger_dptr(device, param, size, data); + private static GetInteger_d GetInteger_dptr = AL.ALNativeLib.LoadFunctionPointer("alcGetIntegerv"); + private unsafe delegate void GetInteger_d(IntPtr device, AlcGetInteger param, int size, int* data); // ALC_API void ALC_APIENTRY alcGetIntegerv( ALCdevice *device, ALCenum param, ALCsizei size, ALCint *buffer ); /// This function returns integers related to the context. @@ -348,46 +360,44 @@ namespace OpenTK.Audio.OpenAL /// the requested capture buffer format. /// the size of the capture buffer in samples, not bytes. /// Returns the capture device pointer, or NULL on failure. - [CLSCompliant(false), DllImport(Alc.Lib, EntryPoint = "alcCaptureOpenDevice", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - public static extern IntPtr CaptureOpenDevice(string devicename, uint frequency, ALFormat format, int buffersize); + public static IntPtr CaptureOpenDevice(string devicename, uint frequency, ALFormat format, int buffersize) => CaptureOpenDevice_dptr(devicename, frequency, format, buffersize); + private static CaptureOpenDevice_d CaptureOpenDevice_dptr = AL.ALNativeLib.LoadFunctionPointer("alcCaptureOpenDevice"); + private delegate IntPtr CaptureOpenDevice_d(string devicename, uint frequency, ALFormat format, int buffersize); - /// This function opens a capture device by name. - /// a pointer to a device name string. - /// the frequency that the buffer should be captured at. - /// the requested capture buffer format. - /// the size of the capture buffer in samples, not bytes. - /// Returns the capture device pointer, or NULL on failure. - [DllImport(Alc.Lib, EntryPoint = "alcCaptureOpenDevice", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()] - public static extern IntPtr CaptureOpenDevice(string devicename, int frequency, ALFormat format, int buffersize); - - // ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice( const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize ); + public static IntPtr CaptureOpenDevice(string devicename, int frequency, ALFormat format, int buffersize) => CaptureOpenDeviceS_dptr(devicename, frequency, format, buffersize); + private static CaptureOpenDeviceS_d CaptureOpenDeviceS_dptr = AL.ALNativeLib.LoadFunctionPointer("alcCaptureOpenDevice"); + private delegate IntPtr CaptureOpenDeviceS_d(string devicename, int frequency, ALFormat format, int buffersize); /// This function closes the specified capture device. /// a pointer to a capture device. /// Returns True if the close operation was successful, False on failure. - [DllImport(Alc.Lib, EntryPoint = "alcCaptureCloseDevice", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - public static extern bool CaptureCloseDevice([In] IntPtr device); + public static bool CaptureCloseDevice([In] IntPtr device) => CaptureCloseDevice_dptr(device); + private static CaptureCloseDevice_d CaptureCloseDevice_dptr = AL.ALNativeLib.LoadFunctionPointer("alcCaptureCloseDevice"); + private delegate bool CaptureCloseDevice_d([In] IntPtr device); // ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice( ALCdevice *device ); /// This function begins a capture operation. /// alcCaptureStart will begin recording to an internal ring buffer of the size specified when opening the capture device. The application can then retrieve the number of samples currently available using the ALC_CAPTURE_SAPMPLES token with alcGetIntegerv. When the application determines that enough samples are available for processing, then it can obtain them with a call to alcCaptureSamples. /// a pointer to a capture device. - [DllImport(Alc.Lib, EntryPoint = "alcCaptureStart", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - public static extern void CaptureStart([In] IntPtr device); + public static void CaptureStart([In] IntPtr device) => CaptureStart_dptr(device); + private static CaptureStart_d CaptureStart_dptr = AL.ALNativeLib.LoadFunctionPointer("alcCaptureStart"); + private delegate void CaptureStart_d([In] IntPtr device); // ALC_API void ALC_APIENTRY alcCaptureStart( ALCdevice *device ); /// This function stops a capture operation. /// a pointer to a capture device. - [DllImport(Alc.Lib, EntryPoint = "alcCaptureStop", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - public static extern void CaptureStop([In] IntPtr device); + public static void CaptureStop([In] IntPtr device) => CaptureStop_dptr(device); + private static CaptureStop_d CaptureStop_dptr = AL.ALNativeLib.LoadFunctionPointer("alcCaptureStop"); + private delegate void CaptureStop_d([In] IntPtr device); // ALC_API void ALC_APIENTRY alcCaptureStop( ALCdevice *device ); /// This function completes a capture operation, and does not block. /// a pointer to a capture device. /// a pointer to a buffer, which must be large enough to accommodate the number of samples. /// the number of samples to be retrieved. - [DllImport(Alc.Lib, EntryPoint = "alcCaptureSamples", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()] - public static extern void CaptureSamples(IntPtr device, IntPtr buffer, int samples); + public static void CaptureSamples(IntPtr device, IntPtr buffer, int samples) => CaptureSamples_dptr(device, buffer, samples); + private static CaptureSamples_d CaptureSamples_dptr = AL.ALNativeLib.LoadFunctionPointer("alcCaptureSamples"); + private delegate void CaptureSamples_d(IntPtr device, IntPtr buffer, int samples); // ALC_API void ALC_APIENTRY alcCaptureSamples( ALCdevice *device, ALCvoid *buffer, ALCsizei samples ); /// This function completes a capture operation, and does not block. @@ -440,7 +450,5 @@ namespace OpenTK.Audio.OpenAL { CaptureSamples(device, ref buffer[0, 0, 0], samples); } - } - } \ No newline at end of file diff --git a/src/OpenTK/Platform/SDL2/Sdl2.cs b/src/OpenTK/Platform/SDL2/Sdl2.cs index a4d18f8f..ff946a42 100644 --- a/src/OpenTK/Platform/SDL2/Sdl2.cs +++ b/src/OpenTK/Platform/SDL2/Sdl2.cs @@ -402,9 +402,9 @@ namespace OpenTK.Platform.SDL2 public static JoystickGuid JoystickGetGUID(IntPtr joystick) => SDL_JoystickGetGUID_ptr(joystick); [SuppressUnmanagedCodeSecurity] - private delegate JoystickGuid SDL_JoystickInstanceID_d(IntPtr joystick); + private delegate int SDL_JoystickInstanceID_d(IntPtr joystick); private static SDL_JoystickInstanceID_d SDL_JoystickInstanceID_ptr = NativeLib.LoadFunctionPointer("SDL_JoystickInstanceID"); - public static JoystickGuid JoystickInstanceID(IntPtr joystick) => SDL_JoystickInstanceID_ptr(joystick); + public static int JoystickInstanceID(IntPtr joystick) => SDL_JoystickInstanceID_ptr(joystick); [SuppressUnmanagedCodeSecurity] private delegate IntPtr SDL_JoystickName_d(IntPtr joystick);