com.shinolab.autd3-sdk.modulation 0.10.0 → 0.13.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/Modulation.cs
CHANGED
|
@@ -6,33 +6,48 @@ using System.Runtime.InteropServices;
|
|
|
6
6
|
|
|
7
7
|
namespace AUTD3
|
|
8
8
|
{
|
|
9
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
10
|
+
internal struct SineOptionNative
|
|
11
|
+
{
|
|
12
|
+
public byte Amplitude;
|
|
13
|
+
public byte Offset;
|
|
14
|
+
public float PhaseRad;
|
|
15
|
+
public byte Clamp;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
19
|
+
internal struct SquareOptionNative
|
|
20
|
+
{
|
|
21
|
+
public byte Low;
|
|
22
|
+
public byte High;
|
|
23
|
+
public float Duty;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
27
|
+
internal struct FourierOptionNative
|
|
28
|
+
{
|
|
29
|
+
public byte HasScaleFactor;
|
|
30
|
+
public float ScaleFactor;
|
|
31
|
+
public byte Clamp;
|
|
32
|
+
public byte Offset;
|
|
33
|
+
}
|
|
34
|
+
|
|
9
35
|
[StructLayout(LayoutKind.Sequential)]
|
|
10
36
|
internal struct SineComponentNative
|
|
11
37
|
{
|
|
12
|
-
public byte Mode;
|
|
13
38
|
public float Freq;
|
|
14
|
-
public
|
|
15
|
-
public IntPtr Option;
|
|
39
|
+
public SineOptionNative Option;
|
|
16
40
|
}
|
|
17
41
|
|
|
18
42
|
internal static class NativeModulation
|
|
19
43
|
{
|
|
20
44
|
private const string Lib = "autd3_modulation";
|
|
21
45
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
static NativeModulation()
|
|
25
|
-
{
|
|
26
|
-
NativeAbi.Verify(Lib, autd3_abi_version());
|
|
27
|
-
NativeAbi.Verify(ClientLib, autd3capi_abi_version());
|
|
28
|
-
}
|
|
46
|
+
static NativeModulation() => NativeAbi.Verify(Lib, autd3_abi_version());
|
|
29
47
|
|
|
30
48
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
31
49
|
private static extern uint autd3_abi_version();
|
|
32
50
|
|
|
33
|
-
[DllImport(ClientLib, EntryPoint = "autd3_abi_version", CallingConvention = CallingConvention.Cdecl)]
|
|
34
|
-
private static extern uint autd3capi_abi_version();
|
|
35
|
-
|
|
36
51
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
37
52
|
internal static extern IntPtr autd3_modulation_buffer_new();
|
|
38
53
|
|
|
@@ -53,57 +68,58 @@ namespace AUTD3
|
|
|
53
68
|
|
|
54
69
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
55
70
|
[return: MarshalAs(UnmanagedType.I1)]
|
|
56
|
-
internal static extern bool autd3_modulation_samples_per_period(ushort divider,
|
|
71
|
+
internal static extern bool autd3_modulation_samples_per_period(ushort divider, float freqHz, out uint outValue);
|
|
57
72
|
|
|
58
73
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
59
|
-
internal static extern
|
|
74
|
+
internal static extern int autd3_modulation_sine_option_default(out byte amplitude, out byte offset, out float phaseRad, [MarshalAs(UnmanagedType.I1)] out bool clamp);
|
|
60
75
|
|
|
61
76
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
62
|
-
internal static extern
|
|
77
|
+
internal static extern int autd3_modulation_square_option_default(out byte low, out byte high, out float duty);
|
|
63
78
|
|
|
64
79
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
65
|
-
internal static extern int
|
|
80
|
+
internal static extern int autd3_modulation_fourier_option_default([MarshalAs(UnmanagedType.I1)] out bool hasScaleFactor, out float scaleFactor, [MarshalAs(UnmanagedType.I1)] out bool clamp, out byte offset);
|
|
66
81
|
|
|
67
82
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
68
|
-
internal static extern
|
|
83
|
+
internal static extern int autd3_modulation_sine(float freq, SineOptionNative option, ushort samplingDivide, ModulationBufferHandle buffer, byte[] outErr, UIntPtr outErrLen);
|
|
69
84
|
|
|
70
85
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
71
|
-
internal static extern
|
|
86
|
+
internal static extern int autd3_modulation_square(float freq, SquareOptionNative option, ushort samplingDivide, ModulationBufferHandle buffer, byte[] outErr, UIntPtr outErrLen);
|
|
72
87
|
|
|
73
88
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
74
|
-
internal static extern int
|
|
89
|
+
internal static extern int autd3_modulation_fourier(SineComponentNative[] components, UIntPtr numComponents, FourierOptionNative option, ushort samplingDivide, ModulationBufferHandle buffer, byte[] outErr, UIntPtr outErrLen);
|
|
75
90
|
|
|
76
91
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
77
|
-
internal static extern
|
|
92
|
+
internal static extern int autd3_modulation_buffer_copy_to(ModulationBufferHandle buffer, [Out] byte[] dst, UIntPtr len);
|
|
78
93
|
|
|
79
94
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
80
|
-
internal static extern
|
|
95
|
+
internal static extern int autd3_modulation_constant(byte amplitude, ModulationBufferHandle buffer);
|
|
81
96
|
|
|
82
97
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
83
|
-
internal static extern int
|
|
98
|
+
internal static extern int autd3_modulation_radiation_pressure_inplace(ModulationBufferHandle buffer);
|
|
99
|
+
}
|
|
84
100
|
|
|
85
|
-
|
|
86
|
-
|
|
101
|
+
internal static class NativeModulationOp
|
|
102
|
+
{
|
|
103
|
+
private const string Lib = "autd3capi";
|
|
87
104
|
|
|
88
|
-
|
|
89
|
-
internal static extern int autd3_modulation_constant(byte amplitude, ModulationBufferHandle buffer);
|
|
105
|
+
static NativeModulationOp() => NativeAbi.Verify(Lib, autd3_abi_version());
|
|
90
106
|
|
|
91
107
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
92
|
-
|
|
108
|
+
private static extern uint autd3_abi_version();
|
|
93
109
|
|
|
94
110
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
95
|
-
internal static extern
|
|
96
|
-
|
|
97
|
-
[DllImport(ClientLib, CallingConvention = CallingConvention.Cdecl)]
|
|
98
|
-
internal static extern IntPtr autd3_op_modulation(byte bank, IntPtr samplingConfig, ModulationBufferHandle modulationBuffer, ushort loopRep, byte transitionMode, ulong transitionValue);
|
|
111
|
+
internal static extern IntPtr autd3_op_modulation(byte bank, ushort samplingDivide, ModulationBufferHandle modulationBuffer, ushort loopRep, byte transitionMode, ulong transitionValue);
|
|
99
112
|
|
|
100
|
-
[DllImport(
|
|
113
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
101
114
|
internal static extern IntPtr autd3_op_write_modulation_buffer(byte bank, uint offset, ModulationBufferHandle modulationBuffer);
|
|
102
115
|
|
|
103
|
-
[DllImport(
|
|
104
|
-
internal static extern
|
|
116
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
117
|
+
internal static extern UIntPtr autd3_op_write_modulation_buffer_max_len();
|
|
105
118
|
|
|
106
|
-
[DllImport(
|
|
119
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
120
|
+
internal static extern IntPtr autd3_op_config_modulation(byte bank, ushort samplingDivide, uint size, ushort rep);
|
|
121
|
+
|
|
122
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
107
123
|
internal static extern IntPtr autd3_op_activate_modulation_bank(byte bank, byte transitionMode, ulong transitionValue);
|
|
108
124
|
}
|
|
109
125
|
|
|
@@ -189,57 +205,105 @@ namespace AUTD3
|
|
|
189
205
|
public void Dispose() => _handle.Dispose();
|
|
190
206
|
}
|
|
191
207
|
|
|
208
|
+
internal static class ModulationOptionDefaults
|
|
209
|
+
{
|
|
210
|
+
internal static readonly byte SineAmplitude;
|
|
211
|
+
internal static readonly byte SineOffset;
|
|
212
|
+
internal static readonly Angle SinePhase;
|
|
213
|
+
internal static readonly bool SineClamp;
|
|
214
|
+
internal static readonly byte SquareLow;
|
|
215
|
+
internal static readonly byte SquareHigh;
|
|
216
|
+
internal static readonly float SquareDuty;
|
|
217
|
+
internal static readonly float? FourierScaleFactor;
|
|
218
|
+
internal static readonly bool FourierClamp;
|
|
219
|
+
internal static readonly byte FourierOffset;
|
|
220
|
+
|
|
221
|
+
static ModulationOptionDefaults()
|
|
222
|
+
{
|
|
223
|
+
OptionNative.Apply("preset", NativeModulation.autd3_modulation_sine_option_default(out SineAmplitude, out SineOffset, out var phase, out SineClamp));
|
|
224
|
+
SinePhase = Angle.FromRad(phase);
|
|
225
|
+
OptionNative.Apply("preset", NativeModulation.autd3_modulation_square_option_default(out SquareLow, out SquareHigh, out SquareDuty));
|
|
226
|
+
OptionNative.Apply("preset", NativeModulation.autd3_modulation_fourier_option_default(out var hasScaleFactor, out var scaleFactor, out FourierClamp, out FourierOffset));
|
|
227
|
+
FourierScaleFactor = hasScaleFactor ? scaleFactor : (float?)null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
192
231
|
public readonly struct SineOption
|
|
193
232
|
{
|
|
194
233
|
private readonly byte? _amplitude;
|
|
195
|
-
public byte Amplitude { get => _amplitude ??
|
|
234
|
+
public byte Amplitude { get => _amplitude ?? ModulationOptionDefaults.SineAmplitude; init => _amplitude = value; }
|
|
196
235
|
private readonly byte? _offset;
|
|
197
|
-
public byte Offset { get => _offset ??
|
|
198
|
-
|
|
199
|
-
public
|
|
200
|
-
private readonly
|
|
201
|
-
public
|
|
236
|
+
public byte Offset { get => _offset ?? ModulationOptionDefaults.SineOffset; init => _offset = value; }
|
|
237
|
+
private readonly Angle? _phase;
|
|
238
|
+
public Angle Phase { get => _phase ?? ModulationOptionDefaults.SinePhase; init => _phase = value; }
|
|
239
|
+
private readonly bool? _clamp;
|
|
240
|
+
public bool Clamp { get => _clamp ?? ModulationOptionDefaults.SineClamp; init => _clamp = value; }
|
|
241
|
+
|
|
242
|
+
internal SineOptionNative ToNative() => new SineOptionNative
|
|
243
|
+
{
|
|
244
|
+
Amplitude = Amplitude,
|
|
245
|
+
Offset = Offset,
|
|
246
|
+
PhaseRad = Phase.Rad,
|
|
247
|
+
Clamp = OptionNative.Flag(Clamp),
|
|
248
|
+
};
|
|
202
249
|
}
|
|
203
250
|
|
|
204
251
|
public readonly struct SquareOption
|
|
205
252
|
{
|
|
206
|
-
|
|
253
|
+
private readonly byte? _low;
|
|
254
|
+
public byte Low { get => _low ?? ModulationOptionDefaults.SquareLow; init => _low = value; }
|
|
207
255
|
private readonly byte? _high;
|
|
208
|
-
public byte High { get => _high ??
|
|
256
|
+
public byte High { get => _high ?? ModulationOptionDefaults.SquareHigh; init => _high = value; }
|
|
209
257
|
private readonly float? _duty;
|
|
210
|
-
public float Duty { get => _duty ??
|
|
211
|
-
|
|
212
|
-
|
|
258
|
+
public float Duty { get => _duty ?? ModulationOptionDefaults.SquareDuty; init => _duty = value; }
|
|
259
|
+
|
|
260
|
+
internal SquareOptionNative ToNative() => new SquareOptionNative
|
|
261
|
+
{
|
|
262
|
+
Low = Low,
|
|
263
|
+
High = High,
|
|
264
|
+
Duty = Duty,
|
|
265
|
+
};
|
|
213
266
|
}
|
|
214
267
|
|
|
215
268
|
public readonly struct FourierOption
|
|
216
269
|
{
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
270
|
+
private readonly bool _scaleFactorSet;
|
|
271
|
+
private readonly float? _scaleFactor;
|
|
272
|
+
|
|
273
|
+
public float? ScaleFactor
|
|
274
|
+
{
|
|
275
|
+
get => _scaleFactorSet ? _scaleFactor : ModulationOptionDefaults.FourierScaleFactor;
|
|
276
|
+
init
|
|
277
|
+
{
|
|
278
|
+
_scaleFactor = value;
|
|
279
|
+
_scaleFactorSet = true;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
private readonly bool? _clamp;
|
|
284
|
+
public bool Clamp { get => _clamp ?? ModulationOptionDefaults.FourierClamp; init => _clamp = value; }
|
|
285
|
+
private readonly byte? _offset;
|
|
286
|
+
public byte Offset { get => _offset ?? ModulationOptionDefaults.FourierOffset; init => _offset = value; }
|
|
287
|
+
|
|
288
|
+
internal FourierOptionNative ToNative() => new FourierOptionNative
|
|
289
|
+
{
|
|
290
|
+
HasScaleFactor = OptionNative.Flag(ScaleFactor.HasValue),
|
|
291
|
+
ScaleFactor = ScaleFactor ?? 0f,
|
|
292
|
+
Clamp = OptionNative.Flag(Clamp),
|
|
293
|
+
Offset = Offset,
|
|
294
|
+
};
|
|
220
295
|
}
|
|
221
296
|
|
|
222
297
|
public readonly struct SineComponent
|
|
223
298
|
{
|
|
224
299
|
public Freq Freq { get; }
|
|
225
300
|
public SineOption Option { get; }
|
|
226
|
-
private readonly bool _nearest;
|
|
227
301
|
|
|
228
302
|
public SineComponent(Freq freq, SineOption option)
|
|
229
303
|
{
|
|
230
304
|
Freq = freq;
|
|
231
305
|
Option = option;
|
|
232
|
-
_nearest = false;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
public SineComponent(Nearest<Freq> freq, SineOption option)
|
|
236
|
-
{
|
|
237
|
-
Freq = freq.Value;
|
|
238
|
-
Option = option;
|
|
239
|
-
_nearest = true;
|
|
240
306
|
}
|
|
241
|
-
|
|
242
|
-
internal byte ModeCode => _nearest ? (byte)2 : Freq.ModeCode;
|
|
243
307
|
}
|
|
244
308
|
|
|
245
309
|
public sealed class Modulation : ICommand
|
|
@@ -250,106 +314,48 @@ namespace AUTD3
|
|
|
250
314
|
private readonly LoopBehavior _loopBehavior;
|
|
251
315
|
private readonly TransitionMode _transitionMode;
|
|
252
316
|
|
|
253
|
-
public Modulation(SamplingConfig config, ModulationBuffer data, LoopBehavior
|
|
317
|
+
public Modulation(SamplingConfig config, ModulationBuffer data, LoopBehavior loopBehavior = default, TransitionMode transitionMode = default)
|
|
254
318
|
: this(ModulationBank.B0, config, data, loopBehavior, transitionMode)
|
|
255
319
|
{
|
|
256
320
|
}
|
|
257
321
|
|
|
258
|
-
public Modulation(ModulationBank bank, SamplingConfig config, ModulationBuffer data, LoopBehavior
|
|
322
|
+
public Modulation(ModulationBank bank, SamplingConfig config, ModulationBuffer data, LoopBehavior loopBehavior = default, TransitionMode transitionMode = default)
|
|
259
323
|
{
|
|
260
324
|
_bank = bank;
|
|
261
325
|
_samplingConfig = config;
|
|
262
326
|
_buffer = data;
|
|
263
|
-
_loopBehavior = loopBehavior
|
|
264
|
-
_transitionMode = transitionMode
|
|
327
|
+
_loopBehavior = loopBehavior;
|
|
328
|
+
_transitionMode = transitionMode;
|
|
265
329
|
}
|
|
266
330
|
|
|
267
331
|
public static ModulationBuffer ModulationBuffer() => new ModulationBuffer();
|
|
268
332
|
|
|
269
|
-
public static uint? SamplesPerPeriod(ushort divider, Freq freq)
|
|
270
|
-
|
|
271
|
-
if (freq.Mode != AUTD3.Freq.FreqMode.IntExact)
|
|
272
|
-
{
|
|
273
|
-
throw new Autd3Exception("samples_per_period requires an integer frequency", Autd3ErrorCode.InvalidArgument);
|
|
274
|
-
}
|
|
275
|
-
return NativeModulation.autd3_modulation_samples_per_period(divider, freq.HzIntValue, out var value) ? value : null;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
IntPtr ICommand.CreateOp(Geometry geometry)
|
|
279
|
-
{
|
|
280
|
-
var sampling = _samplingConfig.CreateHandle();
|
|
281
|
-
try
|
|
282
|
-
{
|
|
283
|
-
return NativeModulation.autd3_op_modulation(
|
|
284
|
-
(byte)_bank, sampling, _buffer.Handle, _loopBehavior.Rep, _transitionMode.Mode, _transitionMode.Value);
|
|
285
|
-
}
|
|
286
|
-
finally
|
|
287
|
-
{
|
|
288
|
-
NativeCore.autd3_core_sampling_config_free(sampling);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
public static void Sine(Nearest<Freq> freq, SineOption option, ModulationBuffer dst) =>
|
|
293
|
-
Sine(freq.Value, 2, option, dst);
|
|
333
|
+
public static uint? SamplesPerPeriod(ushort divider, Freq freq) =>
|
|
334
|
+
NativeModulation.autd3_modulation_samples_per_period(divider, freq.Hz, out var value) ? value : null;
|
|
294
335
|
|
|
295
|
-
|
|
296
|
-
|
|
336
|
+
IntPtr ICommand.CreateOp(Geometry geometry) =>
|
|
337
|
+
NativeModulationOp.autd3_op_modulation(
|
|
338
|
+
(byte)_bank, _samplingConfig.DivideForNative(), _buffer.Handle, _loopBehavior.Rep, _transitionMode.Mode, _transitionMode.Value);
|
|
297
339
|
|
|
298
|
-
|
|
340
|
+
public static void Sine(Freq freq, SineOption option, SamplingConfig config, ModulationBuffer dst)
|
|
299
341
|
{
|
|
300
|
-
var sampling =
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
option.Amplitude, option.Offset, option.Phase.Rad, option.Clamp, sampling);
|
|
305
|
-
try
|
|
306
|
-
{
|
|
307
|
-
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
308
|
-
if (NativeModulation.autd3_modulation_sine(modeCode, freq.HzValue, freq.HzIntValue, optionHandle, dst.Handle, err, (UIntPtr)err.Length) != 0)
|
|
309
|
-
{
|
|
310
|
-
throw new Autd3Exception(NativeUtil.Utf8(err));
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
finally
|
|
314
|
-
{
|
|
315
|
-
NativeModulation.autd3_modulation_sine_option_free(optionHandle);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
finally
|
|
342
|
+
var sampling = config.DivideForNative();
|
|
343
|
+
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
344
|
+
var code = NativeModulation.autd3_modulation_sine(freq.Hz, option.ToNative(), sampling, dst.Handle, err, (UIntPtr)err.Length);
|
|
345
|
+
if (code != 0)
|
|
319
346
|
{
|
|
320
|
-
|
|
347
|
+
throw Autd3Exception.FromNative(code, err);
|
|
321
348
|
}
|
|
322
349
|
}
|
|
323
350
|
|
|
324
|
-
public static void Square(
|
|
325
|
-
Square(freq.Value, 2, option, dst);
|
|
326
|
-
|
|
327
|
-
public static void Square(Freq freq, SquareOption option, ModulationBuffer dst) =>
|
|
328
|
-
Square(freq, freq.ModeCode, option, dst);
|
|
329
|
-
|
|
330
|
-
private static void Square(Freq freq, byte modeCode, SquareOption option, ModulationBuffer dst)
|
|
351
|
+
public static void Square(Freq freq, SquareOption option, SamplingConfig config, ModulationBuffer dst)
|
|
331
352
|
{
|
|
332
|
-
var sampling =
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
option.Low, option.High, option.Duty, sampling);
|
|
337
|
-
try
|
|
338
|
-
{
|
|
339
|
-
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
340
|
-
if (NativeModulation.autd3_modulation_square(modeCode, freq.HzValue, freq.HzIntValue, optionHandle, dst.Handle, err, (UIntPtr)err.Length) != 0)
|
|
341
|
-
{
|
|
342
|
-
throw new Autd3Exception(NativeUtil.Utf8(err));
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
finally
|
|
346
|
-
{
|
|
347
|
-
NativeModulation.autd3_modulation_square_option_free(optionHandle);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
finally
|
|
353
|
+
var sampling = config.DivideForNative();
|
|
354
|
+
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
355
|
+
var code = NativeModulation.autd3_modulation_square(freq.Hz, option.ToNative(), sampling, dst.Handle, err, (UIntPtr)err.Length);
|
|
356
|
+
if (code != 0)
|
|
351
357
|
{
|
|
352
|
-
|
|
358
|
+
throw Autd3Exception.FromNative(code, err);
|
|
353
359
|
}
|
|
354
360
|
}
|
|
355
361
|
|
|
@@ -361,63 +367,24 @@ namespace AUTD3
|
|
|
361
367
|
}
|
|
362
368
|
}
|
|
363
369
|
|
|
364
|
-
public static void Fourier(SineComponent[] components, FourierOption option, ModulationBuffer dst)
|
|
370
|
+
public static void Fourier(SineComponent[] components, FourierOption option, SamplingConfig config, ModulationBuffer dst)
|
|
365
371
|
{
|
|
366
|
-
var
|
|
367
|
-
var optionHandles = new List<IntPtr>();
|
|
372
|
+
var sampling = config.DivideForNative();
|
|
368
373
|
var native = new SineComponentNative[components.Length];
|
|
369
|
-
|
|
374
|
+
for (var i = 0; i < components.Length; i++)
|
|
370
375
|
{
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
var c = components[i];
|
|
374
|
-
var sampling = c.Option.SamplingConfig.CreateHandle();
|
|
375
|
-
samplingHandles.Add(sampling);
|
|
376
|
-
var optionHandle = NativeModulation.autd3_modulation_sine_option_new(
|
|
377
|
-
c.Option.Amplitude, c.Option.Offset, c.Option.Phase.Rad, c.Option.Clamp, sampling);
|
|
378
|
-
optionHandles.Add(optionHandle);
|
|
379
|
-
native[i] = new SineComponentNative
|
|
380
|
-
{
|
|
381
|
-
Mode = c.ModeCode,
|
|
382
|
-
Freq = c.Freq.HzValue,
|
|
383
|
-
FreqInt = c.Freq.HzIntValue,
|
|
384
|
-
Option = optionHandle,
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
var fourierOption = NativeModulation.autd3_modulation_fourier_option_new(
|
|
389
|
-
option.ScaleFactor.HasValue, option.ScaleFactor ?? 0f, option.Clamp, option.Offset);
|
|
390
|
-
try
|
|
391
|
-
{
|
|
392
|
-
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
393
|
-
if (NativeModulation.autd3_modulation_fourier(native, (UIntPtr)components.Length, fourierOption, dst.Handle, err, (UIntPtr)err.Length) != 0)
|
|
394
|
-
{
|
|
395
|
-
throw new Autd3Exception(NativeUtil.Utf8(err));
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
finally
|
|
376
|
+
var c = components[i];
|
|
377
|
+
native[i] = new SineComponentNative
|
|
399
378
|
{
|
|
400
|
-
|
|
401
|
-
|
|
379
|
+
Freq = c.Freq.Hz,
|
|
380
|
+
Option = c.Option.ToNative(),
|
|
381
|
+
};
|
|
402
382
|
}
|
|
403
|
-
|
|
383
|
+
var err = new byte[NativeAbi.ErrorBufferLength];
|
|
384
|
+
var code = NativeModulation.autd3_modulation_fourier(native, (UIntPtr)components.Length, option.ToNative(), sampling, dst.Handle, err, (UIntPtr)err.Length);
|
|
385
|
+
if (code != 0)
|
|
404
386
|
{
|
|
405
|
-
|
|
406
|
-
{
|
|
407
|
-
NativeModulation.autd3_modulation_sine_option_free(optionHandle);
|
|
408
|
-
}
|
|
409
|
-
foreach (var sampling in samplingHandles)
|
|
410
|
-
{
|
|
411
|
-
NativeCore.autd3_core_sampling_config_free(sampling);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
public static void RadiationPressure(ModulationBuffer src, ModulationBuffer dst)
|
|
417
|
-
{
|
|
418
|
-
if (NativeModulation.autd3_modulation_radiation_pressure(src.Handle, dst.Handle) != 0)
|
|
419
|
-
{
|
|
420
|
-
throw new Autd3Exception("radiation pressure failed");
|
|
387
|
+
throw Autd3Exception.FromNative(code, err);
|
|
421
388
|
}
|
|
422
389
|
}
|
|
423
390
|
|
package/ModulationOps.cs
CHANGED
|
@@ -10,6 +10,8 @@ namespace AUTD3
|
|
|
10
10
|
|
|
11
11
|
public sealed class WriteModulationBuffer : ICommand
|
|
12
12
|
{
|
|
13
|
+
public static readonly int MaxLen = (int)NativeModulationOp.autd3_op_write_modulation_buffer_max_len();
|
|
14
|
+
|
|
13
15
|
private readonly ModulationBank _bank;
|
|
14
16
|
private readonly uint _offset;
|
|
15
17
|
private readonly ModulationBuffer _buffer;
|
|
@@ -22,7 +24,7 @@ namespace AUTD3
|
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
IntPtr ICommand.CreateOp(Geometry geometry) =>
|
|
25
|
-
|
|
27
|
+
NativeModulationOp.autd3_op_write_modulation_buffer((byte)_bank, _offset, _buffer.Handle);
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
public sealed class ConfigModulation : ICommand
|
|
@@ -32,26 +34,16 @@ namespace AUTD3
|
|
|
32
34
|
private readonly uint _size;
|
|
33
35
|
private readonly LoopBehavior _loopBehavior;
|
|
34
36
|
|
|
35
|
-
public ConfigModulation(ModulationBank bank, SamplingConfig config, uint size, LoopBehavior
|
|
37
|
+
public ConfigModulation(ModulationBank bank, SamplingConfig config, uint size, LoopBehavior loopBehavior)
|
|
36
38
|
{
|
|
37
39
|
_bank = bank;
|
|
38
40
|
_config = config;
|
|
39
41
|
_size = size;
|
|
40
|
-
_loopBehavior = loopBehavior
|
|
42
|
+
_loopBehavior = loopBehavior;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
IntPtr ICommand.CreateOp(Geometry geometry)
|
|
44
|
-
|
|
45
|
-
var sampling = _config.CreateHandle();
|
|
46
|
-
try
|
|
47
|
-
{
|
|
48
|
-
return NativeModulation.autd3_op_config_modulation((byte)_bank, sampling, _size, _loopBehavior.Rep);
|
|
49
|
-
}
|
|
50
|
-
finally
|
|
51
|
-
{
|
|
52
|
-
NativeCore.autd3_core_sampling_config_free(sampling);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
45
|
+
IntPtr ICommand.CreateOp(Geometry geometry) =>
|
|
46
|
+
NativeModulationOp.autd3_op_config_modulation((byte)_bank, _config.DivideForNative(), _size, _loopBehavior.Rep);
|
|
55
47
|
}
|
|
56
48
|
|
|
57
49
|
public sealed class ActivateModulationBank : ICommand
|
|
@@ -59,13 +51,13 @@ namespace AUTD3
|
|
|
59
51
|
private readonly ModulationBank _bank;
|
|
60
52
|
private readonly TransitionMode _transitionMode;
|
|
61
53
|
|
|
62
|
-
public ActivateModulationBank(ModulationBank bank, TransitionMode
|
|
54
|
+
public ActivateModulationBank(ModulationBank bank, TransitionMode transitionMode)
|
|
63
55
|
{
|
|
64
56
|
_bank = bank;
|
|
65
|
-
_transitionMode = transitionMode
|
|
57
|
+
_transitionMode = transitionMode;
|
|
66
58
|
}
|
|
67
59
|
|
|
68
60
|
IntPtr ICommand.CreateOp(Geometry geometry) =>
|
|
69
|
-
|
|
61
|
+
NativeModulationOp.autd3_op_activate_modulation_bank((byte)_bank, _transitionMode.Mode, _transitionMode.Value);
|
|
70
62
|
}
|
|
71
63
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/THIRD-PARTY-LICENSES.md
CHANGED
|
@@ -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 (
|
|
8
|
+
- MIT License (27)
|
|
9
9
|
- Apache License 2.0 (3)
|
|
10
10
|
- Unicode License v3 (1)
|
|
11
11
|
|
|
@@ -226,7 +226,7 @@ Used by:
|
|
|
226
226
|
Used by:
|
|
227
227
|
|
|
228
228
|
- nalgebra 0.35.0 — https://github.com/dimforge/nalgebra
|
|
229
|
-
- simba 0.10.
|
|
229
|
+
- simba 0.10.2 — https://github.com/dimforge/simba
|
|
230
230
|
|
|
231
231
|
```
|
|
232
232
|
Apache License
|
|
@@ -511,7 +511,7 @@ DEALINGS IN THE SOFTWARE.
|
|
|
511
511
|
|
|
512
512
|
Used by:
|
|
513
513
|
|
|
514
|
-
- matrixmultiply 0.3.
|
|
514
|
+
- matrixmultiply 0.3.11 — https://github.com/bluss/matrixmultiply/
|
|
515
515
|
|
|
516
516
|
```
|
|
517
517
|
Copyright (c) 2016 - 2023 Ulrik Sverdrup "bluss"
|
|
@@ -548,44 +548,8 @@ DEALINGS IN THE SOFTWARE.
|
|
|
548
548
|
|
|
549
549
|
Used by:
|
|
550
550
|
|
|
551
|
-
-
|
|
552
|
-
-
|
|
553
|
-
|
|
554
|
-
```
|
|
555
|
-
Copyright (c) 2019 Tokio Contributors
|
|
556
|
-
|
|
557
|
-
Permission is hereby granted, free of charge, to any
|
|
558
|
-
person obtaining a copy of this software and associated
|
|
559
|
-
documentation files (the "Software"), to deal in the
|
|
560
|
-
Software without restriction, including without
|
|
561
|
-
limitation the rights to use, copy, modify, merge,
|
|
562
|
-
publish, distribute, sublicense, and/or sell copies of
|
|
563
|
-
the Software, and to permit persons to whom the Software
|
|
564
|
-
is furnished to do so, subject to the following
|
|
565
|
-
conditions:
|
|
566
|
-
|
|
567
|
-
The above copyright notice and this permission notice
|
|
568
|
-
shall be included in all copies or substantial portions
|
|
569
|
-
of the Software.
|
|
570
|
-
|
|
571
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
572
|
-
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
573
|
-
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
574
|
-
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
575
|
-
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
576
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
577
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
578
|
-
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
579
|
-
DEALINGS IN THE SOFTWARE.
|
|
580
|
-
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
## MIT License
|
|
584
|
-
|
|
585
|
-
Used by:
|
|
586
|
-
|
|
587
|
-
- zerocopy-derive 0.8.52 — https://github.com/google/zerocopy
|
|
588
|
-
- zerocopy 0.8.52 — https://github.com/google/zerocopy
|
|
551
|
+
- zerocopy-derive 0.8.63 — https://github.com/google/zerocopy
|
|
552
|
+
- zerocopy 0.8.63 — https://github.com/google/zerocopy
|
|
589
553
|
|
|
590
554
|
```
|
|
591
555
|
Copyright 2023 The Fuchsia Authors
|
|
@@ -683,7 +647,7 @@ SOFTWARE.
|
|
|
683
647
|
|
|
684
648
|
Used by:
|
|
685
649
|
|
|
686
|
-
- bytemuck 1.25.
|
|
650
|
+
- bytemuck 1.25.2 — https://github.com/Lokathor/bytemuck
|
|
687
651
|
|
|
688
652
|
```
|
|
689
653
|
MIT License
|
|
@@ -702,7 +666,38 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
702
666
|
|
|
703
667
|
Used by:
|
|
704
668
|
|
|
705
|
-
-
|
|
669
|
+
- wide 1.7.1 — https://github.com/Lokathor/wide
|
|
670
|
+
|
|
671
|
+
```
|
|
672
|
+
MIT License
|
|
673
|
+
|
|
674
|
+
Copyright (c) 2020 Daniel "Lokathor" Gee
|
|
675
|
+
|
|
676
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
677
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
678
|
+
in the Software without restriction, including without limitation the rights
|
|
679
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
680
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
681
|
+
furnished to do so, subject to the following conditions:
|
|
682
|
+
|
|
683
|
+
The above copyright notice and this permission notice shall be included in all
|
|
684
|
+
copies or substantial portions of the Software.
|
|
685
|
+
|
|
686
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
687
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
688
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
689
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
690
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
691
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
692
|
+
SOFTWARE.
|
|
693
|
+
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
## MIT License
|
|
697
|
+
|
|
698
|
+
Used by:
|
|
699
|
+
|
|
700
|
+
- safe_arch 1.2.0 — https://github.com/Lokathor/safe_arch
|
|
706
701
|
|
|
707
702
|
```
|
|
708
703
|
MIT License
|
|
@@ -721,9 +716,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
721
716
|
|
|
722
717
|
Used by:
|
|
723
718
|
|
|
724
|
-
- autd3-rs-core 0.
|
|
725
|
-
- autd3-rs-modulation 0.
|
|
726
|
-
- autd3-cpu-wire 0.
|
|
719
|
+
- autd3-rs-core 0.13.0 — https://github.com/shinolab/autd3-sdk
|
|
720
|
+
- autd3-rs-modulation 0.13.0 — https://github.com/shinolab/autd3-sdk
|
|
721
|
+
- autd3-cpu-wire 0.13.0 — https://github.com/shinolab/autd3-sdk
|
|
727
722
|
|
|
728
723
|
```
|
|
729
724
|
MIT License
|
|
@@ -754,9 +749,8 @@ SOFTWARE.
|
|
|
754
749
|
|
|
755
750
|
Used by:
|
|
756
751
|
|
|
757
|
-
- autd3-ffi-abi 0.
|
|
758
|
-
- autd3-ffi-modulation 0.
|
|
759
|
-
- wide 1.5.0 — https://github.com/Lokathor/wide
|
|
752
|
+
- autd3-ffi-abi 0.13.0 — https://github.com/shinolab/autd3-sdk
|
|
753
|
+
- autd3-ffi-modulation 0.13.0 — https://github.com/shinolab/autd3-sdk
|
|
760
754
|
|
|
761
755
|
```
|
|
762
756
|
MIT License
|
|
@@ -784,13 +778,13 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
784
778
|
|
|
785
779
|
Used by:
|
|
786
780
|
|
|
787
|
-
-
|
|
788
|
-
-
|
|
789
|
-
-
|
|
790
|
-
- syn
|
|
791
|
-
- thiserror-impl 2.0.
|
|
792
|
-
- thiserror 2.0.
|
|
793
|
-
- unicode-ident 1.0.
|
|
781
|
+
- proc-macro2 1.0.107 — https://github.com/dtolnay/proc-macro2
|
|
782
|
+
- quote 1.0.47 — https://github.com/dtolnay/quote
|
|
783
|
+
- syn 2.0.119 — https://github.com/dtolnay/syn
|
|
784
|
+
- syn 3.0.9 — https://github.com/dtolnay/syn
|
|
785
|
+
- thiserror-impl 2.0.21 — https://github.com/dtolnay/thiserror
|
|
786
|
+
- thiserror 2.0.21 — https://github.com/dtolnay/thiserror
|
|
787
|
+
- unicode-ident 1.0.27 — https://github.com/dtolnay/unicode-ident
|
|
794
788
|
|
|
795
789
|
```
|
|
796
790
|
Permission is hereby granted, free of charge, to any
|
|
@@ -823,37 +817,6 @@ DEALINGS IN THE SOFTWARE.
|
|
|
823
817
|
|
|
824
818
|
Used by:
|
|
825
819
|
|
|
826
|
-
- tracing-core 0.1.36 — https://github.com/tokio-rs/tracing
|
|
827
|
-
|
|
828
|
-
```
|
|
829
|
-
The MIT License (MIT)
|
|
830
|
-
|
|
831
|
-
Copyright (c) 2014 Mathijs van de Nes
|
|
832
|
-
|
|
833
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
834
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
835
|
-
in the Software without restriction, including without limitation the rights
|
|
836
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
837
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
838
|
-
furnished to do so, subject to the following conditions:
|
|
839
|
-
|
|
840
|
-
The above copyright notice and this permission notice shall be included in all
|
|
841
|
-
copies or substantial portions of the Software.
|
|
842
|
-
|
|
843
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
844
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
845
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
846
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
847
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
848
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
849
|
-
SOFTWARE.
|
|
850
|
-
|
|
851
|
-
```
|
|
852
|
-
|
|
853
|
-
## MIT License
|
|
854
|
-
|
|
855
|
-
Used by:
|
|
856
|
-
|
|
857
820
|
- typenum 1.20.1 — https://github.com/paholg/typenum
|
|
858
821
|
|
|
859
822
|
```
|
|
@@ -885,7 +848,7 @@ SOFTWARE.
|
|
|
885
848
|
|
|
886
849
|
Used by:
|
|
887
850
|
|
|
888
|
-
- unicode-ident 1.0.
|
|
851
|
+
- unicode-ident 1.0.27 — https://github.com/dtolnay/unicode-ident
|
|
889
852
|
|
|
890
853
|
```
|
|
891
854
|
UNICODE LICENSE V3
|
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.modulation"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.13.0",
|
|
9
9
|
"displayName": "AUTD3 Modulation",
|
|
10
10
|
"description": "AUTD3 amplitude modulation waveforms (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.
|
|
18
|
+
"com.shinolab.autd3-sdk.core": "0.13.0"
|
|
19
19
|
}
|
|
20
20
|
}
|