t1 / TFDContents / Assets / Standard Assets / Windows / Kinect / AudioSource.cs @ 9
이력 | 보기 | 이력해설 | 다운로드 (18.1 KB)
| 1 | 3 | KTH | #if !(UNITY_WSA_10_0 && NETFX_CORE) |
|---|---|---|---|
| 2 | using RootSystem = System; |
||
| 3 | using System.Linq; |
||
| 4 | using System.Collections.Generic; |
||
| 5 | namespace Windows.Kinect |
||
| 6 | {
|
||
| 7 | // |
||
| 8 | // Windows.Kinect.AudioSource |
||
| 9 | // |
||
| 10 | public sealed partial class AudioSource : Helper.INativeWrapper |
||
| 11 | |||
| 12 | {
|
||
| 13 | internal RootSystem.IntPtr _pNative; |
||
| 14 | RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
|
||
| 15 | |||
| 16 | // Constructors and Finalizers |
||
| 17 | internal AudioSource(RootSystem.IntPtr pNative) |
||
| 18 | {
|
||
| 19 | _pNative = pNative; |
||
| 20 | Windows_Kinect_AudioSource_AddRefObject(ref _pNative); |
||
| 21 | } |
||
| 22 | |||
| 23 | ~AudioSource() |
||
| 24 | {
|
||
| 25 | Dispose(false); |
||
| 26 | } |
||
| 27 | |||
| 28 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 29 | private static extern void Windows_Kinect_AudioSource_ReleaseObject(ref RootSystem.IntPtr pNative); |
||
| 30 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 31 | private static extern void Windows_Kinect_AudioSource_AddRefObject(ref RootSystem.IntPtr pNative); |
||
| 32 | private void Dispose(bool disposing) |
||
| 33 | {
|
||
| 34 | if (_pNative == RootSystem.IntPtr.Zero) |
||
| 35 | {
|
||
| 36 | return; |
||
| 37 | } |
||
| 38 | |||
| 39 | __EventCleanup(); |
||
| 40 | |||
| 41 | Helper.NativeObjectCache.RemoveObject<AudioSource>(_pNative); |
||
| 42 | Windows_Kinect_AudioSource_ReleaseObject(ref _pNative); |
||
| 43 | |||
| 44 | _pNative = RootSystem.IntPtr.Zero; |
||
| 45 | } |
||
| 46 | |||
| 47 | |||
| 48 | // Public Properties |
||
| 49 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 50 | private static extern int Windows_Kinect_AudioSource_get_AudioBeams(RootSystem.IntPtr pNative, [RootSystem.Runtime.InteropServices.Out] RootSystem.IntPtr[] outCollection, int outCollectionSize); |
||
| 51 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 52 | private static extern int Windows_Kinect_AudioSource_get_AudioBeams_Length(RootSystem.IntPtr pNative); |
||
| 53 | public RootSystem.Collections.Generic.IList<Windows.Kinect.AudioBeam> AudioBeams |
||
| 54 | {
|
||
| 55 | get |
||
| 56 | {
|
||
| 57 | if (_pNative == RootSystem.IntPtr.Zero) |
||
| 58 | {
|
||
| 59 | throw new RootSystem.ObjectDisposedException("AudioSource");
|
||
| 60 | } |
||
| 61 | |||
| 62 | int outCollectionSize = Windows_Kinect_AudioSource_get_AudioBeams_Length(_pNative); |
||
| 63 | var outCollection = new RootSystem.IntPtr[outCollectionSize]; |
||
| 64 | var managedCollection = new Windows.Kinect.AudioBeam[outCollectionSize]; |
||
| 65 | |||
| 66 | outCollectionSize = Windows_Kinect_AudioSource_get_AudioBeams(_pNative, outCollection, outCollectionSize); |
||
| 67 | Helper.ExceptionHelper.CheckLastError(); |
||
| 68 | for(int i=0;i<outCollectionSize;i++) |
||
| 69 | {
|
||
| 70 | if(outCollection[i] == RootSystem.IntPtr.Zero) |
||
| 71 | {
|
||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | var obj = Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.AudioBeam>(outCollection[i], n => new Windows.Kinect.AudioBeam(n)); |
||
| 76 | |||
| 77 | managedCollection[i] = obj; |
||
| 78 | } |
||
| 79 | return managedCollection; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 84 | private static extern bool Windows_Kinect_AudioSource_get_IsActive(RootSystem.IntPtr pNative); |
||
| 85 | public bool IsActive |
||
| 86 | {
|
||
| 87 | get |
||
| 88 | {
|
||
| 89 | if (_pNative == RootSystem.IntPtr.Zero) |
||
| 90 | {
|
||
| 91 | throw new RootSystem.ObjectDisposedException("AudioSource");
|
||
| 92 | } |
||
| 93 | |||
| 94 | return Windows_Kinect_AudioSource_get_IsActive(_pNative); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 99 | private static extern RootSystem.IntPtr Windows_Kinect_AudioSource_get_KinectSensor(RootSystem.IntPtr pNative); |
||
| 100 | public Windows.Kinect.KinectSensor KinectSensor |
||
| 101 | {
|
||
| 102 | get |
||
| 103 | {
|
||
| 104 | if (_pNative == RootSystem.IntPtr.Zero) |
||
| 105 | {
|
||
| 106 | throw new RootSystem.ObjectDisposedException("AudioSource");
|
||
| 107 | } |
||
| 108 | |||
| 109 | RootSystem.IntPtr objectPointer = Windows_Kinect_AudioSource_get_KinectSensor(_pNative); |
||
| 110 | Helper.ExceptionHelper.CheckLastError(); |
||
| 111 | if (objectPointer == RootSystem.IntPtr.Zero) |
||
| 112 | {
|
||
| 113 | return null; |
||
| 114 | } |
||
| 115 | |||
| 116 | return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectSensor>(objectPointer, n => new Windows.Kinect.KinectSensor(n)); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 121 | private static extern uint Windows_Kinect_AudioSource_get_MaxSubFrameCount(RootSystem.IntPtr pNative); |
||
| 122 | public uint MaxSubFrameCount |
||
| 123 | {
|
||
| 124 | get |
||
| 125 | {
|
||
| 126 | if (_pNative == RootSystem.IntPtr.Zero) |
||
| 127 | {
|
||
| 128 | throw new RootSystem.ObjectDisposedException("AudioSource");
|
||
| 129 | } |
||
| 130 | |||
| 131 | return Windows_Kinect_AudioSource_get_MaxSubFrameCount(_pNative); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 136 | private static extern long Windows_Kinect_AudioSource_get_SubFrameDuration(RootSystem.IntPtr pNative); |
||
| 137 | public RootSystem.TimeSpan SubFrameDuration |
||
| 138 | {
|
||
| 139 | get |
||
| 140 | {
|
||
| 141 | if (_pNative == RootSystem.IntPtr.Zero) |
||
| 142 | {
|
||
| 143 | throw new RootSystem.ObjectDisposedException("AudioSource");
|
||
| 144 | } |
||
| 145 | |||
| 146 | return RootSystem.TimeSpan.FromMilliseconds(Windows_Kinect_AudioSource_get_SubFrameDuration(_pNative)); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 151 | private static extern uint Windows_Kinect_AudioSource_get_SubFrameLengthInBytes(RootSystem.IntPtr pNative); |
||
| 152 | public uint SubFrameLengthInBytes |
||
| 153 | {
|
||
| 154 | get |
||
| 155 | {
|
||
| 156 | if (_pNative == RootSystem.IntPtr.Zero) |
||
| 157 | {
|
||
| 158 | throw new RootSystem.ObjectDisposedException("AudioSource");
|
||
| 159 | } |
||
| 160 | |||
| 161 | return Windows_Kinect_AudioSource_get_SubFrameLengthInBytes(_pNative); |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 166 | private static extern Windows.Kinect.KinectAudioCalibrationState Windows_Kinect_AudioSource_get_AudioCalibrationState(RootSystem.IntPtr pNative); |
||
| 167 | public Windows.Kinect.KinectAudioCalibrationState AudioCalibrationState |
||
| 168 | {
|
||
| 169 | get |
||
| 170 | {
|
||
| 171 | if (_pNative == RootSystem.IntPtr.Zero) |
||
| 172 | {
|
||
| 173 | throw new RootSystem.ObjectDisposedException("AudioSource");
|
||
| 174 | } |
||
| 175 | |||
| 176 | return Windows_Kinect_AudioSource_get_AudioCalibrationState(_pNative); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | |||
| 181 | // Events |
||
| 182 | private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle; |
||
| 183 | [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)] |
||
| 184 | private delegate void _Windows_Kinect_FrameCapturedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative); |
||
| 185 | private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>>> Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>>>(); |
||
| 186 | [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Kinect_FrameCapturedEventArgs_Delegate))] |
||
| 187 | private static void Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative) |
||
| 188 | {
|
||
| 189 | List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>> callbackList = null; |
||
| 190 | Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList); |
||
| 191 | lock(callbackList) |
||
| 192 | {
|
||
| 193 | var objThis = Helper.NativeObjectCache.GetObject<AudioSource>(pNative); |
||
| 194 | var args = new Windows.Kinect.FrameCapturedEventArgs(result); |
||
| 195 | foreach(var func in callbackList) |
||
| 196 | {
|
||
| 197 | Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
|
||
| 198 | } |
||
| 199 | } |
||
| 200 | } |
||
| 201 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 202 | private static extern void Windows_Kinect_AudioSource_add_FrameCaptured(RootSystem.IntPtr pNative, _Windows_Kinect_FrameCapturedEventArgs_Delegate eventCallback, bool unsubscribe); |
||
| 203 | public event RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs> FrameCaptured |
||
| 204 | {
|
||
| 205 | add |
||
| 206 | {
|
||
| 207 | Helper.EventPump.EnsureInitialized(); |
||
| 208 | |||
| 209 | Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
| 210 | var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative]; |
||
| 211 | lock (callbackList) |
||
| 212 | {
|
||
| 213 | callbackList.Add(value); |
||
| 214 | if(callbackList.Count == 1) |
||
| 215 | {
|
||
| 216 | var del = new _Windows_Kinect_FrameCapturedEventArgs_Delegate(Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler); |
||
| 217 | _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del); |
||
| 218 | Windows_Kinect_AudioSource_add_FrameCaptured(_pNative, del, false); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | } |
||
| 222 | remove |
||
| 223 | {
|
||
| 224 | if (_pNative == RootSystem.IntPtr.Zero) |
||
| 225 | {
|
||
| 226 | return; |
||
| 227 | } |
||
| 228 | |||
| 229 | Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
| 230 | var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative]; |
||
| 231 | lock (callbackList) |
||
| 232 | {
|
||
| 233 | callbackList.Remove(value); |
||
| 234 | if(callbackList.Count == 0) |
||
| 235 | {
|
||
| 236 | Windows_Kinect_AudioSource_add_FrameCaptured(_pNative, Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler, true); |
||
| 237 | _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle.Free(); |
||
| 238 | } |
||
| 239 | } |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Data_PropertyChangedEventArgs_Delegate_Handle; |
||
| 244 | [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)] |
||
| 245 | private delegate void _Windows_Data_PropertyChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative); |
||
| 246 | private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>>> Windows_Data_PropertyChangedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>>>(); |
||
| 247 | [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Data_PropertyChangedEventArgs_Delegate))] |
||
| 248 | private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative) |
||
| 249 | {
|
||
| 250 | List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>> callbackList = null; |
||
| 251 | Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList); |
||
| 252 | lock(callbackList) |
||
| 253 | {
|
||
| 254 | var objThis = Helper.NativeObjectCache.GetObject<AudioSource>(pNative); |
||
| 255 | var args = new Windows.Data.PropertyChangedEventArgs(result); |
||
| 256 | foreach(var func in callbackList) |
||
| 257 | {
|
||
| 258 | Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
|
||
| 259 | } |
||
| 260 | } |
||
| 261 | } |
||
| 262 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 263 | private static extern void Windows_Kinect_AudioSource_add_PropertyChanged(RootSystem.IntPtr pNative, _Windows_Data_PropertyChangedEventArgs_Delegate eventCallback, bool unsubscribe); |
||
| 264 | public event RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs> PropertyChanged |
||
| 265 | {
|
||
| 266 | add |
||
| 267 | {
|
||
| 268 | Helper.EventPump.EnsureInitialized(); |
||
| 269 | |||
| 270 | Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
| 271 | var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative]; |
||
| 272 | lock (callbackList) |
||
| 273 | {
|
||
| 274 | callbackList.Add(value); |
||
| 275 | if(callbackList.Count == 1) |
||
| 276 | {
|
||
| 277 | var del = new _Windows_Data_PropertyChangedEventArgs_Delegate(Windows_Data_PropertyChangedEventArgs_Delegate_Handler); |
||
| 278 | _Windows_Data_PropertyChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del); |
||
| 279 | Windows_Kinect_AudioSource_add_PropertyChanged(_pNative, del, false); |
||
| 280 | } |
||
| 281 | } |
||
| 282 | } |
||
| 283 | remove |
||
| 284 | {
|
||
| 285 | if (_pNative == RootSystem.IntPtr.Zero) |
||
| 286 | {
|
||
| 287 | return; |
||
| 288 | } |
||
| 289 | |||
| 290 | Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
| 291 | var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative]; |
||
| 292 | lock (callbackList) |
||
| 293 | {
|
||
| 294 | callbackList.Remove(value); |
||
| 295 | if(callbackList.Count == 0) |
||
| 296 | {
|
||
| 297 | Windows_Kinect_AudioSource_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true); |
||
| 298 | _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free(); |
||
| 299 | } |
||
| 300 | } |
||
| 301 | } |
||
| 302 | } |
||
| 303 | |||
| 304 | |||
| 305 | // Public Methods |
||
| 306 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
||
| 307 | private static extern RootSystem.IntPtr Windows_Kinect_AudioSource_OpenReader(RootSystem.IntPtr pNative); |
||
| 308 | public Windows.Kinect.AudioBeamFrameReader OpenReader() |
||
| 309 | {
|
||
| 310 | if (_pNative == RootSystem.IntPtr.Zero) |
||
| 311 | {
|
||
| 312 | throw new RootSystem.ObjectDisposedException("AudioSource");
|
||
| 313 | } |
||
| 314 | |||
| 315 | RootSystem.IntPtr objectPointer = Windows_Kinect_AudioSource_OpenReader(_pNative); |
||
| 316 | Helper.ExceptionHelper.CheckLastError(); |
||
| 317 | if (objectPointer == RootSystem.IntPtr.Zero) |
||
| 318 | {
|
||
| 319 | return null; |
||
| 320 | } |
||
| 321 | |||
| 322 | return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.AudioBeamFrameReader>(objectPointer, n => new Windows.Kinect.AudioBeamFrameReader(n)); |
||
| 323 | } |
||
| 324 | |||
| 325 | private void __EventCleanup() |
||
| 326 | {
|
||
| 327 | {
|
||
| 328 | Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
| 329 | var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative]; |
||
| 330 | lock (callbackList) |
||
| 331 | {
|
||
| 332 | if (callbackList.Count > 0) |
||
| 333 | {
|
||
| 334 | callbackList.Clear(); |
||
| 335 | if (_pNative != RootSystem.IntPtr.Zero) |
||
| 336 | {
|
||
| 337 | Windows_Kinect_AudioSource_add_FrameCaptured(_pNative, Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler, true); |
||
| 338 | } |
||
| 339 | _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle.Free(); |
||
| 340 | } |
||
| 341 | } |
||
| 342 | } |
||
| 343 | {
|
||
| 344 | Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
| 345 | var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative]; |
||
| 346 | lock (callbackList) |
||
| 347 | {
|
||
| 348 | if (callbackList.Count > 0) |
||
| 349 | {
|
||
| 350 | callbackList.Clear(); |
||
| 351 | if (_pNative != RootSystem.IntPtr.Zero) |
||
| 352 | {
|
||
| 353 | Windows_Kinect_AudioSource_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true); |
||
| 354 | } |
||
| 355 | _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free(); |
||
| 356 | } |
||
| 357 | } |
||
| 358 | } |
||
| 359 | } |
||
| 360 | } |
||
| 361 | |||
| 362 | } |
||
| 363 | #endif |