com.shinolab.autd3-sdk.pattern 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Ops.cs CHANGED
@@ -1,4 +1,5 @@
1
1
  using System;
2
+ using System.Runtime.InteropServices;
2
3
 
3
4
  namespace AUTD3
4
5
  {
@@ -47,12 +48,13 @@ namespace AUTD3
47
48
 
48
49
  IntPtr ICommand.CreateOp()
49
50
  {
50
- var handles = new IntPtr[_patterns.Length];
51
+ var handles = new SafeHandle[_patterns.Length];
51
52
  for (var i = 0; i < _patterns.Length; i++)
52
53
  {
53
54
  handles[i] = _patterns[i].Handle;
54
55
  }
55
- return NativePattern.autd3_op_write_pattern_compressed((byte)_bank, _index, (byte)_format, handles, (UIntPtr)handles.Length);
56
+ using var lease = new HandleArray(handles);
57
+ return NativePattern.autd3_op_write_pattern_compressed((byte)_bank, _index, (byte)_format, lease.Pointers, (UIntPtr)lease.Pointers.Length);
56
58
  }
57
59
  }
58
60
 
@@ -126,7 +128,7 @@ namespace AUTD3
126
128
  var sampling = _config.CreateHandle();
127
129
  try
128
130
  {
129
- return NativePattern.autd3_op_config_foci_stm((byte)_bank, sampling, _size, _numFoci, _soundSpeed.MPerS, _loopBehavior.Rep);
131
+ return NativePattern.autd3_op_config_foci_stm((byte)_bank, sampling, _size, _numFoci, _soundSpeed.MS, _loopBehavior.Rep);
130
132
  }
131
133
  finally
132
134
  {
package/Pattern.cs CHANGED
@@ -90,98 +90,111 @@ namespace AUTD3
90
90
  NativeAbi.Verify(ClientLib, autd3capi_abi_version());
91
91
  }
92
92
 
93
- [DllImport(Lib)]
93
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
94
94
  private static extern uint autd3_abi_version();
95
95
 
96
- [DllImport(ClientLib, EntryPoint = "autd3_abi_version")]
96
+ [DllImport(ClientLib, EntryPoint = "autd3_abi_version", CallingConvention = CallingConvention.Cdecl)]
97
97
  private static extern uint autd3capi_abi_version();
98
98
 
99
- [DllImport(Lib)]
99
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
100
100
  internal static extern float autd3_pattern_wavelength(float soundSpeedMmPerS);
101
101
 
102
- [DllImport(Lib)]
103
- internal static extern IntPtr autd3_core_geometry_pattern_buffer(IntPtr geometry);
102
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
103
+ internal static extern IntPtr autd3_core_geometry_pattern_buffer(GeometryHandle geometry);
104
104
 
105
- [DllImport(Lib)]
105
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
106
106
  internal static extern IntPtr autd3_pattern_buffer_from_array(EmissionNative[] emissions, UIntPtr numDevices);
107
107
 
108
- [DllImport(Lib)]
109
- internal static extern UIntPtr autd3_pattern_buffer_num_devices(IntPtr buffer);
108
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
109
+ internal static extern UIntPtr autd3_pattern_buffer_num_devices(PatternBufferHandle buffer);
110
110
 
111
- [DllImport(Lib)]
112
- internal static extern UIntPtr autd3_pattern_buffer_num_transducers(IntPtr buffer, UIntPtr dev);
111
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
112
+ internal static extern UIntPtr autd3_pattern_buffer_num_transducers(PatternBufferHandle buffer, UIntPtr dev);
113
113
 
114
- [DllImport(Lib)]
115
- internal static extern int autd3_pattern_buffer_get(IntPtr buffer, UIntPtr dev, UIntPtr tr, out EmissionNative @out);
114
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
115
+ internal static extern int autd3_pattern_buffer_get(PatternBufferHandle buffer, UIntPtr dev, UIntPtr tr, out EmissionNative @out);
116
116
 
117
- [DllImport(Lib)]
118
- internal static extern int autd3_pattern_buffer_set(IntPtr buffer, UIntPtr dev, UIntPtr tr, EmissionNative emission);
117
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
118
+ internal static extern int autd3_pattern_buffer_set(PatternBufferHandle buffer, UIntPtr dev, UIntPtr tr, EmissionNative emission);
119
119
 
120
- [DllImport(Lib)]
120
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
121
121
  internal static extern void autd3_pattern_buffer_free(IntPtr buffer);
122
122
 
123
- [DllImport(Lib)]
124
- internal static extern int autd3_pattern_focus(IntPtr geometry, float[] target, float wavelengthMm, in PatternOptionNative option, IntPtr buffer);
123
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
124
+ internal static extern int autd3_pattern_focus(GeometryHandle geometry, float[] target, float wavelengthMm, in PatternOptionNative option, PatternBufferHandle buffer);
125
125
 
126
- [DllImport(Lib)]
127
- internal static extern int autd3_pattern_focus_device(IntPtr geometry, UIntPtr dev, float[] target, float wavelengthMm, in PatternOptionNative option, [Out] EmissionNative[] dst);
126
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
127
+ internal static extern int autd3_pattern_focus_device(GeometryHandle geometry, UIntPtr dev, float[] target, float wavelengthMm, in PatternOptionNative option, [Out] EmissionNative[] dst);
128
128
 
129
- [DllImport(Lib)]
129
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
130
130
  internal static extern int autd3_pattern_focus_transducer(float[] position, float[] target, float wavelengthMm, in PatternOptionNative option, out EmissionNative @out);
131
131
 
132
- [DllImport(Lib)]
133
- internal static extern int autd3_pattern_plane(IntPtr geometry, float[] dir, float wavelengthMm, in PatternOptionNative option, IntPtr buffer);
132
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
133
+ internal static extern int autd3_pattern_plane(GeometryHandle geometry, float[] dir, float wavelengthMm, in PatternOptionNative option, PatternBufferHandle buffer);
134
134
 
135
- [DllImport(Lib)]
136
- internal static extern int autd3_pattern_plane_device(IntPtr geometry, UIntPtr dev, float[] dir, float wavelengthMm, in PatternOptionNative option, [Out] EmissionNative[] dst);
135
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
136
+ internal static extern int autd3_pattern_plane_device(GeometryHandle geometry, UIntPtr dev, float[] dir, float wavelengthMm, in PatternOptionNative option, [Out] EmissionNative[] dst);
137
137
 
138
- [DllImport(Lib)]
138
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
139
139
  internal static extern int autd3_pattern_plane_transducer(float[] position, float[] dir, float wavelengthMm, in PatternOptionNative option, out EmissionNative @out);
140
140
 
141
- [DllImport(Lib)]
142
- internal static extern int autd3_pattern_bessel(IntPtr geometry, float[] apex, float[] dir, float thetaRad, float wavelengthMm, in PatternOptionNative option, IntPtr buffer);
141
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
142
+ internal static extern int autd3_pattern_bessel(GeometryHandle geometry, float[] apex, float[] dir, float thetaRad, float wavelengthMm, in PatternOptionNative option, PatternBufferHandle buffer);
143
143
 
144
- [DllImport(Lib)]
145
- internal static extern int autd3_pattern_bessel_device(IntPtr geometry, UIntPtr dev, float[] apex, float[] dir, float thetaRad, float wavelengthMm, in PatternOptionNative option, [Out] EmissionNative[] dst);
144
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
145
+ internal static extern int autd3_pattern_bessel_device(GeometryHandle geometry, UIntPtr dev, float[] apex, float[] dir, float thetaRad, float wavelengthMm, in PatternOptionNative option, [Out] EmissionNative[] dst);
146
146
 
147
- [DllImport(Lib)]
147
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
148
148
  internal static extern int autd3_pattern_bessel_transducer(float[] position, float[] apex, float[] dir, float thetaRad, float wavelengthMm, in PatternOptionNative option, out EmissionNative @out);
149
149
 
150
- [DllImport(Lib)]
151
- internal static extern int autd3_pattern_uniform(byte phase, byte intensity, IntPtr buffer);
150
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
151
+ internal static extern int autd3_pattern_uniform(byte phase, byte intensity, PatternBufferHandle buffer);
152
152
 
153
- [DllImport(Lib)]
154
- internal static extern void autd3_pattern_null(IntPtr buffer);
153
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
154
+ internal static extern void autd3_pattern_null(PatternBufferHandle buffer);
155
155
 
156
156
 
157
- [DllImport(ClientLib)]
158
- internal static extern IntPtr autd3_op_pattern(byte bank, IntPtr patternBuffer, byte transitionMode, ulong transitionValue, uint transitionMarginNs);
157
+ [DllImport(ClientLib, CallingConvention = CallingConvention.Cdecl)]
158
+ internal static extern IntPtr autd3_op_pattern(byte bank, PatternBufferHandle patternBuffer, byte transitionMode, ulong transitionValue, uint transitionMarginNs);
159
159
 
160
- [DllImport(ClientLib)]
161
- internal static extern IntPtr autd3_op_write_pattern_buffer(byte bank, ushort index, IntPtr patternBuffer);
160
+ [DllImport(ClientLib, CallingConvention = CallingConvention.Cdecl)]
161
+ internal static extern IntPtr autd3_op_write_pattern_buffer(byte bank, ushort index, PatternBufferHandle patternBuffer);
162
162
 
163
- [DllImport(ClientLib)]
163
+ [DllImport(ClientLib, CallingConvention = CallingConvention.Cdecl)]
164
164
  internal static extern IntPtr autd3_op_write_pattern_compressed(byte bank, uint index, byte format, IntPtr[] patterns, UIntPtr numPatterns);
165
165
 
166
- [DllImport(ClientLib)]
166
+ [DllImport(ClientLib, CallingConvention = CallingConvention.Cdecl)]
167
167
  internal static extern IntPtr autd3_op_config_pattern(byte bank, IntPtr samplingConfig, uint size, ushort rep);
168
168
 
169
- [DllImport(ClientLib)]
169
+ [DllImport(ClientLib, CallingConvention = CallingConvention.Cdecl)]
170
170
  internal static extern IntPtr autd3_op_config_foci_stm(byte bank, IntPtr samplingConfig, uint size, byte numFoci, float soundSpeedMPerS, ushort rep);
171
171
 
172
- [DllImport(ClientLib)]
172
+ [DllImport(ClientLib, CallingConvention = CallingConvention.Cdecl)]
173
173
  internal static extern IntPtr autd3_op_change_pattern_bank(byte bank, byte transitionMode, ulong transitionValue, uint transitionMarginNs);
174
174
 
175
- [DllImport(ClientLib)]
175
+ [DllImport(ClientLib, CallingConvention = CallingConvention.Cdecl)]
176
176
  internal static extern int autd3_pattern_compression_per_frame(byte format, out UIntPtr @out);
177
177
  }
178
178
 
179
+ internal sealed class PatternBufferHandle : Autd3SafeHandle
180
+ {
181
+ internal PatternBufferHandle(IntPtr handle) : base(handle)
182
+ {
183
+ }
184
+
185
+ protected override bool ReleaseHandle()
186
+ {
187
+ NativePattern.autd3_pattern_buffer_free(handle);
188
+ return true;
189
+ }
190
+ }
191
+
179
192
  public readonly struct DevicePattern : IEnumerable<Emission>
180
193
  {
181
- private readonly IntPtr _buffer;
194
+ private readonly PatternBufferHandle _buffer;
182
195
  private readonly UIntPtr _dev;
183
196
 
184
- internal DevicePattern(IntPtr buffer, UIntPtr dev)
197
+ internal DevicePattern(PatternBufferHandle buffer, UIntPtr dev)
185
198
  {
186
199
  _buffer = buffer;
187
200
  _dev = dev;
@@ -221,9 +234,9 @@ namespace AUTD3
221
234
  {
222
235
  internal const int NumTransducers = 249;
223
236
 
224
- private IntPtr _handle;
237
+ private readonly PatternBufferHandle _handle;
225
238
 
226
- internal IntPtr Handle => _handle;
239
+ internal PatternBufferHandle Handle => _handle;
227
240
 
228
241
  internal PatternBuffer(IntPtr handle)
229
242
  {
@@ -231,7 +244,7 @@ namespace AUTD3
231
244
  {
232
245
  throw new Autd3Exception("failed to create pattern buffer");
233
246
  }
234
- _handle = handle;
247
+ _handle = new PatternBufferHandle(handle);
235
248
  }
236
249
 
237
250
  public static PatternBuffer FromArray(Emission[][] emissions)
@@ -279,24 +292,7 @@ namespace AUTD3
279
292
 
280
293
  IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
281
294
 
282
- public void Dispose()
283
- {
284
- var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
285
- if (handle != IntPtr.Zero)
286
- {
287
- NativePattern.autd3_pattern_buffer_free(handle);
288
- }
289
- GC.SuppressFinalize(this);
290
- }
291
-
292
- ~PatternBuffer()
293
- {
294
- var handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
295
- if (handle != IntPtr.Zero)
296
- {
297
- NativePattern.autd3_pattern_buffer_free(handle);
298
- }
299
- }
295
+ public void Dispose() => _handle.Dispose();
300
296
  }
301
297
 
302
298
  public static class GeometryPatternBufferExtensions
@@ -305,9 +301,6 @@ namespace AUTD3
305
301
  new PatternBuffer(NativePattern.autd3_core_geometry_pattern_buffer(geometry.Handle));
306
302
  }
307
303
 
308
-
309
-
310
-
311
304
  public sealed class Pattern : ICommand
312
305
  {
313
306
  private readonly PatternBank _bank;
@@ -331,7 +324,7 @@ namespace AUTD3
331
324
 
332
325
 
333
326
  public static Length Wavelength(Velocity soundSpeed) =>
334
- new Length(NativePattern.autd3_pattern_wavelength(soundSpeed.MmPerS));
327
+ new Length(NativePattern.autd3_pattern_wavelength(soundSpeed.MmS));
335
328
 
336
329
 
337
330
  public static void Focus(Geometry geometry, Vector3 target, Length wavelength, FocusOption option, PatternBuffer dst)
@@ -410,7 +403,7 @@ namespace AUTD3
410
403
  var a = Coords.PointArray(apex);
411
404
  var d = Coords.DirArray(dir);
412
405
  var o = option.ToNative();
413
- if (NativePattern.autd3_pattern_bessel(geometry.Handle, a, d, theta.Radian, wavelength.Mm, in o, dst.Handle) != 0)
406
+ if (NativePattern.autd3_pattern_bessel(geometry.Handle, a, d, theta.Rad, wavelength.Mm, in o, dst.Handle) != 0)
414
407
  {
415
408
  throw new Autd3Exception("bessel failed (buffer device count must match geometry)");
416
409
  }
@@ -422,7 +415,7 @@ namespace AUTD3
422
415
  var o = option.ToNative();
423
416
  if (NativePattern.autd3_pattern_bessel_device(device.GeometryHandle, device.DeviceIndex,
424
417
  Coords.PointArray(apex),
425
- Coords.DirArray(dir), theta.Radian, wavelength.Mm, in o, native) != 0)
418
+ Coords.DirArray(dir), theta.Rad, wavelength.Mm, in o, native) != 0)
426
419
  {
427
420
  throw new Autd3Exception("bessel_device failed");
428
421
  }
@@ -435,7 +428,7 @@ namespace AUTD3
435
428
  if (NativePattern.autd3_pattern_bessel_transducer(
436
429
  Coords.PointArray(position),
437
430
  Coords.PointArray(apex),
438
- Coords.DirArray(dir), theta.Radian, wavelength.Mm, in o, out var e) != 0)
431
+ Coords.DirArray(dir), theta.Rad, wavelength.Mm, in o, out var e) != 0)
439
432
  {
440
433
  throw new Autd3Exception("bessel_transducer failed");
441
434
  }
Binary file
@@ -5,7 +5,7 @@ The following is a list of those components and the full text of their licenses.
5
5
 
6
6
  ## Overview
7
7
 
8
- - MIT License (50)
8
+ - MIT License (51)
9
9
  - Apache License 2.0 (3)
10
10
  - Unicode License v3 (1)
11
11
 
@@ -854,8 +854,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
854
854
 
855
855
  Used by:
856
856
 
857
- - autd3-rs-core 0.6.0 — https://github.com/shinolab/autd3-sdk
858
- - autd3-rs-pattern 0.6.0 — https://github.com/shinolab/autd3-sdk
857
+ - autd3-rs-core 0.7.0 — https://github.com/shinolab/autd3-sdk
858
+ - autd3-rs-pattern 0.7.0 — https://github.com/shinolab/autd3-sdk
859
859
  - autd3-cpu-wire 0.6.0 — https://github.com/shinolab/autd3-sdk
860
860
 
861
861
  ```
@@ -887,8 +887,8 @@ SOFTWARE.
887
887
 
888
888
  Used by:
889
889
 
890
- - autd3-ffi-abi 0.6.0 — https://github.com/shinolab/autd3-sdk
891
- - autd3-ffi-pattern 0.6.0 — https://github.com/shinolab/autd3-sdk
890
+ - autd3-ffi-abi 0.7.0 — https://github.com/shinolab/autd3-sdk
891
+ - autd3-ffi-pattern 0.7.0 — https://github.com/shinolab/autd3-sdk
892
892
  - chrono 0.4.45 — https://github.com/chronotope/chrono
893
893
  - wide 1.5.0 — https://github.com/Lokathor/wide
894
894
  - winapi-i686-pc-windows-gnu 0.4.0 — https://github.com/retep998/winapi-rs
@@ -972,6 +972,37 @@ DEALINGS IN THE SOFTWARE.
972
972
 
973
973
  Used by:
974
974
 
975
+ - tracing-core 0.1.36 — https://github.com/tokio-rs/tracing
976
+
977
+ ```
978
+ The MIT License (MIT)
979
+
980
+ Copyright (c) 2014 Mathijs van de Nes
981
+
982
+ Permission is hereby granted, free of charge, to any person obtaining a copy
983
+ of this software and associated documentation files (the "Software"), to deal
984
+ in the Software without restriction, including without limitation the rights
985
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
986
+ copies of the Software, and to permit persons to whom the Software is
987
+ furnished to do so, subject to the following conditions:
988
+
989
+ The above copyright notice and this permission notice shall be included in all
990
+ copies or substantial portions of the Software.
991
+
992
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
993
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
994
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
995
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
996
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
997
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
998
+ SOFTWARE.
999
+
1000
+ ```
1001
+
1002
+ ## MIT License
1003
+
1004
+ Used by:
1005
+
975
1006
  - typenum 1.20.1 — https://github.com/paholg/typenum
976
1007
 
977
1008
  ```
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "git+https://github.com/shinolab/autd3-sdk.git",
6
6
  "directory": "bindings/unity/com.shinolab.autd3-sdk.pattern"
7
7
  },
8
- "version": "0.6.0",
8
+ "version": "0.7.0",
9
9
  "displayName": "AUTD3 Pattern",
10
10
  "description": "AUTD3 emission patterns: Focus, Plane, Bessel (Unity binding).",
11
11
  "unity": "6000.0",
@@ -15,6 +15,6 @@
15
15
  "url": "https://github.com/shinolab"
16
16
  },
17
17
  "dependencies": {
18
- "com.shinolab.autd3-sdk.core": "0.6.0"
18
+ "com.shinolab.autd3-sdk.core": "0.7.0"
19
19
  }
20
20
  }