com.shinolab.autd3-sdk.modulation 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.Modulation.asmdef +16 -0
- package/AUTD3.Modulation.asmdef.meta +7 -0
- package/AssemblyInfo.cs +5 -0
- package/AssemblyInfo.cs.meta +11 -0
- package/LICENSE.md +21 -0
- package/LICENSE.md.meta +7 -0
- package/Modulation.cs +419 -0
- package/Modulation.cs.meta +11 -0
- package/ModulationOps.cs +84 -0
- package/ModulationOps.cs.meta +11 -0
- package/Plugins/linux-x64/libautd3_modulation.so +0 -0
- package/Plugins/linux-x64/libautd3_modulation.so.meta +35 -0
- package/Plugins/linux-x64.meta +8 -0
- package/Plugins/osx-arm64/libautd3_modulation.dylib +0 -0
- package/Plugins/osx-arm64/libautd3_modulation.dylib.meta +35 -0
- package/Plugins/osx-arm64.meta +8 -0
- package/Plugins/win-x64/autd3_modulation.dll +0 -0
- package/Plugins/win-x64/autd3_modulation.dll.meta +35 -0
- package/Plugins/win-x64.meta +8 -0
- package/Plugins.meta +8 -0
- package/README.md +41 -0
- package/README.md.meta +7 -0
- package/THIRD-PARTY-LICENSES.md +835 -0
- package/THIRD-PARTY-LICENSES.md.meta +7 -0
- package/csc.rsp +2 -0
- package/csc.rsp.meta +7 -0
- package/package.json +15 -0
- package/package.json.meta +7 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "AUTD3.Modulation",
|
|
3
|
+
"rootNamespace": "AUTD3",
|
|
4
|
+
"references": [
|
|
5
|
+
"AUTD3.Core"
|
|
6
|
+
],
|
|
7
|
+
"includePlatforms": [],
|
|
8
|
+
"excludePlatforms": [],
|
|
9
|
+
"allowUnsafeCode": false,
|
|
10
|
+
"overrideReferences": false,
|
|
11
|
+
"precompiledReferences": [],
|
|
12
|
+
"autoReferenced": true,
|
|
13
|
+
"defineConstraints": [],
|
|
14
|
+
"versionDefines": [],
|
|
15
|
+
"noEngineReferences": false
|
|
16
|
+
}
|
package/AssemblyInfo.cs
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shun Suzuki
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/LICENSE.md.meta
ADDED
package/Modulation.cs
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using System.Runtime.InteropServices;
|
|
5
|
+
|
|
6
|
+
namespace AUTD3
|
|
7
|
+
{
|
|
8
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
9
|
+
internal struct SineComponentNative
|
|
10
|
+
{
|
|
11
|
+
public byte Mode;
|
|
12
|
+
public float Freq;
|
|
13
|
+
public uint FreqInt;
|
|
14
|
+
public IntPtr Option;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
internal static class NativeModulation
|
|
18
|
+
{
|
|
19
|
+
private const string Lib = "autd3_modulation";
|
|
20
|
+
|
|
21
|
+
[DllImport(Lib)]
|
|
22
|
+
internal static extern IntPtr autd3_modulation_buffer_new();
|
|
23
|
+
|
|
24
|
+
[DllImport(Lib)]
|
|
25
|
+
internal static extern IntPtr autd3_modulation_buffer_from_bytes(byte[] data, UIntPtr len);
|
|
26
|
+
|
|
27
|
+
[DllImport(Lib)]
|
|
28
|
+
internal static extern UIntPtr autd3_modulation_buffer_len(IntPtr buffer);
|
|
29
|
+
|
|
30
|
+
[DllImport(Lib)]
|
|
31
|
+
internal static extern int autd3_modulation_buffer_get(IntPtr buffer, UIntPtr index, out byte @out);
|
|
32
|
+
|
|
33
|
+
[DllImport(Lib)]
|
|
34
|
+
internal static extern int autd3_modulation_buffer_set(IntPtr buffer, UIntPtr index, byte value);
|
|
35
|
+
|
|
36
|
+
[DllImport(Lib)]
|
|
37
|
+
internal static extern void autd3_modulation_buffer_free(IntPtr buffer);
|
|
38
|
+
|
|
39
|
+
[DllImport(Lib)]
|
|
40
|
+
[return: MarshalAs(UnmanagedType.I1)]
|
|
41
|
+
internal static extern bool autd3_modulation_samples_per_period(ushort divider, uint freqHz, out uint outValue);
|
|
42
|
+
|
|
43
|
+
[DllImport(Lib)]
|
|
44
|
+
internal static extern IntPtr autd3_modulation_sine_option_new(byte amplitude, byte offset, float phase, [MarshalAs(UnmanagedType.I1)] bool clamp, IntPtr samplingConfig);
|
|
45
|
+
|
|
46
|
+
[DllImport(Lib)]
|
|
47
|
+
internal static extern void autd3_modulation_sine_option_free(IntPtr option);
|
|
48
|
+
|
|
49
|
+
[DllImport(Lib)]
|
|
50
|
+
internal static extern int autd3_modulation_sine(byte mode, float freq, uint freqInt, IntPtr option, IntPtr buffer);
|
|
51
|
+
|
|
52
|
+
[DllImport(Lib)]
|
|
53
|
+
internal static extern IntPtr autd3_modulation_square_option_new(byte low, byte high, float duty, IntPtr samplingConfig);
|
|
54
|
+
|
|
55
|
+
[DllImport(Lib)]
|
|
56
|
+
internal static extern void autd3_modulation_square_option_free(IntPtr option);
|
|
57
|
+
|
|
58
|
+
[DllImport(Lib)]
|
|
59
|
+
internal static extern int autd3_modulation_square(byte mode, float freq, uint freqInt, IntPtr option, IntPtr buffer);
|
|
60
|
+
|
|
61
|
+
[DllImport(Lib)]
|
|
62
|
+
internal static extern IntPtr autd3_modulation_fourier_option_new([MarshalAs(UnmanagedType.I1)] bool hasScaleFactor, float scaleFactor, [MarshalAs(UnmanagedType.I1)] bool clamp, byte offset);
|
|
63
|
+
|
|
64
|
+
[DllImport(Lib)]
|
|
65
|
+
internal static extern void autd3_modulation_fourier_option_free(IntPtr option);
|
|
66
|
+
|
|
67
|
+
[DllImport(Lib)]
|
|
68
|
+
internal static extern int autd3_modulation_fourier(SineComponentNative[] components, UIntPtr numComponents, IntPtr option, IntPtr buffer);
|
|
69
|
+
|
|
70
|
+
[DllImport(Lib)]
|
|
71
|
+
internal static extern int autd3_modulation_constant(byte intensity, IntPtr buffer);
|
|
72
|
+
|
|
73
|
+
[DllImport(Lib)]
|
|
74
|
+
internal static extern int autd3_modulation_radiation_pressure(IntPtr src, IntPtr dst);
|
|
75
|
+
|
|
76
|
+
[DllImport(Lib)]
|
|
77
|
+
internal static extern int autd3_modulation_radiation_pressure_inplace(IntPtr buffer);
|
|
78
|
+
|
|
79
|
+
[DllImport("autd3capi")]
|
|
80
|
+
internal static extern IntPtr autd3_op_modulation(byte bank, IntPtr samplingConfig, IntPtr modulationBuffer, ushort loopRep, byte transitionMode, ulong transitionValue);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public sealed class ModulationBuffer : IDisposable, IEnumerable<byte>
|
|
84
|
+
{
|
|
85
|
+
internal IntPtr Handle { get; private set; }
|
|
86
|
+
|
|
87
|
+
private ModulationBuffer(IntPtr handle)
|
|
88
|
+
{
|
|
89
|
+
if (handle == IntPtr.Zero)
|
|
90
|
+
{
|
|
91
|
+
throw new Autd3Exception("failed to create modulation buffer");
|
|
92
|
+
}
|
|
93
|
+
Handle = handle;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
internal ModulationBuffer() : this(NativeModulation.autd3_modulation_buffer_new())
|
|
97
|
+
{
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public ModulationBuffer(int length) : this(length == 0
|
|
101
|
+
? NativeModulation.autd3_modulation_buffer_new()
|
|
102
|
+
: NativeModulation.autd3_modulation_buffer_from_bytes(new byte[length], (UIntPtr)length))
|
|
103
|
+
{
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public static ModulationBuffer FromBytes(byte[] data) =>
|
|
107
|
+
new ModulationBuffer(NativeModulation.autd3_modulation_buffer_from_bytes(data, (UIntPtr)data.Length));
|
|
108
|
+
|
|
109
|
+
public int Length => (int)NativeModulation.autd3_modulation_buffer_len(Handle);
|
|
110
|
+
|
|
111
|
+
public byte this[int index]
|
|
112
|
+
{
|
|
113
|
+
get
|
|
114
|
+
{
|
|
115
|
+
if (NativeModulation.autd3_modulation_buffer_get(Handle, (UIntPtr)index, out var value) != 0)
|
|
116
|
+
throw new ArgumentOutOfRangeException(nameof(index));
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
set
|
|
120
|
+
{
|
|
121
|
+
if (NativeModulation.autd3_modulation_buffer_set(Handle, (UIntPtr)index, value) != 0)
|
|
122
|
+
throw new ArgumentOutOfRangeException(nameof(index));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public IEnumerator<byte> GetEnumerator()
|
|
127
|
+
{
|
|
128
|
+
var length = Length;
|
|
129
|
+
for (var i = 0; i < length; i++)
|
|
130
|
+
{
|
|
131
|
+
yield return this[i];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
136
|
+
|
|
137
|
+
public void Dispose()
|
|
138
|
+
{
|
|
139
|
+
if (Handle != IntPtr.Zero)
|
|
140
|
+
{
|
|
141
|
+
NativeModulation.autd3_modulation_buffer_free(Handle);
|
|
142
|
+
Handle = IntPtr.Zero;
|
|
143
|
+
}
|
|
144
|
+
GC.SuppressFinalize(this);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
~ModulationBuffer()
|
|
148
|
+
{
|
|
149
|
+
if (Handle != IntPtr.Zero)
|
|
150
|
+
{
|
|
151
|
+
NativeModulation.autd3_modulation_buffer_free(Handle);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public readonly struct SineOption
|
|
157
|
+
{
|
|
158
|
+
public byte Amplitude { get; }
|
|
159
|
+
public byte Offset { get; }
|
|
160
|
+
public Angle Phase { get; }
|
|
161
|
+
public bool Clamp { get; }
|
|
162
|
+
public SamplingConfig SamplingConfig { get; }
|
|
163
|
+
|
|
164
|
+
public SineOption() : this(amplitude: 0xFF)
|
|
165
|
+
{
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public SineOption(byte amplitude = 0xFF, byte offset = 0x80, Angle phase = default, bool clamp = false, SamplingConfig? samplingConfig = null)
|
|
169
|
+
{
|
|
170
|
+
Amplitude = amplitude;
|
|
171
|
+
Offset = offset;
|
|
172
|
+
Phase = phase;
|
|
173
|
+
Clamp = clamp;
|
|
174
|
+
SamplingConfig = samplingConfig ?? SamplingConfig.Freq4k;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
public readonly struct SquareOption
|
|
179
|
+
{
|
|
180
|
+
public byte Low { get; }
|
|
181
|
+
public byte High { get; }
|
|
182
|
+
public float Duty { get; }
|
|
183
|
+
public SamplingConfig SamplingConfig { get; }
|
|
184
|
+
|
|
185
|
+
public SquareOption() : this(low: 0x00)
|
|
186
|
+
{
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
public SquareOption(byte low = 0x00, byte high = 0xFF, float duty = 0.5f, SamplingConfig? samplingConfig = null)
|
|
190
|
+
{
|
|
191
|
+
Low = low;
|
|
192
|
+
High = high;
|
|
193
|
+
Duty = duty;
|
|
194
|
+
SamplingConfig = samplingConfig ?? SamplingConfig.Freq4k;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
public readonly struct FourierOption
|
|
199
|
+
{
|
|
200
|
+
public float? ScaleFactor { get; }
|
|
201
|
+
public bool Clamp { get; }
|
|
202
|
+
public byte Offset { get; }
|
|
203
|
+
|
|
204
|
+
public FourierOption(float? scaleFactor = null, bool clamp = false, byte offset = 0x00)
|
|
205
|
+
{
|
|
206
|
+
ScaleFactor = scaleFactor;
|
|
207
|
+
Clamp = clamp;
|
|
208
|
+
Offset = offset;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
public readonly struct SineComponent
|
|
213
|
+
{
|
|
214
|
+
public Freq Freq { get; }
|
|
215
|
+
public SineOption Option { get; }
|
|
216
|
+
private readonly bool _nearest;
|
|
217
|
+
|
|
218
|
+
public SineComponent(Freq freq, SineOption option)
|
|
219
|
+
{
|
|
220
|
+
Freq = freq;
|
|
221
|
+
Option = option;
|
|
222
|
+
_nearest = false;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
public SineComponent(Nearest<Freq> freq, SineOption option)
|
|
226
|
+
{
|
|
227
|
+
Freq = freq.Value;
|
|
228
|
+
Option = option;
|
|
229
|
+
_nearest = true;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
internal byte ModeCode => _nearest ? (byte)2 : Freq.ModeCode;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
public sealed class Modulation : ICommand
|
|
236
|
+
{
|
|
237
|
+
private readonly ModulationBank _bank;
|
|
238
|
+
private readonly SamplingConfig _samplingConfig;
|
|
239
|
+
private readonly ModulationBuffer _buffer;
|
|
240
|
+
private readonly LoopBehavior _loopBehavior;
|
|
241
|
+
private readonly TransitionMode _transitionMode;
|
|
242
|
+
|
|
243
|
+
public Modulation(SamplingConfig config, ModulationBuffer data, LoopBehavior? loopBehavior = null, TransitionMode? transitionMode = null)
|
|
244
|
+
: this(ModulationBank.B0, config, data, loopBehavior, transitionMode)
|
|
245
|
+
{
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public Modulation(ModulationBank bank, SamplingConfig config, ModulationBuffer data, LoopBehavior? loopBehavior = null, TransitionMode? transitionMode = null)
|
|
249
|
+
{
|
|
250
|
+
_bank = bank;
|
|
251
|
+
_samplingConfig = config;
|
|
252
|
+
_buffer = data;
|
|
253
|
+
_loopBehavior = loopBehavior ?? LoopBehavior.Infinite;
|
|
254
|
+
_transitionMode = transitionMode ?? TransitionMode.Immediate;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
public static ModulationBuffer ModulationBuffer() => new ModulationBuffer();
|
|
258
|
+
|
|
259
|
+
public static uint SamplesPerPeriod(ushort divider, uint freqHz)
|
|
260
|
+
{
|
|
261
|
+
if (!NativeModulation.autd3_modulation_samples_per_period(divider, freqHz, out var value))
|
|
262
|
+
{
|
|
263
|
+
throw new Autd3Exception("samples_per_period is not an integer for the given frequency");
|
|
264
|
+
}
|
|
265
|
+
return value;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
IntPtr ICommand.CreateOp()
|
|
269
|
+
{
|
|
270
|
+
var sampling = _samplingConfig.CreateHandle();
|
|
271
|
+
try
|
|
272
|
+
{
|
|
273
|
+
return NativeModulation.autd3_op_modulation(
|
|
274
|
+
(byte)_bank, sampling, _buffer.Handle, _loopBehavior.Rep, _transitionMode.Mode, _transitionMode.Value);
|
|
275
|
+
}
|
|
276
|
+
finally
|
|
277
|
+
{
|
|
278
|
+
NativeCore.autd3_core_sampling_config_free(sampling);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
public static void Sine(Nearest<Freq> freq, SineOption option, ModulationBuffer dst) =>
|
|
283
|
+
Sine(freq.Value, 2, option, dst);
|
|
284
|
+
|
|
285
|
+
public static void Sine(Freq freq, SineOption option, ModulationBuffer dst) =>
|
|
286
|
+
Sine(freq, freq.ModeCode, option, dst);
|
|
287
|
+
|
|
288
|
+
private static void Sine(Freq freq, byte modeCode, SineOption option, ModulationBuffer dst)
|
|
289
|
+
{
|
|
290
|
+
var sampling = option.SamplingConfig.CreateHandle();
|
|
291
|
+
try
|
|
292
|
+
{
|
|
293
|
+
var optionHandle = NativeModulation.autd3_modulation_sine_option_new(
|
|
294
|
+
option.Amplitude, option.Offset, option.Phase.Radian, option.Clamp, sampling);
|
|
295
|
+
try
|
|
296
|
+
{
|
|
297
|
+
if (NativeModulation.autd3_modulation_sine(modeCode, freq.HzValue, freq.HzIntValue, optionHandle, dst.Handle) != 0)
|
|
298
|
+
{
|
|
299
|
+
throw new Autd3Exception("sine modulation failed");
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
finally
|
|
303
|
+
{
|
|
304
|
+
NativeModulation.autd3_modulation_sine_option_free(optionHandle);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
finally
|
|
308
|
+
{
|
|
309
|
+
NativeCore.autd3_core_sampling_config_free(sampling);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
public static void Square(Nearest<Freq> freq, SquareOption option, ModulationBuffer dst) =>
|
|
314
|
+
Square(freq.Value, 2, option, dst);
|
|
315
|
+
|
|
316
|
+
public static void Square(Freq freq, SquareOption option, ModulationBuffer dst) =>
|
|
317
|
+
Square(freq, freq.ModeCode, option, dst);
|
|
318
|
+
|
|
319
|
+
private static void Square(Freq freq, byte modeCode, SquareOption option, ModulationBuffer dst)
|
|
320
|
+
{
|
|
321
|
+
var sampling = option.SamplingConfig.CreateHandle();
|
|
322
|
+
try
|
|
323
|
+
{
|
|
324
|
+
var optionHandle = NativeModulation.autd3_modulation_square_option_new(
|
|
325
|
+
option.Low, option.High, option.Duty, sampling);
|
|
326
|
+
try
|
|
327
|
+
{
|
|
328
|
+
if (NativeModulation.autd3_modulation_square(modeCode, freq.HzValue, freq.HzIntValue, optionHandle, dst.Handle) != 0)
|
|
329
|
+
{
|
|
330
|
+
throw new Autd3Exception("square modulation failed");
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
finally
|
|
334
|
+
{
|
|
335
|
+
NativeModulation.autd3_modulation_square_option_free(optionHandle);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
finally
|
|
339
|
+
{
|
|
340
|
+
NativeCore.autd3_core_sampling_config_free(sampling);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
public static void Constant(byte intensity, ModulationBuffer dst)
|
|
345
|
+
{
|
|
346
|
+
if (NativeModulation.autd3_modulation_constant(intensity, dst.Handle) != 0)
|
|
347
|
+
{
|
|
348
|
+
throw new Autd3Exception("constant modulation failed");
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
public static void Fourier(SineComponent[] components, FourierOption option, ModulationBuffer dst)
|
|
353
|
+
{
|
|
354
|
+
var samplingHandles = new List<IntPtr>();
|
|
355
|
+
var optionHandles = new List<IntPtr>();
|
|
356
|
+
var native = new SineComponentNative[components.Length];
|
|
357
|
+
try
|
|
358
|
+
{
|
|
359
|
+
for (var i = 0; i < components.Length; i++)
|
|
360
|
+
{
|
|
361
|
+
var c = components[i];
|
|
362
|
+
var sampling = c.Option.SamplingConfig.CreateHandle();
|
|
363
|
+
samplingHandles.Add(sampling);
|
|
364
|
+
var optionHandle = NativeModulation.autd3_modulation_sine_option_new(
|
|
365
|
+
c.Option.Amplitude, c.Option.Offset, c.Option.Phase.Radian, c.Option.Clamp, sampling);
|
|
366
|
+
optionHandles.Add(optionHandle);
|
|
367
|
+
native[i] = new SineComponentNative
|
|
368
|
+
{
|
|
369
|
+
Mode = c.ModeCode,
|
|
370
|
+
Freq = c.Freq.HzValue,
|
|
371
|
+
FreqInt = c.Freq.HzIntValue,
|
|
372
|
+
Option = optionHandle,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
var fourierOption = NativeModulation.autd3_modulation_fourier_option_new(
|
|
377
|
+
option.ScaleFactor.HasValue, option.ScaleFactor ?? 0f, option.Clamp, option.Offset);
|
|
378
|
+
try
|
|
379
|
+
{
|
|
380
|
+
if (NativeModulation.autd3_modulation_fourier(native, (UIntPtr)components.Length, fourierOption, dst.Handle) != 0)
|
|
381
|
+
{
|
|
382
|
+
throw new Autd3Exception("fourier modulation failed");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
finally
|
|
386
|
+
{
|
|
387
|
+
NativeModulation.autd3_modulation_fourier_option_free(fourierOption);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
finally
|
|
391
|
+
{
|
|
392
|
+
foreach (var optionHandle in optionHandles)
|
|
393
|
+
{
|
|
394
|
+
NativeModulation.autd3_modulation_sine_option_free(optionHandle);
|
|
395
|
+
}
|
|
396
|
+
foreach (var sampling in samplingHandles)
|
|
397
|
+
{
|
|
398
|
+
NativeCore.autd3_core_sampling_config_free(sampling);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
public static void RadiationPressure(ModulationBuffer src, ModulationBuffer dst)
|
|
404
|
+
{
|
|
405
|
+
if (NativeModulation.autd3_modulation_radiation_pressure(src.Handle, dst.Handle) != 0)
|
|
406
|
+
{
|
|
407
|
+
throw new Autd3Exception("radiation pressure failed");
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
public static void RadiationPressureInplace(ModulationBuffer buffer)
|
|
412
|
+
{
|
|
413
|
+
if (NativeModulation.autd3_modulation_radiation_pressure_inplace(buffer.Handle) != 0)
|
|
414
|
+
{
|
|
415
|
+
throw new Autd3Exception("radiation pressure failed");
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
package/ModulationOps.cs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Runtime.InteropServices;
|
|
3
|
+
|
|
4
|
+
namespace AUTD3
|
|
5
|
+
{
|
|
6
|
+
public enum ModulationBank : byte
|
|
7
|
+
{
|
|
8
|
+
B0 = 0,
|
|
9
|
+
B1 = 1,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
internal static class NativeModulationOp
|
|
13
|
+
{
|
|
14
|
+
[DllImport("autd3capi")]
|
|
15
|
+
internal static extern IntPtr autd3_op_write_modulation_buffer(byte bank, uint offset, IntPtr modulationBuffer);
|
|
16
|
+
|
|
17
|
+
[DllImport("autd3capi")]
|
|
18
|
+
internal static extern IntPtr autd3_op_config_modulation(byte bank, IntPtr samplingConfig, uint size, ushort rep);
|
|
19
|
+
|
|
20
|
+
[DllImport("autd3capi")]
|
|
21
|
+
internal static extern IntPtr autd3_op_change_modulation_bank(byte bank, byte transitionMode, ulong transitionValue);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public sealed class WriteModulationBuffer : ICommand
|
|
25
|
+
{
|
|
26
|
+
private readonly ModulationBank _bank;
|
|
27
|
+
private readonly uint _offset;
|
|
28
|
+
private readonly ModulationBuffer _buffer;
|
|
29
|
+
|
|
30
|
+
public WriteModulationBuffer(ModulationBank bank, uint offset, ModulationBuffer data)
|
|
31
|
+
{
|
|
32
|
+
_bank = bank;
|
|
33
|
+
_offset = offset;
|
|
34
|
+
_buffer = data;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
IntPtr ICommand.CreateOp() =>
|
|
38
|
+
NativeModulationOp.autd3_op_write_modulation_buffer((byte)_bank, _offset, _buffer.Handle);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public sealed class ConfigModulation : ICommand
|
|
42
|
+
{
|
|
43
|
+
private readonly ModulationBank _bank;
|
|
44
|
+
private readonly SamplingConfig _config;
|
|
45
|
+
private readonly uint _size;
|
|
46
|
+
private readonly LoopBehavior _loopBehavior;
|
|
47
|
+
|
|
48
|
+
public ConfigModulation(ModulationBank bank, SamplingConfig config, uint size, LoopBehavior? loopBehavior = null)
|
|
49
|
+
{
|
|
50
|
+
_bank = bank;
|
|
51
|
+
_config = config;
|
|
52
|
+
_size = size;
|
|
53
|
+
_loopBehavior = loopBehavior ?? LoopBehavior.Infinite;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
IntPtr ICommand.CreateOp()
|
|
57
|
+
{
|
|
58
|
+
var sampling = _config.CreateHandle();
|
|
59
|
+
try
|
|
60
|
+
{
|
|
61
|
+
return NativeModulationOp.autd3_op_config_modulation((byte)_bank, sampling, _size, _loopBehavior.Rep);
|
|
62
|
+
}
|
|
63
|
+
finally
|
|
64
|
+
{
|
|
65
|
+
NativeCore.autd3_core_sampling_config_free(sampling);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public sealed class ChangeModulationBank : ICommand
|
|
71
|
+
{
|
|
72
|
+
private readonly ModulationBank _bank;
|
|
73
|
+
private readonly TransitionMode _transitionMode;
|
|
74
|
+
|
|
75
|
+
public ChangeModulationBank(ModulationBank bank, TransitionMode? transitionMode = null)
|
|
76
|
+
{
|
|
77
|
+
_bank = bank;
|
|
78
|
+
_transitionMode = transitionMode ?? TransitionMode.Immediate;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
IntPtr ICommand.CreateOp() =>
|
|
82
|
+
NativeModulationOp.autd3_op_change_modulation_bank((byte)_bank, _transitionMode.Mode, _transitionMode.Value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 80920448acf46755a6b54e8acb05e3ac
|
|
3
|
+
PluginImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
iconMap: {}
|
|
7
|
+
executionOrder: {}
|
|
8
|
+
defineConstraints: []
|
|
9
|
+
isPreloaded: 0
|
|
10
|
+
isOverridable: 0
|
|
11
|
+
isExplicitlyReferenced: 0
|
|
12
|
+
validateReferences: 1
|
|
13
|
+
platformData:
|
|
14
|
+
- first:
|
|
15
|
+
Any:
|
|
16
|
+
second:
|
|
17
|
+
enabled: 0
|
|
18
|
+
settings: {}
|
|
19
|
+
- first:
|
|
20
|
+
Editor: Editor
|
|
21
|
+
second:
|
|
22
|
+
enabled: 1
|
|
23
|
+
settings:
|
|
24
|
+
CPU: x86_64
|
|
25
|
+
DefaultValueInitialized: true
|
|
26
|
+
OS: Linux
|
|
27
|
+
- first:
|
|
28
|
+
Standalone: Linux64
|
|
29
|
+
second:
|
|
30
|
+
enabled: 1
|
|
31
|
+
settings:
|
|
32
|
+
CPU: x86_64
|
|
33
|
+
userData:
|
|
34
|
+
assetBundleName:
|
|
35
|
+
assetBundleVariant:
|
|
Binary file
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: fdf59d6384f3a749bf6b5312a0243f1a
|
|
3
|
+
PluginImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
iconMap: {}
|
|
7
|
+
executionOrder: {}
|
|
8
|
+
defineConstraints: []
|
|
9
|
+
isPreloaded: 0
|
|
10
|
+
isOverridable: 0
|
|
11
|
+
isExplicitlyReferenced: 0
|
|
12
|
+
validateReferences: 1
|
|
13
|
+
platformData:
|
|
14
|
+
- first:
|
|
15
|
+
Any:
|
|
16
|
+
second:
|
|
17
|
+
enabled: 0
|
|
18
|
+
settings: {}
|
|
19
|
+
- first:
|
|
20
|
+
Editor: Editor
|
|
21
|
+
second:
|
|
22
|
+
enabled: 1
|
|
23
|
+
settings:
|
|
24
|
+
CPU: ARM64
|
|
25
|
+
DefaultValueInitialized: true
|
|
26
|
+
OS: OSX
|
|
27
|
+
- first:
|
|
28
|
+
Standalone: OSXUniversal
|
|
29
|
+
second:
|
|
30
|
+
enabled: 1
|
|
31
|
+
settings:
|
|
32
|
+
CPU: ARM64
|
|
33
|
+
userData:
|
|
34
|
+
assetBundleName:
|
|
35
|
+
assetBundleVariant:
|