00001 #region --- OpenTK.OpenAL License ---
00002
00003
00004
00005
00006
00007
00008 #endregion
00009
00010 using System;
00011 using System.Collections.Generic;
00012 using System.Runtime.InteropServices;
00013 using System.Security;
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 namespace OpenTK.Audio.OpenAL
00070 {
00071
00073 public static class Alc
00074 {
00075 #region Constants
00076
00077 private const string Lib = AL.Lib;
00078 private const CallingConvention Style = CallingConvention.Cdecl;
00079
00080 #endregion Constants
00081
00082 #region Context Management
00083
00084 #region CreateContext
00085
00086 [DllImport(Alc.Lib, EntryPoint = "alcCreateContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity]
00087 unsafe static extern IntPtr sys_CreateContext([In] IntPtr device, [In] int* attrlist);
00088
00093 [CLSCompliant(false)]
00094 unsafe public static ContextHandle CreateContext([In] IntPtr device, [In] int* attrlist)
00095 {
00096 return new ContextHandle(sys_CreateContext(device, attrlist));
00097 }
00098
00099
00100
00106 public static ContextHandle CreateContext(IntPtr device, int[] attriblist)
00107 {
00108 unsafe
00109 {
00110 fixed (int* attriblist_ptr = attriblist)
00111 {
00112 return CreateContext(device, attriblist_ptr);
00113 }
00114 }
00115 }
00116
00117 #endregion
00118
00119 [DllImport(Alc.Lib, EntryPoint = "alcMakeContextCurrent", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00120 static extern bool MakeContextCurrent(IntPtr context);
00121
00125 public static bool MakeContextCurrent(ContextHandle context)
00126 {
00127 return MakeContextCurrent(context.Handle);
00128 }
00129
00130
00131 [DllImport(Alc.Lib, EntryPoint = "alcProcessContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00132 static extern void ProcessContext(IntPtr context);
00133
00136 public static void ProcessContext(ContextHandle context)
00137 {
00138 ProcessContext(context.Handle);
00139 }
00140
00141
00142 [DllImport(Alc.Lib, EntryPoint = "alcSuspendContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00143 static extern void SuspendContext(IntPtr context);
00144
00147 public static void SuspendContext(ContextHandle context)
00148 {
00149 SuspendContext(context.Handle);
00150 }
00151
00152
00153 [DllImport(Alc.Lib, EntryPoint = "alcDestroyContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00154 static extern void DestroyContext(IntPtr context);
00155
00158 public static void DestroyContext(ContextHandle context)
00159 {
00160 DestroyContext(context.Handle);
00161 }
00162
00163
00164 [DllImport(Alc.Lib, EntryPoint = "alcGetCurrentContext", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00165 private static extern IntPtr sys_GetCurrentContext();
00166
00169 public static ContextHandle GetCurrentContext()
00170 {
00171 return new ContextHandle(sys_GetCurrentContext());
00172 }
00173
00174
00175 [DllImport(Alc.Lib, EntryPoint = "alcGetContextsDevice", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00176 static extern IntPtr GetContextsDevice(IntPtr context);
00177
00181 public static IntPtr GetContextsDevice(ContextHandle context)
00182 {
00183 return GetContextsDevice(context.Handle);
00184 }
00185
00186
00187 #endregion Context Management
00188
00189 #region Device Management
00190
00194 [DllImport(Alc.Lib, EntryPoint = "alcOpenDevice", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
00195 public static extern IntPtr OpenDevice([In] string devicename);
00196
00197
00201 [DllImport(Alc.Lib, EntryPoint = "alcCloseDevice", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00202 public static extern bool CloseDevice([In] IntPtr device);
00203
00204
00205 #endregion Device Management
00206
00207 #region Error support.
00208
00212 [DllImport(Alc.Lib, EntryPoint = "alcGetError", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00213 public static extern AlcError GetError([In] IntPtr device);
00214
00215
00216 #endregion Error support.
00217
00218 #region Extension support.
00219
00224 [DllImport(Alc.Lib, EntryPoint = "alcIsExtensionPresent", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
00225 public static extern bool IsExtensionPresent([In] IntPtr device, [In] string extname);
00226
00227
00232 [DllImport(Alc.Lib, EntryPoint = "alcGetProcAddress", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
00233 public static extern IntPtr GetProcAddress([In] IntPtr device, [In] string funcname);
00234
00235
00240 [DllImport(Alc.Lib, EntryPoint = "alcGetEnumValue", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
00241 public static extern int GetEnumValue([In] IntPtr device, [In] string enumname);
00242
00243
00244 #endregion Extension support.
00245
00246 #region Query functions
00247
00248 [DllImport(Alc.Lib, EntryPoint = "alcGetString", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
00249 private static extern IntPtr GetStringPrivate([In] IntPtr device, AlcGetString param);
00250
00251
00263 public static string GetString(IntPtr device, AlcGetString param)
00264 {
00265 return Marshal.PtrToStringAnsi(GetStringPrivate(device, param));
00266 }
00267
00277 public static IList<string> GetString(IntPtr device, AlcGetStringList param)
00278 {
00279 List<string> result = new List<string>();
00280 IntPtr t = GetStringPrivate(IntPtr.Zero, (AlcGetString)param);
00281 System.Text.StringBuilder sb = new System.Text.StringBuilder();
00282 byte b;
00283 int offset = 0;
00284 do
00285 {
00286 b = Marshal.ReadByte(t, offset++);
00287 if (b != 0)
00288 sb.Append((char)b);
00289 if (b == 0)
00290 {
00291 result.Add(sb.ToString());
00292 if (Marshal.ReadByte(t, offset) == 0)
00293 break;
00294 else
00295 sb.Remove(0, sb.Length);
00296 }
00297 } while (true);
00298
00299 return (IList<string>)result;
00300 }
00301
00302 [DllImport(Alc.Lib, EntryPoint = "alcGetIntegerv", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
00303 unsafe static extern void GetInteger(IntPtr device, AlcGetInteger param, int size, int* data);
00304
00305
00311 public static void GetInteger(IntPtr device, AlcGetInteger param, int size, out int data)
00312 {
00313 unsafe
00314 {
00315 fixed (int* data_ptr = &data)
00316 {
00317 GetInteger(device, param, size, data_ptr);
00318 }
00319 }
00320 }
00321
00327 public static void GetInteger(IntPtr device, AlcGetInteger param, int size, int[] data)
00328 {
00329 unsafe
00330 {
00331 fixed (int* data_ptr = data)
00332 {
00333 GetInteger(device, param, size, data_ptr);
00334 }
00335 }
00336 }
00337
00338 #endregion Query functions
00339
00340 #region Capture functions
00341
00348 [CLSCompliant(false), DllImport(Alc.Lib, EntryPoint = "alcCaptureOpenDevice", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
00349 public static extern IntPtr CaptureOpenDevice(string devicename, uint frequency, ALFormat format, int buffersize);
00350
00357 [DllImport(Alc.Lib, EntryPoint = "alcCaptureOpenDevice", ExactSpelling = true, CallingConvention = Alc.Style, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity()]
00358 public static extern IntPtr CaptureOpenDevice(string devicename, int frequency, ALFormat format, int buffersize);
00359
00360
00361
00365 [DllImport(Alc.Lib, EntryPoint = "alcCaptureCloseDevice", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00366 public static extern bool CaptureCloseDevice([In] IntPtr device);
00367
00368
00372 [DllImport(Alc.Lib, EntryPoint = "alcCaptureStart", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00373 public static extern void CaptureStart([In] IntPtr device);
00374
00375
00378 [DllImport(Alc.Lib, EntryPoint = "alcCaptureStop", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00379 public static extern void CaptureStop([In] IntPtr device);
00380
00381
00386 [DllImport(Alc.Lib, EntryPoint = "alcCaptureSamples", ExactSpelling = true, CallingConvention = Alc.Style), SuppressUnmanagedCodeSecurity()]
00387 public static extern void CaptureSamples(IntPtr device, IntPtr buffer, int samples);
00388
00389
00394 public static void CaptureSamples<T>(IntPtr device, ref T buffer, int samples)
00395 where T : struct
00396 {
00397 GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
00398 try
00399 {
00400 CaptureSamples(device, handle.AddrOfPinnedObject(), samples);
00401 }
00402 finally
00403 {
00404 handle.Free();
00405 }
00406 }
00407
00412 public static void CaptureSamples<T>(IntPtr device, T[] buffer, int samples)
00413 where T : struct
00414 {
00415 CaptureSamples(device, ref buffer[0], samples);
00416 }
00417
00422 public static void CaptureSamples<T>(IntPtr device, T[,] buffer, int samples)
00423 where T : struct
00424 {
00425 CaptureSamples(device, ref buffer[0, 0], samples);
00426 }
00427
00432 public static void CaptureSamples<T>(IntPtr device, T[, ,] buffer, int samples)
00433 where T : struct
00434 {
00435 CaptureSamples(device, ref buffer[0, 0, 0], samples);
00436 }
00437
00438 #endregion Capture functions
00439
00440 }
00441
00442 }