@grame/faustwasm 0.7.10 → 0.8.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/README.md +2 -2
- package/assets/standalone/faustwasm/index.d.ts +76 -9
- package/assets/standalone/faustwasm/index.js +270 -77
- package/assets/standalone/faustwasm/index.js.map +4 -4
- package/assets/standalone/index-pwa.js +7 -8
- package/assets/standalone/index-template.js +2 -2
- package/assets/standalone/index.js +59 -61
- package/assets/standalone/service-worker.js +47 -8
- package/dist/cjs/index.d.ts +76 -9
- package/dist/cjs/index.js +270 -77
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs-bundle/index.d.ts +76 -9
- package/dist/cjs-bundle/index.js +270 -77
- package/dist/cjs-bundle/index.js.map +4 -4
- package/dist/esm/index.d.ts +76 -9
- package/dist/esm/index.js +270 -77
- package/dist/esm/index.js.map +4 -4
- package/dist/esm-bundle/index.d.ts +76 -9
- package/dist/esm-bundle/index.js +270 -77
- package/dist/esm-bundle/index.js.map +4 -4
- package/package.json +1 -1
- package/src/FaustAudioWorkletCommunicator.ts +143 -0
- package/src/FaustAudioWorkletNode.ts +23 -12
- package/src/FaustAudioWorkletProcessor.ts +34 -15
- package/src/FaustDspGenerator.ts +20 -2
- package/src/FaustFFTAudioWorkletProcessor.ts +31 -2
- package/src/FaustOfflineProcessor.ts +6 -0
- package/src/FaustScriptProcessorNode.ts +4 -1
- package/src/FaustWebAudioDsp.ts +38 -10
- package/test/faustlive-wasm/faustwasm/index.d.ts +76 -9
- package/test/faustlive-wasm/faustwasm/index.js +270 -77
- package/test/faustlive-wasm/faustwasm/index.js.map +4 -4
- package/assets/standalone/coi-serviceworker.js +0 -146
|
@@ -237,6 +237,49 @@ export declare const instantiateFaustModule: (FaustModuleFactoryIn?: FaustModule
|
|
|
237
237
|
* @param wasmFile path to `libfaust-wasm.wasm`
|
|
238
238
|
*/
|
|
239
239
|
export declare const instantiateFaustModuleFromFile: (jsFile: string, dataFile?: string, wasmFile?: string) => Promise<FaustModule>;
|
|
240
|
+
declare class FaustAudioWorkletCommunicator {
|
|
241
|
+
protected readonly port: MessagePort;
|
|
242
|
+
protected readonly supportSharedArrayBuffer: boolean;
|
|
243
|
+
protected readonly byteLength: number;
|
|
244
|
+
protected uin8Invert: Uint8ClampedArray;
|
|
245
|
+
protected uin8NewAccData: Uint8ClampedArray;
|
|
246
|
+
protected uin8NewGyrData: Uint8ClampedArray;
|
|
247
|
+
protected f32Acc: Float32Array;
|
|
248
|
+
protected f32Gyr: Float32Array;
|
|
249
|
+
constructor(port: MessagePort);
|
|
250
|
+
initializeBuffer(ab: SharedArrayBuffer | ArrayBuffer): void;
|
|
251
|
+
setNewAccDataAvailable(value: boolean): void;
|
|
252
|
+
getNewAccDataAvailable(): boolean;
|
|
253
|
+
setNewGyrDataAvailable(value: boolean): void;
|
|
254
|
+
getNewGyrDataAvailable(): boolean;
|
|
255
|
+
setAcc({ x, y, z }: {
|
|
256
|
+
x: number;
|
|
257
|
+
y: number;
|
|
258
|
+
z: number;
|
|
259
|
+
}, invert?: boolean): void;
|
|
260
|
+
getAcc(): {
|
|
261
|
+
x: number;
|
|
262
|
+
y: number;
|
|
263
|
+
z: number;
|
|
264
|
+
invert: boolean;
|
|
265
|
+
} | undefined;
|
|
266
|
+
setGyr({ alpha, beta, gamma }: {
|
|
267
|
+
alpha: number;
|
|
268
|
+
beta: number;
|
|
269
|
+
gamma: number;
|
|
270
|
+
}): void;
|
|
271
|
+
getGyr(): {
|
|
272
|
+
alpha: number;
|
|
273
|
+
beta: number;
|
|
274
|
+
gamma: number;
|
|
275
|
+
} | undefined;
|
|
276
|
+
}
|
|
277
|
+
declare class FaustAudioWorkletNodeCommunicator extends FaustAudioWorkletCommunicator {
|
|
278
|
+
constructor(port: MessagePort);
|
|
279
|
+
}
|
|
280
|
+
declare class FaustAudioWorkletProcessorCommunicator extends FaustAudioWorkletCommunicator {
|
|
281
|
+
constructor(port: MessagePort);
|
|
282
|
+
}
|
|
240
283
|
/**
|
|
241
284
|
* The Faust wasm instance interface.
|
|
242
285
|
*/
|
|
@@ -627,6 +670,29 @@ export interface IFaustBaseWebAudioDsp {
|
|
|
627
670
|
* @return the DSP JSON description
|
|
628
671
|
*/
|
|
629
672
|
getJSON(): string;
|
|
673
|
+
/**
|
|
674
|
+
* Start accelerometer and gyroscope handlers.
|
|
675
|
+
*/
|
|
676
|
+
startSensors(): void;
|
|
677
|
+
/**
|
|
678
|
+
* Stop accelerometer and gyroscope handlers.
|
|
679
|
+
*/
|
|
680
|
+
stopSensors(): void;
|
|
681
|
+
/** Indicating if the DSP handles the accelerometer */
|
|
682
|
+
readonly hasAccInput: boolean;
|
|
683
|
+
/**
|
|
684
|
+
* Accelerometer handling.
|
|
685
|
+
* accelerationIncludingGravity: DeviceMotionEvent["accelerationIncludingGravity"]
|
|
686
|
+
* invert: boolean
|
|
687
|
+
*/
|
|
688
|
+
propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
|
|
689
|
+
/** Indicating if the DSP handles the gyroscope */
|
|
690
|
+
readonly hasGyrInput: boolean;
|
|
691
|
+
/**
|
|
692
|
+
* Gyroscope handling.
|
|
693
|
+
* event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">
|
|
694
|
+
*/
|
|
695
|
+
propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
|
|
630
696
|
/**
|
|
631
697
|
* Start the DSP audio processing.
|
|
632
698
|
*/
|
|
@@ -639,14 +705,6 @@ export interface IFaustBaseWebAudioDsp {
|
|
|
639
705
|
* Destroy the DSP.
|
|
640
706
|
*/
|
|
641
707
|
destroy(): void;
|
|
642
|
-
/** Indicating if the DSP handles the accelerometer */
|
|
643
|
-
readonly hasAccInput: boolean;
|
|
644
|
-
/** Accelerometer handling */
|
|
645
|
-
propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
|
|
646
|
-
/** Indicating if the DSP handles the gyroscope */
|
|
647
|
-
readonly hasGyrInput: boolean;
|
|
648
|
-
/** Gyroscope handling */
|
|
649
|
-
propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
|
|
650
708
|
}
|
|
651
709
|
export interface IFaustMonoWebAudioDsp extends IFaustBaseWebAudioDsp {
|
|
652
710
|
}
|
|
@@ -787,6 +845,8 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
|
|
|
787
845
|
start(): void;
|
|
788
846
|
stop(): void;
|
|
789
847
|
destroy(): void;
|
|
848
|
+
startSensors(): void;
|
|
849
|
+
stopSensors(): void;
|
|
790
850
|
}
|
|
791
851
|
export declare class FaustMonoWebAudioDsp extends FaustBaseWebAudioDsp implements IFaustMonoWebAudioDsp {
|
|
792
852
|
private fInstance;
|
|
@@ -883,6 +943,7 @@ export interface FaustAudioWorkletProcessorDependencies<Poly extends boolean = f
|
|
|
883
943
|
FaustPolyWebAudioDsp: Poly extends true ? typeof FaustPolyWebAudioDsp : undefined;
|
|
884
944
|
FaustWebAudioDspVoice: Poly extends true ? typeof FaustWebAudioDspVoice : undefined;
|
|
885
945
|
FaustWasmInstantiator: typeof FaustWasmInstantiator;
|
|
946
|
+
FaustAudioWorkletProcessorCommunicator: typeof FaustAudioWorkletProcessorCommunicator;
|
|
886
947
|
}
|
|
887
948
|
export interface FaustAudioWorkletNodeOptions<Poly extends boolean = false> extends AudioWorkletNodeOptions {
|
|
888
949
|
processorOptions: Poly extends true ? FaustPolyAudioWorkletProcessorOptions : FaustMonoAudioWorkletProcessorOptions;
|
|
@@ -933,6 +994,7 @@ export interface FaustFFTAudioWorkletProcessorDependencies {
|
|
|
933
994
|
FaustBaseWebAudioDsp: typeof FaustBaseWebAudioDsp;
|
|
934
995
|
FaustMonoWebAudioDsp: typeof FaustMonoWebAudioDsp;
|
|
935
996
|
FaustWasmInstantiator: typeof FaustWasmInstantiator;
|
|
997
|
+
FaustAudioWorkletProcessorCommunicator: typeof FaustAudioWorkletProcessorCommunicator;
|
|
936
998
|
FFTUtils: typeof FFTUtils;
|
|
937
999
|
}
|
|
938
1000
|
export interface FaustFFTAudioWorkletNodeOptions extends AudioWorkletNodeOptions {
|
|
@@ -1139,6 +1201,8 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
|
|
|
1139
1201
|
propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
|
|
1140
1202
|
get hasGyrInput(): boolean;
|
|
1141
1203
|
propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
|
|
1204
|
+
startSensors(): void;
|
|
1205
|
+
stopSensors(): void;
|
|
1142
1206
|
/**
|
|
1143
1207
|
* Render frames in an array.
|
|
1144
1208
|
*
|
|
@@ -1295,7 +1359,9 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
|
|
|
1295
1359
|
protected fPlotHandler: PlotHandler | null;
|
|
1296
1360
|
protected fUICallback: UIHandler;
|
|
1297
1361
|
protected fDescriptor: FaustUIInputItem[];
|
|
1362
|
+
protected fCommunicator: FaustAudioWorkletNodeCommunicator;
|
|
1298
1363
|
constructor(context: BaseAudioContext, name: string, factory: LooseFaustDspFactory, options?: Partial<FaustAudioWorkletNodeOptions<Poly>>);
|
|
1364
|
+
protected handleMessageAux: (e: MessageEvent) => void;
|
|
1299
1365
|
private handleDeviceMotion;
|
|
1300
1366
|
private handleDeviceOrientation;
|
|
1301
1367
|
/** Setup accelerometer and gyroscope handlers */
|
|
@@ -1365,8 +1431,9 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
|
|
|
1365
1431
|
protected handleDeviceMotion: any;
|
|
1366
1432
|
protected handleDeviceOrientation: any;
|
|
1367
1433
|
init(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp): void;
|
|
1368
|
-
/**
|
|
1434
|
+
/** Start accelerometer and gyroscope handlers */
|
|
1369
1435
|
startSensors(): Promise<void>;
|
|
1436
|
+
/** Stop accelerometer and gyroscope handlers */
|
|
1370
1437
|
stopSensors(): void;
|
|
1371
1438
|
compute(input: Float32Array[], output: Float32Array[]): boolean;
|
|
1372
1439
|
setOutputParamHandler(handler: OutputParamHandler): void;
|
package/dist/cjs-bundle/index.js
CHANGED
|
@@ -6128,7 +6128,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
6128
6128
|
const { registerProcessor, AudioWorkletProcessor, sampleRate } = globalThis;
|
|
6129
6129
|
const {
|
|
6130
6130
|
FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
|
|
6131
|
-
FaustWasmInstantiator: FaustWasmInstantiator2
|
|
6131
|
+
FaustWasmInstantiator: FaustWasmInstantiator2,
|
|
6132
|
+
FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2
|
|
6132
6133
|
} = dependencies;
|
|
6133
6134
|
const {
|
|
6134
6135
|
processorName,
|
|
@@ -6153,7 +6154,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
6153
6154
|
constructor(options) {
|
|
6154
6155
|
super(options);
|
|
6155
6156
|
this.paramValuesCache = {};
|
|
6156
|
-
this.
|
|
6157
|
+
this.fCommunicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
|
|
6157
6158
|
const { parameterDescriptors } = this.constructor;
|
|
6158
6159
|
parameterDescriptors.forEach((pd) => {
|
|
6159
6160
|
this.paramValuesCache[pd.name] = pd.defaultValue || 0;
|
|
@@ -6200,19 +6201,26 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
6200
6201
|
this.paramValuesCache[path] = paramValue;
|
|
6201
6202
|
}
|
|
6202
6203
|
}
|
|
6204
|
+
if (this.fCommunicator.getNewAccDataAvailable()) {
|
|
6205
|
+
const acc = this.fCommunicator.getAcc();
|
|
6206
|
+
if (acc) {
|
|
6207
|
+
this.fCommunicator.setNewAccDataAvailable(false);
|
|
6208
|
+
const { invert, ...data } = acc;
|
|
6209
|
+
this.propagateAcc(data, invert);
|
|
6210
|
+
}
|
|
6211
|
+
}
|
|
6212
|
+
if (this.fCommunicator.getNewGyrDataAvailable()) {
|
|
6213
|
+
const gyr = this.fCommunicator.getGyr();
|
|
6214
|
+
if (gyr) {
|
|
6215
|
+
this.fCommunicator.setNewGyrDataAvailable(false);
|
|
6216
|
+
this.propagateGyr(gyr);
|
|
6217
|
+
}
|
|
6218
|
+
}
|
|
6203
6219
|
return this.fDSPCode.compute(inputs[0], outputs[0]);
|
|
6204
6220
|
}
|
|
6205
6221
|
handleMessageAux(e) {
|
|
6206
6222
|
const msg = e.data;
|
|
6207
6223
|
switch (msg.type) {
|
|
6208
|
-
case "acc": {
|
|
6209
|
-
this.propagateAcc(msg.data, msg.invert);
|
|
6210
|
-
break;
|
|
6211
|
-
}
|
|
6212
|
-
case "gyr": {
|
|
6213
|
-
this.propagateGyr(msg.data);
|
|
6214
|
-
break;
|
|
6215
|
-
}
|
|
6216
6224
|
case "midi": {
|
|
6217
6225
|
this.midiMessage(msg.data);
|
|
6218
6226
|
break;
|
|
@@ -6281,10 +6289,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
6281
6289
|
class FaustMonoAudioWorkletProcessor extends FaustAudioWorkletProcessor {
|
|
6282
6290
|
constructor(options) {
|
|
6283
6291
|
super(options);
|
|
6292
|
+
this.handleMessageAux = (e) => {
|
|
6293
|
+
super.handleMessageAux(e);
|
|
6294
|
+
};
|
|
6284
6295
|
const { FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2 } = dependencies;
|
|
6285
6296
|
const { factory, sampleSize } = options.processorOptions;
|
|
6286
6297
|
const instance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
|
|
6287
6298
|
this.fDSPCode = new FaustMonoWebAudioDsp2(instance, sampleRate, sampleSize, 128, factory.soundfiles);
|
|
6299
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
6300
|
+
this.port.start();
|
|
6288
6301
|
this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
|
|
6289
6302
|
this.fDSPCode.start();
|
|
6290
6303
|
}
|
|
@@ -6311,7 +6324,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
6311
6324
|
const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory);
|
|
6312
6325
|
const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
|
|
6313
6326
|
this.fDSPCode = new FaustPolyWebAudioDsp3(instance, sampleRate, sampleSize, 128, soundfiles);
|
|
6314
|
-
this.port.
|
|
6327
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
6328
|
+
this.port.start();
|
|
6315
6329
|
this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
|
|
6316
6330
|
this.fDSPCode.start();
|
|
6317
6331
|
}
|
|
@@ -6357,6 +6371,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
6357
6371
|
FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
|
|
6358
6372
|
FaustWasmInstantiator: FaustWasmInstantiator2,
|
|
6359
6373
|
FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2,
|
|
6374
|
+
FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2,
|
|
6360
6375
|
FFTUtils
|
|
6361
6376
|
} = dependencies;
|
|
6362
6377
|
const {
|
|
@@ -6440,7 +6455,58 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
6440
6455
|
this.fBufferNum = 0;
|
|
6441
6456
|
this.soundfiles = {};
|
|
6442
6457
|
this.windowFunction = null;
|
|
6443
|
-
this.
|
|
6458
|
+
this.handleMessageAux = (e) => {
|
|
6459
|
+
var _a, _b, _c;
|
|
6460
|
+
const msg = e.data;
|
|
6461
|
+
switch (msg.type) {
|
|
6462
|
+
case "midi":
|
|
6463
|
+
this.midiMessage(msg.data);
|
|
6464
|
+
break;
|
|
6465
|
+
case "ctrlChange":
|
|
6466
|
+
this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
|
|
6467
|
+
break;
|
|
6468
|
+
case "pitchWheel":
|
|
6469
|
+
this.pitchWheel(msg.data[0], msg.data[1]);
|
|
6470
|
+
break;
|
|
6471
|
+
case "param":
|
|
6472
|
+
this.setParamValue(msg.data.path, msg.data.value);
|
|
6473
|
+
break;
|
|
6474
|
+
case "setPlotHandler": {
|
|
6475
|
+
if (msg.data) {
|
|
6476
|
+
this.fPlotHandler = (output, index, events) => {
|
|
6477
|
+
if (events)
|
|
6478
|
+
this.fCachedEvents.push(...events);
|
|
6479
|
+
};
|
|
6480
|
+
} else {
|
|
6481
|
+
this.fPlotHandler = null;
|
|
6482
|
+
}
|
|
6483
|
+
(_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
|
|
6484
|
+
break;
|
|
6485
|
+
}
|
|
6486
|
+
case "setupWamEventHandler": {
|
|
6487
|
+
this.setupWamEventHandler();
|
|
6488
|
+
break;
|
|
6489
|
+
}
|
|
6490
|
+
case "start": {
|
|
6491
|
+
(_b = this.fDSPCode) == null ? void 0 : _b.start();
|
|
6492
|
+
break;
|
|
6493
|
+
}
|
|
6494
|
+
case "stop": {
|
|
6495
|
+
(_c = this.fDSPCode) == null ? void 0 : _c.stop();
|
|
6496
|
+
break;
|
|
6497
|
+
}
|
|
6498
|
+
case "destroy": {
|
|
6499
|
+
this.port.close();
|
|
6500
|
+
this.destroy();
|
|
6501
|
+
break;
|
|
6502
|
+
}
|
|
6503
|
+
default:
|
|
6504
|
+
break;
|
|
6505
|
+
}
|
|
6506
|
+
};
|
|
6507
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
6508
|
+
this.port.start();
|
|
6509
|
+
this.communicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
|
|
6444
6510
|
const { parameterDescriptors } = this.constructor;
|
|
6445
6511
|
parameterDescriptors.forEach((pd) => {
|
|
6446
6512
|
this.paramValuesCache[pd.name] = pd.defaultValue || 0;
|
|
@@ -6596,6 +6662,21 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
6596
6662
|
this.paramValuesCache[path] = paramValue;
|
|
6597
6663
|
}
|
|
6598
6664
|
}
|
|
6665
|
+
if (this.communicator.getNewAccDataAvailable()) {
|
|
6666
|
+
const acc = this.communicator.getAcc();
|
|
6667
|
+
if (acc) {
|
|
6668
|
+
this.communicator.setNewAccDataAvailable(false);
|
|
6669
|
+
const { invert, ...data } = acc;
|
|
6670
|
+
this.propagateAcc(data, invert);
|
|
6671
|
+
}
|
|
6672
|
+
}
|
|
6673
|
+
if (this.communicator.getNewGyrDataAvailable()) {
|
|
6674
|
+
const gyr = this.communicator.getGyr();
|
|
6675
|
+
if (gyr) {
|
|
6676
|
+
this.communicator.setNewGyrDataAvailable(false);
|
|
6677
|
+
this.propagateGyr(gyr);
|
|
6678
|
+
}
|
|
6679
|
+
}
|
|
6599
6680
|
if (input == null ? void 0 : input.length) {
|
|
6600
6681
|
let $inputWrite = 0;
|
|
6601
6682
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -6625,55 +6706,6 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
6625
6706
|
}
|
|
6626
6707
|
return true;
|
|
6627
6708
|
}
|
|
6628
|
-
handleMessageAux(e) {
|
|
6629
|
-
var _a, _b, _c;
|
|
6630
|
-
const msg = e.data;
|
|
6631
|
-
switch (msg.type) {
|
|
6632
|
-
case "midi":
|
|
6633
|
-
this.midiMessage(msg.data);
|
|
6634
|
-
break;
|
|
6635
|
-
case "ctrlChange":
|
|
6636
|
-
this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
|
|
6637
|
-
break;
|
|
6638
|
-
case "pitchWheel":
|
|
6639
|
-
this.pitchWheel(msg.data[0], msg.data[1]);
|
|
6640
|
-
break;
|
|
6641
|
-
case "param":
|
|
6642
|
-
this.setParamValue(msg.data.path, msg.data.value);
|
|
6643
|
-
break;
|
|
6644
|
-
case "setPlotHandler": {
|
|
6645
|
-
if (msg.data) {
|
|
6646
|
-
this.fPlotHandler = (output, index, events) => {
|
|
6647
|
-
if (events)
|
|
6648
|
-
this.fCachedEvents.push(...events);
|
|
6649
|
-
};
|
|
6650
|
-
} else {
|
|
6651
|
-
this.fPlotHandler = null;
|
|
6652
|
-
}
|
|
6653
|
-
(_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
|
|
6654
|
-
break;
|
|
6655
|
-
}
|
|
6656
|
-
case "setupWamEventHandler": {
|
|
6657
|
-
this.setupWamEventHandler();
|
|
6658
|
-
break;
|
|
6659
|
-
}
|
|
6660
|
-
case "start": {
|
|
6661
|
-
(_b = this.fDSPCode) == null ? void 0 : _b.start();
|
|
6662
|
-
break;
|
|
6663
|
-
}
|
|
6664
|
-
case "stop": {
|
|
6665
|
-
(_c = this.fDSPCode) == null ? void 0 : _c.stop();
|
|
6666
|
-
break;
|
|
6667
|
-
}
|
|
6668
|
-
case "destroy": {
|
|
6669
|
-
this.port.close();
|
|
6670
|
-
this.destroy();
|
|
6671
|
-
break;
|
|
6672
|
-
}
|
|
6673
|
-
default:
|
|
6674
|
-
break;
|
|
6675
|
-
}
|
|
6676
|
-
}
|
|
6677
6709
|
setParamValue(path, value) {
|
|
6678
6710
|
var _a;
|
|
6679
6711
|
(_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(path, value);
|
|
@@ -6691,6 +6723,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
6691
6723
|
var _a;
|
|
6692
6724
|
(_a = this.fDSPCode) == null ? void 0 : _a.pitchWheel(channel, wheel);
|
|
6693
6725
|
}
|
|
6726
|
+
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
6727
|
+
this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
|
|
6728
|
+
}
|
|
6729
|
+
propagateGyr(event) {
|
|
6730
|
+
this.fDSPCode.propagateGyr(event);
|
|
6731
|
+
}
|
|
6694
6732
|
resetFFT(sizeIn, overlapIn, windowFunctionIn, inputChannels, outputChannels, bufferSize) {
|
|
6695
6733
|
var _a, _b;
|
|
6696
6734
|
const fftSize = ~~ceil(Math.max(2, sizeIn || 1024), 2);
|
|
@@ -8473,6 +8511,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8473
8511
|
this.fComputeHandler = null;
|
|
8474
8512
|
this.fPlotHandler = null;
|
|
8475
8513
|
}
|
|
8514
|
+
startSensors() {
|
|
8515
|
+
this.startSensors();
|
|
8516
|
+
}
|
|
8517
|
+
stopSensors() {
|
|
8518
|
+
this.stopSensors();
|
|
8519
|
+
}
|
|
8476
8520
|
};
|
|
8477
8521
|
var FaustMonoWebAudioDsp = class extends FaustBaseWebAudioDsp {
|
|
8478
8522
|
constructor(instance, sampleRate, sampleSize, bufferSize, soundfiles) {
|
|
@@ -9098,6 +9142,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
9098
9142
|
propagateGyr(event) {
|
|
9099
9143
|
this.fDSPCode.propagateGyr(event);
|
|
9100
9144
|
}
|
|
9145
|
+
startSensors() {
|
|
9146
|
+
}
|
|
9147
|
+
stopSensors() {
|
|
9148
|
+
}
|
|
9101
9149
|
/**
|
|
9102
9150
|
* Render frames in an array.
|
|
9103
9151
|
*
|
|
@@ -9726,6 +9774,130 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
9726
9774
|
};
|
|
9727
9775
|
var SoundfileReader_default = SoundfileReader;
|
|
9728
9776
|
|
|
9777
|
+
// src/FaustAudioWorkletCommunicator.ts
|
|
9778
|
+
var FaustAudioWorkletCommunicator = class {
|
|
9779
|
+
constructor(port) {
|
|
9780
|
+
this.port = port;
|
|
9781
|
+
this.supportSharedArrayBuffer = !!globalThis.SharedArrayBuffer;
|
|
9782
|
+
this.byteLength = 4 * Uint8Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
9783
|
+
}
|
|
9784
|
+
initializeBuffer(ab) {
|
|
9785
|
+
let ptr = 0;
|
|
9786
|
+
this.uin8Invert = new Uint8ClampedArray(ab, ptr, 1);
|
|
9787
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9788
|
+
this.uin8NewAccData = new Uint8ClampedArray(ab, ptr, 1);
|
|
9789
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9790
|
+
this.uin8NewGyrData = new Uint8ClampedArray(ab, ptr, 1);
|
|
9791
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9792
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9793
|
+
;
|
|
9794
|
+
this.f32Acc = new Float32Array(ab, ptr, 3);
|
|
9795
|
+
ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
9796
|
+
this.f32Gyr = new Float32Array(ab, ptr, 3);
|
|
9797
|
+
ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
9798
|
+
}
|
|
9799
|
+
setNewAccDataAvailable(value) {
|
|
9800
|
+
if (!this.uin8NewAccData)
|
|
9801
|
+
return;
|
|
9802
|
+
this.uin8NewAccData[0] = +value;
|
|
9803
|
+
}
|
|
9804
|
+
getNewAccDataAvailable() {
|
|
9805
|
+
var _a;
|
|
9806
|
+
return !!((_a = this.uin8NewAccData) == null ? void 0 : _a[0]);
|
|
9807
|
+
}
|
|
9808
|
+
setNewGyrDataAvailable(value) {
|
|
9809
|
+
if (!this.uin8NewGyrData)
|
|
9810
|
+
return;
|
|
9811
|
+
this.uin8NewGyrData[0] = +value;
|
|
9812
|
+
}
|
|
9813
|
+
getNewGyrDataAvailable() {
|
|
9814
|
+
var _a;
|
|
9815
|
+
return !!((_a = this.uin8NewGyrData) == null ? void 0 : _a[0]);
|
|
9816
|
+
}
|
|
9817
|
+
setAcc({ x, y, z }, invert = false) {
|
|
9818
|
+
if (!this.supportSharedArrayBuffer) {
|
|
9819
|
+
const e = { type: "acc", data: { x, y, z }, invert };
|
|
9820
|
+
this.port.postMessage(e);
|
|
9821
|
+
}
|
|
9822
|
+
if (!this.uin8NewAccData)
|
|
9823
|
+
return;
|
|
9824
|
+
this.uin8Invert[0] = +invert;
|
|
9825
|
+
this.f32Acc[0] = x;
|
|
9826
|
+
this.f32Acc[1] = y;
|
|
9827
|
+
this.f32Acc[2] = z;
|
|
9828
|
+
this.uin8NewAccData[0] = 1;
|
|
9829
|
+
}
|
|
9830
|
+
getAcc() {
|
|
9831
|
+
if (!this.uin8NewAccData)
|
|
9832
|
+
return;
|
|
9833
|
+
const invert = !!this.uin8Invert[0];
|
|
9834
|
+
const [x, y, z] = this.f32Acc;
|
|
9835
|
+
return { x, y, z, invert };
|
|
9836
|
+
}
|
|
9837
|
+
setGyr({ alpha, beta, gamma }) {
|
|
9838
|
+
if (!this.supportSharedArrayBuffer) {
|
|
9839
|
+
const e = { type: "gyr", data: { alpha, beta, gamma } };
|
|
9840
|
+
this.port.postMessage(e);
|
|
9841
|
+
}
|
|
9842
|
+
if (!this.uin8NewGyrData)
|
|
9843
|
+
return;
|
|
9844
|
+
this.f32Gyr[0] = alpha;
|
|
9845
|
+
this.f32Gyr[1] = beta;
|
|
9846
|
+
this.f32Gyr[2] = gamma;
|
|
9847
|
+
this.uin8NewGyrData[0] = 1;
|
|
9848
|
+
}
|
|
9849
|
+
getGyr() {
|
|
9850
|
+
if (!this.uin8NewGyrData)
|
|
9851
|
+
return;
|
|
9852
|
+
const [alpha, beta, gamma] = this.f32Gyr;
|
|
9853
|
+
return { alpha, beta, gamma };
|
|
9854
|
+
}
|
|
9855
|
+
};
|
|
9856
|
+
var FaustAudioWorkletNodeCommunicator = class extends FaustAudioWorkletCommunicator {
|
|
9857
|
+
constructor(port) {
|
|
9858
|
+
super(port);
|
|
9859
|
+
if (this.supportSharedArrayBuffer) {
|
|
9860
|
+
const sab = new SharedArrayBuffer(this.byteLength);
|
|
9861
|
+
this.initializeBuffer(sab);
|
|
9862
|
+
this.port.postMessage({ type: "initSab", sab });
|
|
9863
|
+
} else {
|
|
9864
|
+
const ab = new ArrayBuffer(this.byteLength);
|
|
9865
|
+
this.initializeBuffer(ab);
|
|
9866
|
+
}
|
|
9867
|
+
}
|
|
9868
|
+
};
|
|
9869
|
+
var FaustAudioWorkletProcessorCommunicator = class extends FaustAudioWorkletCommunicator {
|
|
9870
|
+
constructor(port) {
|
|
9871
|
+
super(port);
|
|
9872
|
+
if (this.supportSharedArrayBuffer) {
|
|
9873
|
+
this.port.addEventListener("message", (event) => {
|
|
9874
|
+
const { data } = event;
|
|
9875
|
+
if (data.type === "initSab") {
|
|
9876
|
+
this.initializeBuffer(data.sab);
|
|
9877
|
+
}
|
|
9878
|
+
});
|
|
9879
|
+
} else {
|
|
9880
|
+
const ab = new ArrayBuffer(this.byteLength);
|
|
9881
|
+
this.initializeBuffer(ab);
|
|
9882
|
+
this.port.addEventListener("message", (event) => {
|
|
9883
|
+
const msg = event.data;
|
|
9884
|
+
switch (msg.type) {
|
|
9885
|
+
case "acc": {
|
|
9886
|
+
this.setAcc(msg.data, msg.invert);
|
|
9887
|
+
break;
|
|
9888
|
+
}
|
|
9889
|
+
case "gyr": {
|
|
9890
|
+
this.setGyr(msg.data);
|
|
9891
|
+
break;
|
|
9892
|
+
}
|
|
9893
|
+
default:
|
|
9894
|
+
break;
|
|
9895
|
+
}
|
|
9896
|
+
});
|
|
9897
|
+
}
|
|
9898
|
+
}
|
|
9899
|
+
};
|
|
9900
|
+
|
|
9729
9901
|
// src/FaustAudioWorkletNode.ts
|
|
9730
9902
|
var _hasAccInput, _hasGyrInput;
|
|
9731
9903
|
var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null) {
|
|
@@ -9743,7 +9915,13 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
9743
9915
|
});
|
|
9744
9916
|
__privateAdd(this, _hasAccInput, false);
|
|
9745
9917
|
__privateAdd(this, _hasGyrInput, false);
|
|
9746
|
-
|
|
9918
|
+
this.handleMessageAux = (e) => {
|
|
9919
|
+
if (e.data.type === "param" && this.fOutputHandler) {
|
|
9920
|
+
this.fOutputHandler(e.data.path, e.data.value);
|
|
9921
|
+
} else if (e.data.type === "plot" && this.fPlotHandler) {
|
|
9922
|
+
this.fPlotHandler(e.data.value, e.data.index, e.data.events);
|
|
9923
|
+
}
|
|
9924
|
+
};
|
|
9747
9925
|
// Accelerometer and gyroscope handlers
|
|
9748
9926
|
this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
9749
9927
|
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
@@ -9778,14 +9956,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
9778
9956
|
}
|
|
9779
9957
|
};
|
|
9780
9958
|
FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
|
|
9781
|
-
this.
|
|
9782
|
-
|
|
9783
|
-
|
|
9784
|
-
} else if (e.data.type === "plot" && this.fPlotHandler) {
|
|
9785
|
-
this.fPlotHandler(e.data.value, e.data.index, e.data.events);
|
|
9786
|
-
}
|
|
9787
|
-
};
|
|
9959
|
+
this.fCommunicator = new FaustAudioWorkletNodeCommunicator(this.port);
|
|
9960
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
9961
|
+
this.port.start();
|
|
9788
9962
|
}
|
|
9963
|
+
// Public API
|
|
9789
9964
|
/** Setup accelerometer and gyroscope handlers */
|
|
9790
9965
|
async startSensors() {
|
|
9791
9966
|
if (this.hasAccInput) {
|
|
@@ -9906,8 +10081,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
9906
10081
|
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
9907
10082
|
if (!accelerationIncludingGravity)
|
|
9908
10083
|
return;
|
|
9909
|
-
const
|
|
9910
|
-
this.
|
|
10084
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
10085
|
+
this.fCommunicator.setAcc({ x, y, z }, invert);
|
|
9911
10086
|
}
|
|
9912
10087
|
get hasGyrInput() {
|
|
9913
10088
|
return __privateGet(this, _hasGyrInput);
|
|
@@ -9915,8 +10090,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
9915
10090
|
propagateGyr(event) {
|
|
9916
10091
|
if (!event)
|
|
9917
10092
|
return;
|
|
9918
|
-
const
|
|
9919
|
-
this.
|
|
10093
|
+
const { alpha, beta, gamma } = event;
|
|
10094
|
+
this.fCommunicator.setGyr({ alpha, beta, gamma });
|
|
9920
10095
|
}
|
|
9921
10096
|
setParamValue(path, value) {
|
|
9922
10097
|
const e = { type: "param", data: { path, value } };
|
|
@@ -10059,7 +10234,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
10059
10234
|
this.start();
|
|
10060
10235
|
}
|
|
10061
10236
|
// Public API
|
|
10062
|
-
/**
|
|
10237
|
+
/** Start accelerometer and gyroscope handlers */
|
|
10063
10238
|
async startSensors() {
|
|
10064
10239
|
if (this.hasAccInput) {
|
|
10065
10240
|
if (window.DeviceMotionEvent) {
|
|
@@ -10104,6 +10279,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
10104
10279
|
}
|
|
10105
10280
|
}
|
|
10106
10281
|
}
|
|
10282
|
+
/** Stop accelerometer and gyroscope handlers */
|
|
10107
10283
|
stopSensors() {
|
|
10108
10284
|
if (this.hasAccInput) {
|
|
10109
10285
|
window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
@@ -10277,11 +10453,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
10277
10453
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10278
10454
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10279
10455
|
var FaustSensors = ${FaustSensors.name};
|
|
10456
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
10457
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
10458
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
10459
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
10280
10460
|
// Put them in dependencies
|
|
10281
10461
|
const dependencies = {
|
|
10282
10462
|
FaustBaseWebAudioDsp,
|
|
10283
10463
|
FaustMonoWebAudioDsp,
|
|
10284
|
-
FaustWasmInstantiator
|
|
10464
|
+
FaustWasmInstantiator,
|
|
10465
|
+
FaustAudioWorkletProcessorCommunicator
|
|
10285
10466
|
};
|
|
10286
10467
|
// Generate the actual AudioWorkletProcessor code
|
|
10287
10468
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -10331,12 +10512,17 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
10331
10512
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10332
10513
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10333
10514
|
var FaustSensors = ${FaustSensors.name};
|
|
10515
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
10516
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
10517
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
10518
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
10334
10519
|
var FFTUtils = ${fftUtils.toString()}
|
|
10335
10520
|
// Put them in dependencies
|
|
10336
10521
|
const dependencies = {
|
|
10337
10522
|
FaustBaseWebAudioDsp,
|
|
10338
10523
|
FaustMonoWebAudioDsp,
|
|
10339
10524
|
FaustWasmInstantiator,
|
|
10525
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
10340
10526
|
FFTUtils
|
|
10341
10527
|
};
|
|
10342
10528
|
// Generate the actual AudioWorkletProcessor code
|
|
@@ -10380,6 +10566,7 @@ const dependencies = {
|
|
|
10380
10566
|
FaustBaseWebAudioDsp,
|
|
10381
10567
|
FaustMonoWebAudioDsp,
|
|
10382
10568
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
10569
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
10383
10570
|
FaustPolyWebAudioDsp: void 0,
|
|
10384
10571
|
FaustWebAudioDspVoice: void 0
|
|
10385
10572
|
};
|
|
@@ -10560,11 +10747,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
10560
10747
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10561
10748
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10562
10749
|
var FaustSensors = ${FaustSensors.name};
|
|
10750
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
10751
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
10752
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
10753
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
10563
10754
|
// Put them in dependencies
|
|
10564
10755
|
const dependencies = {
|
|
10565
10756
|
FaustBaseWebAudioDsp,
|
|
10566
10757
|
FaustPolyWebAudioDsp,
|
|
10567
|
-
FaustWasmInstantiator
|
|
10758
|
+
FaustWasmInstantiator,
|
|
10759
|
+
FaustAudioWorkletProcessorCommunicator
|
|
10568
10760
|
};
|
|
10569
10761
|
// Generate the actual AudioWorkletProcessor code
|
|
10570
10762
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -10592,7 +10784,8 @@ const dependencies = {
|
|
|
10592
10784
|
FaustMonoWebAudioDsp: void 0,
|
|
10593
10785
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
10594
10786
|
FaustPolyWebAudioDsp,
|
|
10595
|
-
FaustWebAudioDspVoice
|
|
10787
|
+
FaustWebAudioDspVoice,
|
|
10788
|
+
FaustAudioWorkletProcessorCommunicator
|
|
10596
10789
|
};
|
|
10597
10790
|
const faustData = {
|
|
10598
10791
|
processorName,
|