@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/esm-bundle/index.js
CHANGED
|
@@ -6083,7 +6083,8 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6083
6083
|
const { registerProcessor, AudioWorkletProcessor, sampleRate } = globalThis;
|
|
6084
6084
|
const {
|
|
6085
6085
|
FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
|
|
6086
|
-
FaustWasmInstantiator: FaustWasmInstantiator2
|
|
6086
|
+
FaustWasmInstantiator: FaustWasmInstantiator2,
|
|
6087
|
+
FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2
|
|
6087
6088
|
} = dependencies;
|
|
6088
6089
|
const {
|
|
6089
6090
|
processorName,
|
|
@@ -6108,7 +6109,7 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6108
6109
|
constructor(options) {
|
|
6109
6110
|
super(options);
|
|
6110
6111
|
this.paramValuesCache = {};
|
|
6111
|
-
this.
|
|
6112
|
+
this.fCommunicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
|
|
6112
6113
|
const { parameterDescriptors } = this.constructor;
|
|
6113
6114
|
parameterDescriptors.forEach((pd) => {
|
|
6114
6115
|
this.paramValuesCache[pd.name] = pd.defaultValue || 0;
|
|
@@ -6155,19 +6156,26 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6155
6156
|
this.paramValuesCache[path] = paramValue;
|
|
6156
6157
|
}
|
|
6157
6158
|
}
|
|
6159
|
+
if (this.fCommunicator.getNewAccDataAvailable()) {
|
|
6160
|
+
const acc = this.fCommunicator.getAcc();
|
|
6161
|
+
if (acc) {
|
|
6162
|
+
this.fCommunicator.setNewAccDataAvailable(false);
|
|
6163
|
+
const { invert, ...data } = acc;
|
|
6164
|
+
this.propagateAcc(data, invert);
|
|
6165
|
+
}
|
|
6166
|
+
}
|
|
6167
|
+
if (this.fCommunicator.getNewGyrDataAvailable()) {
|
|
6168
|
+
const gyr = this.fCommunicator.getGyr();
|
|
6169
|
+
if (gyr) {
|
|
6170
|
+
this.fCommunicator.setNewGyrDataAvailable(false);
|
|
6171
|
+
this.propagateGyr(gyr);
|
|
6172
|
+
}
|
|
6173
|
+
}
|
|
6158
6174
|
return this.fDSPCode.compute(inputs[0], outputs[0]);
|
|
6159
6175
|
}
|
|
6160
6176
|
handleMessageAux(e) {
|
|
6161
6177
|
const msg = e.data;
|
|
6162
6178
|
switch (msg.type) {
|
|
6163
|
-
case "acc": {
|
|
6164
|
-
this.propagateAcc(msg.data, msg.invert);
|
|
6165
|
-
break;
|
|
6166
|
-
}
|
|
6167
|
-
case "gyr": {
|
|
6168
|
-
this.propagateGyr(msg.data);
|
|
6169
|
-
break;
|
|
6170
|
-
}
|
|
6171
6179
|
case "midi": {
|
|
6172
6180
|
this.midiMessage(msg.data);
|
|
6173
6181
|
break;
|
|
@@ -6236,10 +6244,15 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6236
6244
|
class FaustMonoAudioWorkletProcessor extends FaustAudioWorkletProcessor {
|
|
6237
6245
|
constructor(options) {
|
|
6238
6246
|
super(options);
|
|
6247
|
+
this.handleMessageAux = (e) => {
|
|
6248
|
+
super.handleMessageAux(e);
|
|
6249
|
+
};
|
|
6239
6250
|
const { FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2 } = dependencies;
|
|
6240
6251
|
const { factory, sampleSize } = options.processorOptions;
|
|
6241
6252
|
const instance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
|
|
6242
6253
|
this.fDSPCode = new FaustMonoWebAudioDsp2(instance, sampleRate, sampleSize, 128, factory.soundfiles);
|
|
6254
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
6255
|
+
this.port.start();
|
|
6243
6256
|
this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
|
|
6244
6257
|
this.fDSPCode.start();
|
|
6245
6258
|
}
|
|
@@ -6266,7 +6279,8 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6266
6279
|
const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory);
|
|
6267
6280
|
const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
|
|
6268
6281
|
this.fDSPCode = new FaustPolyWebAudioDsp3(instance, sampleRate, sampleSize, 128, soundfiles);
|
|
6269
|
-
this.port.
|
|
6282
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
6283
|
+
this.port.start();
|
|
6270
6284
|
this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
|
|
6271
6285
|
this.fDSPCode.start();
|
|
6272
6286
|
}
|
|
@@ -6312,6 +6326,7 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
6312
6326
|
FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
|
|
6313
6327
|
FaustWasmInstantiator: FaustWasmInstantiator2,
|
|
6314
6328
|
FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2,
|
|
6329
|
+
FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2,
|
|
6315
6330
|
FFTUtils
|
|
6316
6331
|
} = dependencies;
|
|
6317
6332
|
const {
|
|
@@ -6395,7 +6410,58 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
6395
6410
|
this.fBufferNum = 0;
|
|
6396
6411
|
this.soundfiles = {};
|
|
6397
6412
|
this.windowFunction = null;
|
|
6398
|
-
this.
|
|
6413
|
+
this.handleMessageAux = (e) => {
|
|
6414
|
+
var _a, _b, _c;
|
|
6415
|
+
const msg = e.data;
|
|
6416
|
+
switch (msg.type) {
|
|
6417
|
+
case "midi":
|
|
6418
|
+
this.midiMessage(msg.data);
|
|
6419
|
+
break;
|
|
6420
|
+
case "ctrlChange":
|
|
6421
|
+
this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
|
|
6422
|
+
break;
|
|
6423
|
+
case "pitchWheel":
|
|
6424
|
+
this.pitchWheel(msg.data[0], msg.data[1]);
|
|
6425
|
+
break;
|
|
6426
|
+
case "param":
|
|
6427
|
+
this.setParamValue(msg.data.path, msg.data.value);
|
|
6428
|
+
break;
|
|
6429
|
+
case "setPlotHandler": {
|
|
6430
|
+
if (msg.data) {
|
|
6431
|
+
this.fPlotHandler = (output, index, events) => {
|
|
6432
|
+
if (events)
|
|
6433
|
+
this.fCachedEvents.push(...events);
|
|
6434
|
+
};
|
|
6435
|
+
} else {
|
|
6436
|
+
this.fPlotHandler = null;
|
|
6437
|
+
}
|
|
6438
|
+
(_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
|
|
6439
|
+
break;
|
|
6440
|
+
}
|
|
6441
|
+
case "setupWamEventHandler": {
|
|
6442
|
+
this.setupWamEventHandler();
|
|
6443
|
+
break;
|
|
6444
|
+
}
|
|
6445
|
+
case "start": {
|
|
6446
|
+
(_b = this.fDSPCode) == null ? void 0 : _b.start();
|
|
6447
|
+
break;
|
|
6448
|
+
}
|
|
6449
|
+
case "stop": {
|
|
6450
|
+
(_c = this.fDSPCode) == null ? void 0 : _c.stop();
|
|
6451
|
+
break;
|
|
6452
|
+
}
|
|
6453
|
+
case "destroy": {
|
|
6454
|
+
this.port.close();
|
|
6455
|
+
this.destroy();
|
|
6456
|
+
break;
|
|
6457
|
+
}
|
|
6458
|
+
default:
|
|
6459
|
+
break;
|
|
6460
|
+
}
|
|
6461
|
+
};
|
|
6462
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
6463
|
+
this.port.start();
|
|
6464
|
+
this.communicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
|
|
6399
6465
|
const { parameterDescriptors } = this.constructor;
|
|
6400
6466
|
parameterDescriptors.forEach((pd) => {
|
|
6401
6467
|
this.paramValuesCache[pd.name] = pd.defaultValue || 0;
|
|
@@ -6551,6 +6617,21 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
6551
6617
|
this.paramValuesCache[path] = paramValue;
|
|
6552
6618
|
}
|
|
6553
6619
|
}
|
|
6620
|
+
if (this.communicator.getNewAccDataAvailable()) {
|
|
6621
|
+
const acc = this.communicator.getAcc();
|
|
6622
|
+
if (acc) {
|
|
6623
|
+
this.communicator.setNewAccDataAvailable(false);
|
|
6624
|
+
const { invert, ...data } = acc;
|
|
6625
|
+
this.propagateAcc(data, invert);
|
|
6626
|
+
}
|
|
6627
|
+
}
|
|
6628
|
+
if (this.communicator.getNewGyrDataAvailable()) {
|
|
6629
|
+
const gyr = this.communicator.getGyr();
|
|
6630
|
+
if (gyr) {
|
|
6631
|
+
this.communicator.setNewGyrDataAvailable(false);
|
|
6632
|
+
this.propagateGyr(gyr);
|
|
6633
|
+
}
|
|
6634
|
+
}
|
|
6554
6635
|
if (input == null ? void 0 : input.length) {
|
|
6555
6636
|
let $inputWrite = 0;
|
|
6556
6637
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -6580,55 +6661,6 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
6580
6661
|
}
|
|
6581
6662
|
return true;
|
|
6582
6663
|
}
|
|
6583
|
-
handleMessageAux(e) {
|
|
6584
|
-
var _a, _b, _c;
|
|
6585
|
-
const msg = e.data;
|
|
6586
|
-
switch (msg.type) {
|
|
6587
|
-
case "midi":
|
|
6588
|
-
this.midiMessage(msg.data);
|
|
6589
|
-
break;
|
|
6590
|
-
case "ctrlChange":
|
|
6591
|
-
this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
|
|
6592
|
-
break;
|
|
6593
|
-
case "pitchWheel":
|
|
6594
|
-
this.pitchWheel(msg.data[0], msg.data[1]);
|
|
6595
|
-
break;
|
|
6596
|
-
case "param":
|
|
6597
|
-
this.setParamValue(msg.data.path, msg.data.value);
|
|
6598
|
-
break;
|
|
6599
|
-
case "setPlotHandler": {
|
|
6600
|
-
if (msg.data) {
|
|
6601
|
-
this.fPlotHandler = (output, index, events) => {
|
|
6602
|
-
if (events)
|
|
6603
|
-
this.fCachedEvents.push(...events);
|
|
6604
|
-
};
|
|
6605
|
-
} else {
|
|
6606
|
-
this.fPlotHandler = null;
|
|
6607
|
-
}
|
|
6608
|
-
(_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
|
|
6609
|
-
break;
|
|
6610
|
-
}
|
|
6611
|
-
case "setupWamEventHandler": {
|
|
6612
|
-
this.setupWamEventHandler();
|
|
6613
|
-
break;
|
|
6614
|
-
}
|
|
6615
|
-
case "start": {
|
|
6616
|
-
(_b = this.fDSPCode) == null ? void 0 : _b.start();
|
|
6617
|
-
break;
|
|
6618
|
-
}
|
|
6619
|
-
case "stop": {
|
|
6620
|
-
(_c = this.fDSPCode) == null ? void 0 : _c.stop();
|
|
6621
|
-
break;
|
|
6622
|
-
}
|
|
6623
|
-
case "destroy": {
|
|
6624
|
-
this.port.close();
|
|
6625
|
-
this.destroy();
|
|
6626
|
-
break;
|
|
6627
|
-
}
|
|
6628
|
-
default:
|
|
6629
|
-
break;
|
|
6630
|
-
}
|
|
6631
|
-
}
|
|
6632
6664
|
setParamValue(path, value) {
|
|
6633
6665
|
var _a;
|
|
6634
6666
|
(_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(path, value);
|
|
@@ -6646,6 +6678,12 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
6646
6678
|
var _a;
|
|
6647
6679
|
(_a = this.fDSPCode) == null ? void 0 : _a.pitchWheel(channel, wheel);
|
|
6648
6680
|
}
|
|
6681
|
+
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
6682
|
+
this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
|
|
6683
|
+
}
|
|
6684
|
+
propagateGyr(event) {
|
|
6685
|
+
this.fDSPCode.propagateGyr(event);
|
|
6686
|
+
}
|
|
6649
6687
|
resetFFT(sizeIn, overlapIn, windowFunctionIn, inputChannels, outputChannels, bufferSize) {
|
|
6650
6688
|
var _a, _b;
|
|
6651
6689
|
const fftSize = ~~ceil(Math.max(2, sizeIn || 1024), 2);
|
|
@@ -8428,6 +8466,12 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
|
|
|
8428
8466
|
this.fComputeHandler = null;
|
|
8429
8467
|
this.fPlotHandler = null;
|
|
8430
8468
|
}
|
|
8469
|
+
startSensors() {
|
|
8470
|
+
this.startSensors();
|
|
8471
|
+
}
|
|
8472
|
+
stopSensors() {
|
|
8473
|
+
this.stopSensors();
|
|
8474
|
+
}
|
|
8431
8475
|
};
|
|
8432
8476
|
var FaustMonoWebAudioDsp = class extends FaustBaseWebAudioDsp {
|
|
8433
8477
|
constructor(instance, sampleRate, sampleSize, bufferSize, soundfiles) {
|
|
@@ -9053,6 +9097,10 @@ var FaustOfflineProcessor = class {
|
|
|
9053
9097
|
propagateGyr(event) {
|
|
9054
9098
|
this.fDSPCode.propagateGyr(event);
|
|
9055
9099
|
}
|
|
9100
|
+
startSensors() {
|
|
9101
|
+
}
|
|
9102
|
+
stopSensors() {
|
|
9103
|
+
}
|
|
9056
9104
|
/**
|
|
9057
9105
|
* Render frames in an array.
|
|
9058
9106
|
*
|
|
@@ -9681,6 +9729,130 @@ var SoundfileReader = class {
|
|
|
9681
9729
|
};
|
|
9682
9730
|
var SoundfileReader_default = SoundfileReader;
|
|
9683
9731
|
|
|
9732
|
+
// src/FaustAudioWorkletCommunicator.ts
|
|
9733
|
+
var FaustAudioWorkletCommunicator = class {
|
|
9734
|
+
constructor(port) {
|
|
9735
|
+
this.port = port;
|
|
9736
|
+
this.supportSharedArrayBuffer = !!globalThis.SharedArrayBuffer;
|
|
9737
|
+
this.byteLength = 4 * Uint8Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
9738
|
+
}
|
|
9739
|
+
initializeBuffer(ab) {
|
|
9740
|
+
let ptr = 0;
|
|
9741
|
+
this.uin8Invert = new Uint8ClampedArray(ab, ptr, 1);
|
|
9742
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9743
|
+
this.uin8NewAccData = new Uint8ClampedArray(ab, ptr, 1);
|
|
9744
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9745
|
+
this.uin8NewGyrData = new Uint8ClampedArray(ab, ptr, 1);
|
|
9746
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9747
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9748
|
+
;
|
|
9749
|
+
this.f32Acc = new Float32Array(ab, ptr, 3);
|
|
9750
|
+
ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
9751
|
+
this.f32Gyr = new Float32Array(ab, ptr, 3);
|
|
9752
|
+
ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
9753
|
+
}
|
|
9754
|
+
setNewAccDataAvailable(value) {
|
|
9755
|
+
if (!this.uin8NewAccData)
|
|
9756
|
+
return;
|
|
9757
|
+
this.uin8NewAccData[0] = +value;
|
|
9758
|
+
}
|
|
9759
|
+
getNewAccDataAvailable() {
|
|
9760
|
+
var _a;
|
|
9761
|
+
return !!((_a = this.uin8NewAccData) == null ? void 0 : _a[0]);
|
|
9762
|
+
}
|
|
9763
|
+
setNewGyrDataAvailable(value) {
|
|
9764
|
+
if (!this.uin8NewGyrData)
|
|
9765
|
+
return;
|
|
9766
|
+
this.uin8NewGyrData[0] = +value;
|
|
9767
|
+
}
|
|
9768
|
+
getNewGyrDataAvailable() {
|
|
9769
|
+
var _a;
|
|
9770
|
+
return !!((_a = this.uin8NewGyrData) == null ? void 0 : _a[0]);
|
|
9771
|
+
}
|
|
9772
|
+
setAcc({ x, y, z }, invert = false) {
|
|
9773
|
+
if (!this.supportSharedArrayBuffer) {
|
|
9774
|
+
const e = { type: "acc", data: { x, y, z }, invert };
|
|
9775
|
+
this.port.postMessage(e);
|
|
9776
|
+
}
|
|
9777
|
+
if (!this.uin8NewAccData)
|
|
9778
|
+
return;
|
|
9779
|
+
this.uin8Invert[0] = +invert;
|
|
9780
|
+
this.f32Acc[0] = x;
|
|
9781
|
+
this.f32Acc[1] = y;
|
|
9782
|
+
this.f32Acc[2] = z;
|
|
9783
|
+
this.uin8NewAccData[0] = 1;
|
|
9784
|
+
}
|
|
9785
|
+
getAcc() {
|
|
9786
|
+
if (!this.uin8NewAccData)
|
|
9787
|
+
return;
|
|
9788
|
+
const invert = !!this.uin8Invert[0];
|
|
9789
|
+
const [x, y, z] = this.f32Acc;
|
|
9790
|
+
return { x, y, z, invert };
|
|
9791
|
+
}
|
|
9792
|
+
setGyr({ alpha, beta, gamma }) {
|
|
9793
|
+
if (!this.supportSharedArrayBuffer) {
|
|
9794
|
+
const e = { type: "gyr", data: { alpha, beta, gamma } };
|
|
9795
|
+
this.port.postMessage(e);
|
|
9796
|
+
}
|
|
9797
|
+
if (!this.uin8NewGyrData)
|
|
9798
|
+
return;
|
|
9799
|
+
this.f32Gyr[0] = alpha;
|
|
9800
|
+
this.f32Gyr[1] = beta;
|
|
9801
|
+
this.f32Gyr[2] = gamma;
|
|
9802
|
+
this.uin8NewGyrData[0] = 1;
|
|
9803
|
+
}
|
|
9804
|
+
getGyr() {
|
|
9805
|
+
if (!this.uin8NewGyrData)
|
|
9806
|
+
return;
|
|
9807
|
+
const [alpha, beta, gamma] = this.f32Gyr;
|
|
9808
|
+
return { alpha, beta, gamma };
|
|
9809
|
+
}
|
|
9810
|
+
};
|
|
9811
|
+
var FaustAudioWorkletNodeCommunicator = class extends FaustAudioWorkletCommunicator {
|
|
9812
|
+
constructor(port) {
|
|
9813
|
+
super(port);
|
|
9814
|
+
if (this.supportSharedArrayBuffer) {
|
|
9815
|
+
const sab = new SharedArrayBuffer(this.byteLength);
|
|
9816
|
+
this.initializeBuffer(sab);
|
|
9817
|
+
this.port.postMessage({ type: "initSab", sab });
|
|
9818
|
+
} else {
|
|
9819
|
+
const ab = new ArrayBuffer(this.byteLength);
|
|
9820
|
+
this.initializeBuffer(ab);
|
|
9821
|
+
}
|
|
9822
|
+
}
|
|
9823
|
+
};
|
|
9824
|
+
var FaustAudioWorkletProcessorCommunicator = class extends FaustAudioWorkletCommunicator {
|
|
9825
|
+
constructor(port) {
|
|
9826
|
+
super(port);
|
|
9827
|
+
if (this.supportSharedArrayBuffer) {
|
|
9828
|
+
this.port.addEventListener("message", (event) => {
|
|
9829
|
+
const { data } = event;
|
|
9830
|
+
if (data.type === "initSab") {
|
|
9831
|
+
this.initializeBuffer(data.sab);
|
|
9832
|
+
}
|
|
9833
|
+
});
|
|
9834
|
+
} else {
|
|
9835
|
+
const ab = new ArrayBuffer(this.byteLength);
|
|
9836
|
+
this.initializeBuffer(ab);
|
|
9837
|
+
this.port.addEventListener("message", (event) => {
|
|
9838
|
+
const msg = event.data;
|
|
9839
|
+
switch (msg.type) {
|
|
9840
|
+
case "acc": {
|
|
9841
|
+
this.setAcc(msg.data, msg.invert);
|
|
9842
|
+
break;
|
|
9843
|
+
}
|
|
9844
|
+
case "gyr": {
|
|
9845
|
+
this.setGyr(msg.data);
|
|
9846
|
+
break;
|
|
9847
|
+
}
|
|
9848
|
+
default:
|
|
9849
|
+
break;
|
|
9850
|
+
}
|
|
9851
|
+
});
|
|
9852
|
+
}
|
|
9853
|
+
}
|
|
9854
|
+
};
|
|
9855
|
+
|
|
9684
9856
|
// src/FaustAudioWorkletNode.ts
|
|
9685
9857
|
var _hasAccInput, _hasGyrInput;
|
|
9686
9858
|
var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null) {
|
|
@@ -9698,7 +9870,13 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9698
9870
|
});
|
|
9699
9871
|
__privateAdd(this, _hasAccInput, false);
|
|
9700
9872
|
__privateAdd(this, _hasGyrInput, false);
|
|
9701
|
-
|
|
9873
|
+
this.handleMessageAux = (e) => {
|
|
9874
|
+
if (e.data.type === "param" && this.fOutputHandler) {
|
|
9875
|
+
this.fOutputHandler(e.data.path, e.data.value);
|
|
9876
|
+
} else if (e.data.type === "plot" && this.fPlotHandler) {
|
|
9877
|
+
this.fPlotHandler(e.data.value, e.data.index, e.data.events);
|
|
9878
|
+
}
|
|
9879
|
+
};
|
|
9702
9880
|
// Accelerometer and gyroscope handlers
|
|
9703
9881
|
this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
9704
9882
|
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
@@ -9733,14 +9911,11 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9733
9911
|
}
|
|
9734
9912
|
};
|
|
9735
9913
|
FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
|
|
9736
|
-
this.
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
} else if (e.data.type === "plot" && this.fPlotHandler) {
|
|
9740
|
-
this.fPlotHandler(e.data.value, e.data.index, e.data.events);
|
|
9741
|
-
}
|
|
9742
|
-
};
|
|
9914
|
+
this.fCommunicator = new FaustAudioWorkletNodeCommunicator(this.port);
|
|
9915
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
9916
|
+
this.port.start();
|
|
9743
9917
|
}
|
|
9918
|
+
// Public API
|
|
9744
9919
|
/** Setup accelerometer and gyroscope handlers */
|
|
9745
9920
|
async startSensors() {
|
|
9746
9921
|
if (this.hasAccInput) {
|
|
@@ -9861,8 +10036,8 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9861
10036
|
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
9862
10037
|
if (!accelerationIncludingGravity)
|
|
9863
10038
|
return;
|
|
9864
|
-
const
|
|
9865
|
-
this.
|
|
10039
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
10040
|
+
this.fCommunicator.setAcc({ x, y, z }, invert);
|
|
9866
10041
|
}
|
|
9867
10042
|
get hasGyrInput() {
|
|
9868
10043
|
return __privateGet(this, _hasGyrInput);
|
|
@@ -9870,8 +10045,8 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9870
10045
|
propagateGyr(event) {
|
|
9871
10046
|
if (!event)
|
|
9872
10047
|
return;
|
|
9873
|
-
const
|
|
9874
|
-
this.
|
|
10048
|
+
const { alpha, beta, gamma } = event;
|
|
10049
|
+
this.fCommunicator.setGyr({ alpha, beta, gamma });
|
|
9875
10050
|
}
|
|
9876
10051
|
setParamValue(path, value) {
|
|
9877
10052
|
const e = { type: "param", data: { path, value } };
|
|
@@ -10014,7 +10189,7 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
|
|
|
10014
10189
|
this.start();
|
|
10015
10190
|
}
|
|
10016
10191
|
// Public API
|
|
10017
|
-
/**
|
|
10192
|
+
/** Start accelerometer and gyroscope handlers */
|
|
10018
10193
|
async startSensors() {
|
|
10019
10194
|
if (this.hasAccInput) {
|
|
10020
10195
|
if (window.DeviceMotionEvent) {
|
|
@@ -10059,6 +10234,7 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
|
|
|
10059
10234
|
}
|
|
10060
10235
|
}
|
|
10061
10236
|
}
|
|
10237
|
+
/** Stop accelerometer and gyroscope handlers */
|
|
10062
10238
|
stopSensors() {
|
|
10063
10239
|
if (this.hasAccInput) {
|
|
10064
10240
|
window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
@@ -10232,11 +10408,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
10232
10408
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10233
10409
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10234
10410
|
var FaustSensors = ${FaustSensors.name};
|
|
10411
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
10412
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
10413
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
10414
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
10235
10415
|
// Put them in dependencies
|
|
10236
10416
|
const dependencies = {
|
|
10237
10417
|
FaustBaseWebAudioDsp,
|
|
10238
10418
|
FaustMonoWebAudioDsp,
|
|
10239
|
-
FaustWasmInstantiator
|
|
10419
|
+
FaustWasmInstantiator,
|
|
10420
|
+
FaustAudioWorkletProcessorCommunicator
|
|
10240
10421
|
};
|
|
10241
10422
|
// Generate the actual AudioWorkletProcessor code
|
|
10242
10423
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -10286,12 +10467,17 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
10286
10467
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10287
10468
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10288
10469
|
var FaustSensors = ${FaustSensors.name};
|
|
10470
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
10471
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
10472
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
10473
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
10289
10474
|
var FFTUtils = ${fftUtils.toString()}
|
|
10290
10475
|
// Put them in dependencies
|
|
10291
10476
|
const dependencies = {
|
|
10292
10477
|
FaustBaseWebAudioDsp,
|
|
10293
10478
|
FaustMonoWebAudioDsp,
|
|
10294
10479
|
FaustWasmInstantiator,
|
|
10480
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
10295
10481
|
FFTUtils
|
|
10296
10482
|
};
|
|
10297
10483
|
// Generate the actual AudioWorkletProcessor code
|
|
@@ -10335,6 +10521,7 @@ const dependencies = {
|
|
|
10335
10521
|
FaustBaseWebAudioDsp,
|
|
10336
10522
|
FaustMonoWebAudioDsp,
|
|
10337
10523
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
10524
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
10338
10525
|
FaustPolyWebAudioDsp: void 0,
|
|
10339
10526
|
FaustWebAudioDspVoice: void 0
|
|
10340
10527
|
};
|
|
@@ -10515,11 +10702,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
10515
10702
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10516
10703
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10517
10704
|
var FaustSensors = ${FaustSensors.name};
|
|
10705
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
10706
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
10707
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
10708
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
10518
10709
|
// Put them in dependencies
|
|
10519
10710
|
const dependencies = {
|
|
10520
10711
|
FaustBaseWebAudioDsp,
|
|
10521
10712
|
FaustPolyWebAudioDsp,
|
|
10522
|
-
FaustWasmInstantiator
|
|
10713
|
+
FaustWasmInstantiator,
|
|
10714
|
+
FaustAudioWorkletProcessorCommunicator
|
|
10523
10715
|
};
|
|
10524
10716
|
// Generate the actual AudioWorkletProcessor code
|
|
10525
10717
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -10547,7 +10739,8 @@ const dependencies = {
|
|
|
10547
10739
|
FaustMonoWebAudioDsp: void 0,
|
|
10548
10740
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
10549
10741
|
FaustPolyWebAudioDsp,
|
|
10550
|
-
FaustWebAudioDspVoice
|
|
10742
|
+
FaustWebAudioDspVoice,
|
|
10743
|
+
FaustAudioWorkletProcessorCommunicator
|
|
10551
10744
|
};
|
|
10552
10745
|
const faustData = {
|
|
10553
10746
|
processorName,
|