com.shinolab.autd3-sdk 0.2.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/AUTD3.asmdef +18 -0
- package/AUTD3.asmdef.meta +7 -0
- package/AsyncOps.cs +45 -0
- package/AsyncOps.cs.meta +11 -0
- package/Client.cs +357 -0
- package/Client.cs.meta +11 -0
- package/Commands.cs +368 -0
- package/Commands.cs.meta +11 -0
- package/Datagram.cs +214 -0
- package/Datagram.cs.meta +11 -0
- package/GlobalUsings.cs +7 -0
- package/GlobalUsings.cs.meta +11 -0
- package/LICENSE.md +21 -0
- package/LICENSE.md.meta +7 -0
- package/Link.cs +12 -0
- package/Link.cs.meta +11 -0
- package/Native.cs +136 -0
- package/Native.cs.meta +11 -0
- package/Plugins/linux-x64/libautd3capi.so +0 -0
- package/Plugins/linux-x64/libautd3capi.so.meta +35 -0
- package/Plugins/linux-x64.meta +8 -0
- package/Plugins/osx-arm64/libautd3capi.dylib +0 -0
- package/Plugins/osx-arm64/libautd3capi.dylib.meta +35 -0
- package/Plugins/osx-arm64.meta +8 -0
- package/Plugins/win-x64/autd3capi.dll +0 -0
- package/Plugins/win-x64/autd3capi.dll.meta +35 -0
- package/Plugins/win-x64.meta +8 -0
- package/Plugins.meta +8 -0
- package/README.md +43 -0
- package/README.md.meta +7 -0
- package/Samples~/FocusSine/AUTD3.Samples.FocusSine.asmdef +20 -0
- package/Samples~/FocusSine/FocusSineSample.cs +59 -0
- package/Stm.cs +362 -0
- package/Stm.cs.meta +11 -0
- package/THIRD-PARTY-LICENSES.md +1083 -0
- package/THIRD-PARTY-LICENSES.md.meta +7 -0
- package/csc.rsp +2 -0
- package/csc.rsp.meta +7 -0
- package/package.json +24 -0
- package/package.json.meta +7 -0
package/Stm.cs
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Numerics;
|
|
4
|
+
using System.Runtime.InteropServices;
|
|
5
|
+
|
|
6
|
+
namespace AUTD3
|
|
7
|
+
{
|
|
8
|
+
public enum PatternStmMode : byte
|
|
9
|
+
{
|
|
10
|
+
PhaseIntensityFull = 0,
|
|
11
|
+
PhaseFull = 1,
|
|
12
|
+
PhaseHalf = 2,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
16
|
+
internal struct Autd3StmControlPointNative
|
|
17
|
+
{
|
|
18
|
+
public float X;
|
|
19
|
+
public float Y;
|
|
20
|
+
public float Z;
|
|
21
|
+
public byte PhaseOffset;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
internal static class NativeStm
|
|
25
|
+
{
|
|
26
|
+
private const string Lib = "autd3capi";
|
|
27
|
+
|
|
28
|
+
[DllImport(Lib)]
|
|
29
|
+
internal static extern IntPtr autd3_stm_config_freq(float hz);
|
|
30
|
+
|
|
31
|
+
[DllImport(Lib)]
|
|
32
|
+
internal static extern IntPtr autd3_stm_config_freq_nearest(float hz);
|
|
33
|
+
|
|
34
|
+
[DllImport(Lib)]
|
|
35
|
+
internal static extern IntPtr autd3_stm_config_period(float secs);
|
|
36
|
+
|
|
37
|
+
[DllImport(Lib)]
|
|
38
|
+
internal static extern IntPtr autd3_stm_config_period_nearest(float secs);
|
|
39
|
+
|
|
40
|
+
[DllImport(Lib)]
|
|
41
|
+
internal static extern IntPtr autd3_stm_config_sampling(ushort divide);
|
|
42
|
+
|
|
43
|
+
[DllImport(Lib)]
|
|
44
|
+
internal static extern void autd3_stm_config_free(IntPtr config);
|
|
45
|
+
|
|
46
|
+
[DllImport(Lib)]
|
|
47
|
+
internal static extern IntPtr autd3_op_foci_stm(IntPtr config, Autd3StmControlPointNative[] points, UIntPtr numSamples, byte numFoci, byte[] intensities, byte bank, float soundSpeedMS, ushort loopRep, byte transitionMode, ulong transitionValue);
|
|
48
|
+
|
|
49
|
+
[DllImport(Lib)]
|
|
50
|
+
internal static extern IntPtr autd3_op_write_foci_buffer(byte bank, uint indexOffset, Autd3StmControlPointNative[] points, UIntPtr numSamples, byte numFoci, byte[] intensities);
|
|
51
|
+
|
|
52
|
+
[DllImport(Lib)]
|
|
53
|
+
internal static extern IntPtr autd3_op_pattern_stm(IntPtr config, IntPtr[] patterns, UIntPtr numPatterns, byte bank, byte mode, ushort loopRep, byte transitionMode, ulong transitionValue);
|
|
54
|
+
|
|
55
|
+
[DllImport(Lib)]
|
|
56
|
+
internal static extern int autd3_stm_circle(float[] center, float radiusMm, UIntPtr numPoints, float[] normal, byte intensity, Autd3StmControlPointNative[] outPoints, byte[] outIntensities);
|
|
57
|
+
|
|
58
|
+
[DllImport(Lib)]
|
|
59
|
+
internal static extern int autd3_stm_line(float[] start, float[] end, UIntPtr numPoints, byte intensity, Autd3StmControlPointNative[] outPoints, byte[] outIntensities);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public readonly struct StmConfig
|
|
63
|
+
{
|
|
64
|
+
private enum ConfigKind : byte
|
|
65
|
+
{
|
|
66
|
+
Freq,
|
|
67
|
+
FreqNearest,
|
|
68
|
+
Period,
|
|
69
|
+
PeriodNearest,
|
|
70
|
+
Sampling,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private readonly ConfigKind _kind;
|
|
74
|
+
private readonly float _value;
|
|
75
|
+
private readonly SamplingConfig _sampling;
|
|
76
|
+
|
|
77
|
+
private StmConfig(ConfigKind kind, float value, SamplingConfig sampling)
|
|
78
|
+
{
|
|
79
|
+
_kind = kind;
|
|
80
|
+
_value = value;
|
|
81
|
+
_sampling = sampling;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public StmConfig(Freq freq) : this(ConfigKind.Freq, freq.Hz, default)
|
|
85
|
+
{
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public StmConfig(Nearest<Freq> freq) : this(ConfigKind.FreqNearest, freq.Value.Hz, default)
|
|
89
|
+
{
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public StmConfig(TimeSpan period) : this(ConfigKind.Period, (float)period.TotalSeconds, default)
|
|
93
|
+
{
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public StmConfig(Nearest<TimeSpan> period) : this(ConfigKind.PeriodNearest, (float)period.Value.TotalSeconds, default)
|
|
97
|
+
{
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public StmConfig(SamplingConfig sampling) : this(ConfigKind.Sampling, 0f, sampling)
|
|
101
|
+
{
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
internal IntPtr CreateHandle()
|
|
105
|
+
{
|
|
106
|
+
var handle = _kind switch
|
|
107
|
+
{
|
|
108
|
+
ConfigKind.Freq => NativeStm.autd3_stm_config_freq(_value),
|
|
109
|
+
ConfigKind.FreqNearest => NativeStm.autd3_stm_config_freq_nearest(_value),
|
|
110
|
+
ConfigKind.Period => NativeStm.autd3_stm_config_period(_value),
|
|
111
|
+
ConfigKind.PeriodNearest => NativeStm.autd3_stm_config_period_nearest(_value),
|
|
112
|
+
_ => NativeStm.autd3_stm_config_sampling(_sampling.Divide()),
|
|
113
|
+
};
|
|
114
|
+
if (handle == IntPtr.Zero)
|
|
115
|
+
{
|
|
116
|
+
throw new Autd3Exception("failed to create stm config");
|
|
117
|
+
}
|
|
118
|
+
return handle;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public readonly struct ControlPoint
|
|
123
|
+
{
|
|
124
|
+
public Vector3 Point { get; }
|
|
125
|
+
public Phase PhaseOffset { get; }
|
|
126
|
+
|
|
127
|
+
public ControlPoint(Vector3 point, Phase? phaseOffset = null)
|
|
128
|
+
{
|
|
129
|
+
Point = point;
|
|
130
|
+
PhaseOffset = phaseOffset ?? Phase.Zero;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public readonly struct ControlPoints
|
|
135
|
+
{
|
|
136
|
+
public ControlPoint[] Points { get; }
|
|
137
|
+
public Intensity Intensity { get; }
|
|
138
|
+
|
|
139
|
+
public ControlPoints(ControlPoint[] points, Intensity? intensity = null)
|
|
140
|
+
{
|
|
141
|
+
Points = points;
|
|
142
|
+
Intensity = intensity ?? Intensity.Max;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public readonly struct FociStmOption
|
|
147
|
+
{
|
|
148
|
+
public PatternBank Bank { get; }
|
|
149
|
+
public Velocity SoundSpeed { get; }
|
|
150
|
+
public LoopBehavior LoopBehavior { get; }
|
|
151
|
+
public TransitionMode TransitionMode { get; }
|
|
152
|
+
|
|
153
|
+
public FociStmOption() : this(bank: PatternBank.B0)
|
|
154
|
+
{
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public FociStmOption(PatternBank bank = PatternBank.B0, Velocity? soundSpeed = null, LoopBehavior? loopBehavior = null, TransitionMode? transitionMode = null)
|
|
158
|
+
{
|
|
159
|
+
Bank = bank;
|
|
160
|
+
SoundSpeed = soundSpeed ?? Velocity.FromMS(340f);
|
|
161
|
+
LoopBehavior = loopBehavior ?? LoopBehavior.Infinite;
|
|
162
|
+
TransitionMode = transitionMode ?? TransitionMode.Immediate;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public readonly struct PatternStmOption
|
|
167
|
+
{
|
|
168
|
+
public PatternBank Bank { get; }
|
|
169
|
+
public PatternStmMode Mode { get; }
|
|
170
|
+
public LoopBehavior LoopBehavior { get; }
|
|
171
|
+
public TransitionMode TransitionMode { get; }
|
|
172
|
+
|
|
173
|
+
public PatternStmOption() : this(bank: PatternBank.B0)
|
|
174
|
+
{
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public PatternStmOption(PatternBank bank = PatternBank.B0, PatternStmMode mode = PatternStmMode.PhaseIntensityFull, LoopBehavior? loopBehavior = null, TransitionMode? transitionMode = null)
|
|
178
|
+
{
|
|
179
|
+
Bank = bank;
|
|
180
|
+
Mode = mode;
|
|
181
|
+
LoopBehavior = loopBehavior ?? LoopBehavior.Infinite;
|
|
182
|
+
TransitionMode = transitionMode ?? TransitionMode.Immediate;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public sealed class FociStm : ICommand
|
|
187
|
+
{
|
|
188
|
+
private readonly StmConfig _config;
|
|
189
|
+
private readonly ControlPoints[] _points;
|
|
190
|
+
private readonly FociStmOption _option;
|
|
191
|
+
|
|
192
|
+
public FociStm(StmConfig config, ControlPoints[] points, FociStmOption? option = null)
|
|
193
|
+
{
|
|
194
|
+
_config = config;
|
|
195
|
+
_points = points;
|
|
196
|
+
_option = option ?? new FociStmOption();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
IntPtr ICommand.CreateOp()
|
|
200
|
+
{
|
|
201
|
+
if (_points.Length == 0)
|
|
202
|
+
{
|
|
203
|
+
throw new Autd3Exception("FociStm requires at least one sample");
|
|
204
|
+
}
|
|
205
|
+
var numFoci = (byte)_points[0].Points.Length;
|
|
206
|
+
var points = new Autd3StmControlPointNative[_points.Length * numFoci];
|
|
207
|
+
var intensities = new byte[_points.Length];
|
|
208
|
+
for (var i = 0; i < _points.Length; i++)
|
|
209
|
+
{
|
|
210
|
+
if (_points[i].Points.Length != numFoci)
|
|
211
|
+
{
|
|
212
|
+
throw new Autd3Exception("all FociStm samples must have the same number of foci");
|
|
213
|
+
}
|
|
214
|
+
intensities[i] = _points[i].Intensity.Value;
|
|
215
|
+
for (var j = 0; j < numFoci; j++)
|
|
216
|
+
{
|
|
217
|
+
var cp = _points[i].Points[j];
|
|
218
|
+
var p = Coords.Point(cp.Point);
|
|
219
|
+
points[i * numFoci + j] = new Autd3StmControlPointNative
|
|
220
|
+
{
|
|
221
|
+
X = p.X,
|
|
222
|
+
Y = p.Y,
|
|
223
|
+
Z = p.Z,
|
|
224
|
+
PhaseOffset = cp.PhaseOffset.Value,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
var configHandle = _config.CreateHandle();
|
|
229
|
+
try
|
|
230
|
+
{
|
|
231
|
+
return NativeStm.autd3_op_foci_stm(configHandle, points, (UIntPtr)_points.Length, numFoci, intensities,
|
|
232
|
+
(byte)_option.Bank, _option.SoundSpeed.MPerS, _option.LoopBehavior.Rep, _option.TransitionMode.Mode, _option.TransitionMode.Value);
|
|
233
|
+
}
|
|
234
|
+
finally
|
|
235
|
+
{
|
|
236
|
+
NativeStm.autd3_stm_config_free(configHandle);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public sealed class PatternStm : ICommand
|
|
242
|
+
{
|
|
243
|
+
private readonly StmConfig _config;
|
|
244
|
+
private readonly PatternBuffer[] _patterns;
|
|
245
|
+
private readonly PatternStmOption _option;
|
|
246
|
+
|
|
247
|
+
public PatternStm(StmConfig config, PatternBuffer[] patterns, PatternStmOption? option = null)
|
|
248
|
+
{
|
|
249
|
+
_config = config;
|
|
250
|
+
_patterns = patterns;
|
|
251
|
+
_option = option ?? new PatternStmOption(PatternBank.B0);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
IntPtr ICommand.CreateOp()
|
|
255
|
+
{
|
|
256
|
+
var handles = new IntPtr[_patterns.Length];
|
|
257
|
+
for (var i = 0; i < _patterns.Length; i++)
|
|
258
|
+
{
|
|
259
|
+
handles[i] = _patterns[i].Handle;
|
|
260
|
+
}
|
|
261
|
+
var configHandle = _config.CreateHandle();
|
|
262
|
+
try
|
|
263
|
+
{
|
|
264
|
+
return NativeStm.autd3_op_pattern_stm(configHandle, handles, (UIntPtr)handles.Length,
|
|
265
|
+
(byte)_option.Bank, (byte)_option.Mode, _option.LoopBehavior.Rep, _option.TransitionMode.Mode, _option.TransitionMode.Value);
|
|
266
|
+
}
|
|
267
|
+
finally
|
|
268
|
+
{
|
|
269
|
+
NativeStm.autd3_stm_config_free(configHandle);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
public sealed class WriteFociBuffer : ICommand
|
|
275
|
+
{
|
|
276
|
+
private readonly PatternBank _bank;
|
|
277
|
+
private readonly uint _indexOffset;
|
|
278
|
+
private readonly ControlPoints[] _points;
|
|
279
|
+
|
|
280
|
+
public WriteFociBuffer(PatternBank bank, uint indexOffset, ControlPoints[] points)
|
|
281
|
+
{
|
|
282
|
+
_bank = bank;
|
|
283
|
+
_indexOffset = indexOffset;
|
|
284
|
+
_points = points;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
IntPtr ICommand.CreateOp()
|
|
288
|
+
{
|
|
289
|
+
if (_points.Length == 0)
|
|
290
|
+
{
|
|
291
|
+
throw new Autd3Exception("WriteFociBuffer requires at least one sample");
|
|
292
|
+
}
|
|
293
|
+
var numFoci = (byte)_points[0].Points.Length;
|
|
294
|
+
var points = new Autd3StmControlPointNative[_points.Length * numFoci];
|
|
295
|
+
var intensities = new byte[_points.Length];
|
|
296
|
+
for (var i = 0; i < _points.Length; i++)
|
|
297
|
+
{
|
|
298
|
+
if (_points[i].Points.Length != numFoci)
|
|
299
|
+
{
|
|
300
|
+
throw new Autd3Exception("all WriteFociBuffer samples must have the same number of foci");
|
|
301
|
+
}
|
|
302
|
+
intensities[i] = _points[i].Intensity.Value;
|
|
303
|
+
for (var j = 0; j < numFoci; j++)
|
|
304
|
+
{
|
|
305
|
+
var cp = _points[i].Points[j];
|
|
306
|
+
var p = Coords.Point(cp.Point);
|
|
307
|
+
points[i * numFoci + j] = new Autd3StmControlPointNative
|
|
308
|
+
{
|
|
309
|
+
X = p.X,
|
|
310
|
+
Y = p.Y,
|
|
311
|
+
Z = p.Z,
|
|
312
|
+
PhaseOffset = cp.PhaseOffset.Value,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return NativeStm.autd3_op_write_foci_buffer((byte)_bank, _indexOffset, points, (UIntPtr)_points.Length, numFoci, intensities);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
public static class Stm
|
|
321
|
+
{
|
|
322
|
+
private static void Fill(List<ControlPoints> dst, Autd3StmControlPointNative[] points, byte[] intensities)
|
|
323
|
+
{
|
|
324
|
+
dst.Clear();
|
|
325
|
+
for (var i = 0; i < points.Length; i++)
|
|
326
|
+
{
|
|
327
|
+
var cp = new ControlPoint(Coords.FromPointArray(new[] { points[i].X, points[i].Y, points[i].Z }), new Phase(points[i].PhaseOffset));
|
|
328
|
+
dst.Add(new ControlPoints(new[] { cp }, new Intensity(intensities[i])));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
public static void Circle(Vector3 center, Length radius, int numPoints, Vector3 normal, Intensity intensity, List<ControlPoints> dst)
|
|
333
|
+
{
|
|
334
|
+
var outPoints = new Autd3StmControlPointNative[numPoints];
|
|
335
|
+
var outIntensities = new byte[numPoints];
|
|
336
|
+
if (NativeStm.autd3_stm_circle(Coords.PointArray(center), radius.Mm, (UIntPtr)numPoints,
|
|
337
|
+
Coords.DirArray(normal), intensity.Value, outPoints, outIntensities) != 0)
|
|
338
|
+
{
|
|
339
|
+
throw new Autd3Exception("circle failed");
|
|
340
|
+
}
|
|
341
|
+
Fill(dst, outPoints, outIntensities);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
public static void Circle(Vector3 center, Length radius, int numPoints, Vector3 normal, List<ControlPoints> dst) =>
|
|
345
|
+
Circle(center, radius, numPoints, normal, Intensity.Max, dst);
|
|
346
|
+
|
|
347
|
+
public static void Line(Vector3 start, Vector3 end, int numPoints, Intensity intensity, List<ControlPoints> dst)
|
|
348
|
+
{
|
|
349
|
+
var outPoints = new Autd3StmControlPointNative[numPoints];
|
|
350
|
+
var outIntensities = new byte[numPoints];
|
|
351
|
+
if (NativeStm.autd3_stm_line(Coords.PointArray(start), Coords.PointArray(end), (UIntPtr)numPoints,
|
|
352
|
+
intensity.Value, outPoints, outIntensities) != 0)
|
|
353
|
+
{
|
|
354
|
+
throw new Autd3Exception("line failed");
|
|
355
|
+
}
|
|
356
|
+
Fill(dst, outPoints, outIntensities);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
public static void Line(Vector3 start, Vector3 end, int numPoints, List<ControlPoints> dst) =>
|
|
360
|
+
Line(start, end, numPoints, Intensity.Max, dst);
|
|
361
|
+
}
|
|
362
|
+
}
|
package/Stm.cs.meta
ADDED