33 using System.Runtime.InteropServices;
40 public const string OpenAlDll =
"/System/Library/Frameworks/OpenAL.framework/OpenAL";
42 public const string OpenAlDll =
"libopenal.so.1";
45 public const string OpenAlDll =
"soft_oal_x86.dll";
47 public const string OpenAlDll =
"soft_oal_x64.dll";
59 public const int Pitch = 0x1003;
65 public const int Gain = 0x100A;
92 public const int Bits = 0x2002;
94 public const int Size = 0x2004;
123 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alEnable")]
124 public static extern void Enable(
int capability);
126 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alDisable")]
127 public static extern void Disable(
int capability);
129 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alIsEnabled")]
132 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetString")]
133 private static extern IntPtr _GetString(
int param);
135 public static string GetString(
int param) => Marshal.PtrToStringAnsi(_GetString(param));
137 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetBooleanv")]
140 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetIntegerv")]
143 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetFloatv")]
144 public static extern void GetFloatv(
int param, out
float data);
146 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetDoublev")]
147 public static extern void GetDoublev(
int param, out
double data);
149 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetBoolean")]
152 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetInteger")]
155 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetFloat")]
158 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetDouble")]
161 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetError")]
171 return "Invalid name";
173 return "Invalid enum";
175 return "Invalid value";
177 return "Invalid operation";
179 return "Out of memory";
181 return "Unknown error";
185 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alIsExtensionPresent")]
188 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetProcAddress")]
191 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetEnumValue")]
194 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alListenerf")]
195 public static extern void Listenerf(
int param,
float value);
197 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alListener3f")]
198 public static extern void Listener3f(
int param,
float value1,
float value2,
float value3);
200 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alListenerfv")]
201 public static extern void Listenerfv(
int param,
float[] values);
203 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetListenerf")]
206 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetListener3f")]
207 public static extern void GetListener3f(
int param, out
float value1, out
float value2, out
float value3);
209 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetListenerfv")]
210 private static extern void _GetListenerfv(
int param, IntPtr values);
232 values =
new float[len];
234 GCHandle arrayHandle = GCHandle.Alloc(values, GCHandleType.Pinned);
235 _GetListenerfv(param, arrayHandle.AddrOfPinnedObject());
239 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGenSources")]
240 private static extern void _GenSources(
int n, IntPtr sources);
244 sources =
new uint[n];
246 GCHandle arrayHandle = GCHandle.Alloc(sources, GCHandleType.Pinned);
247 _GenSources(n, arrayHandle.AddrOfPinnedObject());
257 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alDeleteSources")]
262 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alIsSource")]
265 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourcef")]
266 public static extern void Sourcef(uint sid,
int param,
float value);
268 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSource3f")]
269 public static extern void Source3f(uint sid,
int param,
float value1,
float value2,
float value3);
271 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourcefv")]
272 public static extern void Sourcefv(uint sid,
int param,
float[] values);
274 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourcei")]
275 public static extern void Sourcei(uint sid,
int param,
int value);
277 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSource3i")]
278 public static extern void Source3i(uint sid,
int param,
int value1,
int value2,
int value3);
280 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourceiv")]
281 public static extern void Sourceiv(uint sid,
int param,
int[] values);
283 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetSourcef")]
284 public static extern void GetSourcef(uint sid,
int param, out
float value);
286 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetSource3f")]
287 public static extern void GetSource3f(uint sid,
int param, out
float value1, out
float value2, out
float value3);
289 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetSourcefv")]
290 private static extern void _GetSourcefv(uint sid,
int param, IntPtr values);
292 public static void GetSourcefv(uint sid,
int param, out
float[] values)
322 values =
new float[len];
324 GCHandle arrayHandle = GCHandle.Alloc(values, GCHandleType.Pinned);
325 _GetSourcefv(sid, param, arrayHandle.AddrOfPinnedObject());
329 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetSourcei")]
330 public static extern void GetSourcei(uint sid,
int param, out
int value);
332 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetSource3i")]
333 public static extern void GetSource3i(uint sid,
int param, out
int value1, out
int value2, out
int value3);
335 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetSourceiv")]
336 private static extern void _GetSourceiv(uint sid,
int param, IntPtr values);
338 public static void GetSourceiv(uint sid,
int param, out
int[] values)
368 values =
new int[len];
370 GCHandle arrayHandle = GCHandle.Alloc(values, GCHandleType.Pinned);
371 _GetSourceiv(sid, param, arrayHandle.AddrOfPinnedObject());
375 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourcePlayv")]
378 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourceStopv")]
381 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourceRewindv")]
384 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourcePausev")]
387 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourcePlay")]
390 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourceStop")]
393 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourceRewind")]
396 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourcePause")]
399 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourceQueueBuffers")]
404 uint[] bids =
new uint[1]; bids[0] = bid;
408 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSourceUnqueueBuffers")]
411 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGenBuffers")]
412 private static extern void _GenBuffers(
int n, IntPtr buffers);
416 buffers =
new uint[n];
418 GCHandle arrayHandle = GCHandle.Alloc(buffers, GCHandleType.Pinned);
419 _GenBuffers(n, arrayHandle.AddrOfPinnedObject());
429 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alDeleteBuffers")]
434 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alIsBuffer")]
437 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alBufferData")]
438 public static extern void BufferData(uint bid,
int format, IntPtr data,
int size,
int freq);
440 public static void BufferData<T>(uint bid,
int format, T[] data,
int len,
int freq)
442 GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
443 BufferData(bid, format, handle.AddrOfPinnedObject(), len, freq);
447 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alBufferi")]
448 public static extern void Bufferi(uint bid,
int param,
int value);
450 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alGetBufferi")]
451 public static extern void GetBufferi(uint bid,
int param, out
int value);
453 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alDopplerFactor")]
456 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alDopplerVelocity")]
459 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alSpeedOfSound")]
462 [DllImport(OpenAlDll, CallingConvention = CallingConvention.Cdecl, EntryPoint =
"alDistanceModel")]
static void SourcePlayv(int ns, uint[] sids)
static void GetSource3f(uint sid, int param, out float value1, out float value2, out float value3)
static void GetListenerf(int param, out float value)
static void Sourcefv(uint sid, int param, float[] values)
const int LinearDistanceClamped
static void DeleteBuffer(uint buffer)
static void GetIntegerv(int param, out int data)
static void SourceStopv(int ns, uint[] sids)
static void GetSourcei(uint sid, int param, out int value)
static bool GetBoolean(int param)
static int GetInteger(int param)
const int EnumDopplerFactor
static void Listener3f(int param, float value1, float value2, float value3)
static void Listenerfv(int param, float[] values)
static void GetFloatv(int param, out float data)
static void GetListenerfv(int param, out float[] values)
static bool IsSource(uint sid)
static void Enable(int capability)
static bool IsBuffer(uint bid)
static void SourceQueueBuffer(uint sid, uint bid)
static void Sourcef(uint sid, int param, float value)
static void GenSources(int n, out uint[] sources)
const int ExponentDistance
static void SourcePausev(int ns, uint[] sids)
static void DeleteSource(uint source)
static void GetSource3i(uint sid, int param, out int value1, out int value2, out int value3)
static void GetSourcefv(uint sid, int param, out float[] values)
static void DeleteBuffers(int n, uint[] buffers)
static void GenBuffer(out uint buffer)
static void Bufferi(uint bid, int param, int value)
static void Listenerf(int param, float value)
static void SourcePlay(uint sid)
static IntPtr GetProcAddress(string fname)
static void SourceQueueBuffers(uint sid, int numEntries, uint[] bids)
const int ReferenceDistance
const int BuffersProcessed
static void Source3i(uint sid, int param, int value1, int value2, int value3)
static void GetBufferi(uint bid, int param, out int value)
static void SourceStop(uint sid)
static void BufferData< T >(uint bid, int format, T[] data, int len, int freq)
const int InvalidOperation
static void GetListener3f(int param, out float value1, out float value2, out float value3)
static double GetDouble(int param)
const int InverseDistanceClamped
static string GetErrorString(int error)
static void DeleteSources(int n, uint[] sources)
static void SourceRewind(uint sid)
static void Disable(int capability)
static void GenSource(out uint source)
static void Sourcei(uint sid, int param, int value)
static void DistanceModel(int distanceModel)
static void BufferData(uint bid, int format, IntPtr data, int size, int freq)
static void Source3f(uint sid, int param, float value1, float value2, float value3)
static void GetDoublev(int param, out double data)
static bool IsExtensionPresent(string extname)
const int EnumSpeedOfSound
static void SourcePause(uint sid)
static void DopplerFactor(float value)
const int ExponentDistanceClamped
static int GetEnumValue(string ename)
static void SourceRewindv(int ns, uint[] sids)
static bool IsEnabled(int capability)
static void GetBooleanv(int param, out bool data)
static string GetString(int param)
static void SpeedOfSound(float value)
static void GetSourceiv(uint sid, int param, out int[] values)
const int EnumDistanceModel
static void DopplerVelocity(float value)
static void SourceUnqueueBuffers(uint sid, int numEntries, uint[] bids)
static float GetFloat(int param)
static void GenBuffers(int n, out uint[] buffers)
static void Sourceiv(uint sid, int param, int[] values)
const int InverseDistance
static void GetSourcef(uint sid, int param, out float value)
const int EnumDopplerVelocity