@grame/faustwasm 0.15.7 → 0.16.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grame/faustwasm",
3
- "version": "0.15.7",
3
+ "version": "0.16.1",
4
4
  "description": "WebAssembly version of Faust Compiler",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -314,7 +314,10 @@ export class FaustAudioWorkletNode<
314
314
 
315
315
  setParamValue(path: string, value: number) {
316
316
  const resolved = this.fParamAliases[path] || path;
317
- this.port.postMessage({ type: 'param', data: { path: resolved, value } });
317
+ this.port.postMessage({
318
+ type: 'param',
319
+ data: { path: resolved, value }
320
+ });
318
321
  // Set value on AudioParam (but this is not used on Processor side for now)
319
322
  const param = this.parameters.get(resolved);
320
323
  if (param) param.setValueAtTime(value, this.context.currentTime);
@@ -342,6 +345,26 @@ export class FaustAudioWorkletNode<
342
345
  return this.fDescriptor;
343
346
  }
344
347
 
348
+ init() {
349
+ this.port.postMessage({ type: 'init' });
350
+ }
351
+
352
+ instanceInit() {
353
+ this.port.postMessage({ type: 'instanceInit' });
354
+ }
355
+
356
+ instanceClear() {
357
+ this.port.postMessage({ type: 'instanceClear' });
358
+ }
359
+
360
+ instanceConstants() {
361
+ this.port.postMessage({ type: 'instanceConstants' });
362
+ }
363
+
364
+ instanceResetUserInterface() {
365
+ this.port.postMessage({ type: 'instanceResetUserInterface' });
366
+ }
367
+
345
368
  start() {
346
369
  this.port.postMessage({ type: 'start' });
347
370
  }
@@ -44,18 +44,17 @@ export interface FaustAudioWorkletProcessorDependencies<
44
44
  FaustWasmInstantiator: typeof FaustWasmInstantiator;
45
45
  FaustAudioWorkletProcessorCommunicator: typeof FaustAudioWorkletProcessorCommunicator;
46
46
  }
47
- export interface FaustAudioWorkletNodeOptions<Poly extends boolean = false>
48
- extends AudioWorkletNodeOptions {
47
+ export interface FaustAudioWorkletNodeOptions<
48
+ Poly extends boolean = false
49
+ > extends AudioWorkletNodeOptions {
49
50
  processorOptions: Poly extends true
50
51
  ? FaustPolyAudioWorkletProcessorOptions
51
52
  : FaustMonoAudioWorkletProcessorOptions;
52
53
  }
53
- export interface FaustMonoAudioWorkletNodeOptions
54
- extends AudioWorkletNodeOptions {
54
+ export interface FaustMonoAudioWorkletNodeOptions extends AudioWorkletNodeOptions {
55
55
  processorOptions: FaustMonoAudioWorkletProcessorOptions;
56
56
  }
57
- export interface FaustPolyAudioWorkletNodeOptions
58
- extends AudioWorkletNodeOptions {
57
+ export interface FaustPolyAudioWorkletNodeOptions extends AudioWorkletNodeOptions {
59
58
  processorOptions: FaustPolyAudioWorkletProcessorOptions;
60
59
  }
61
60
  export interface FaustAudioWorkletProcessorOptions {
@@ -65,12 +64,10 @@ export interface FaustAudioWorkletProcessorOptions {
65
64
  moduleId?: string;
66
65
  instanceId?: string;
67
66
  }
68
- export interface FaustMonoAudioWorkletProcessorOptions
69
- extends FaustAudioWorkletProcessorOptions {
67
+ export interface FaustMonoAudioWorkletProcessorOptions extends FaustAudioWorkletProcessorOptions {
70
68
  factory: LooseFaustDspFactory;
71
69
  }
72
- export interface FaustPolyAudioWorkletProcessorOptions
73
- extends FaustAudioWorkletProcessorOptions {
70
+ export interface FaustPolyAudioWorkletProcessorOptions extends FaustAudioWorkletProcessorOptions {
74
71
  voiceFactory: LooseFaustDspFactory;
75
72
  mixerModule: WebAssembly.Module;
76
73
  voices: number;
@@ -283,6 +280,26 @@ const getFaustAudioWorkletProcessor = <Poly extends boolean = false>(
283
280
  this.setupWamEventHandler();
284
281
  break;
285
282
  }
283
+ case 'init': {
284
+ this.fDSPCode.init();
285
+ break;
286
+ }
287
+ case 'instanceInit': {
288
+ this.fDSPCode.instanceInit();
289
+ break;
290
+ }
291
+ case 'instanceClear': {
292
+ this.fDSPCode.instanceClear();
293
+ break;
294
+ }
295
+ case 'instanceConstants': {
296
+ this.fDSPCode.instanceConstants();
297
+ break;
298
+ }
299
+ case 'instanceResetUserInterface': {
300
+ this.fDSPCode.instanceResetUserInterface();
301
+ break;
302
+ }
286
303
  case 'start': {
287
304
  this.fDSPCode.start();
288
305
  break;
@@ -367,7 +367,7 @@ export class FaustMonoDspGenerator implements IFaustMonoDspGenerator {
367
367
  monoDsp.getNumOutputs()
368
368
  ) as FaustMonoScriptProcessorNode;
369
369
  Object.setPrototypeOf(sp, FaustMonoScriptProcessorNode.prototype);
370
- sp.init(monoDsp);
370
+ sp.setupNode(monoDsp);
371
371
  return sp as SP extends true
372
372
  ? FaustMonoScriptProcessorNode
373
373
  : FaustMonoAudioWorkletNode;
@@ -856,7 +856,7 @@ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
856
856
  polyDsp.getNumOutputs()
857
857
  ) as FaustPolyScriptProcessorNode;
858
858
  Object.setPrototypeOf(sp, FaustPolyScriptProcessorNode.prototype);
859
- sp.init(polyDsp);
859
+ sp.setupNode(polyDsp);
860
860
  return sp as SP extends true
861
861
  ? FaustPolyScriptProcessorNode
862
862
  : FaustPolyAudioWorkletNode;
@@ -25,11 +25,9 @@ export interface IFaustOfflineProcessor extends IFaustBaseWebAudioDsp {
25
25
  }
26
26
 
27
27
  export interface IFaustMonoOfflineProcessor
28
- extends IFaustOfflineProcessor,
29
- IFaustMonoWebAudioDsp {}
28
+ extends IFaustOfflineProcessor, IFaustMonoWebAudioDsp {}
30
29
  export interface IFaustPolyOfflineProcessor
31
- extends IFaustOfflineProcessor,
32
- IFaustPolyWebAudioDsp {}
30
+ extends IFaustOfflineProcessor, IFaustPolyWebAudioDsp {}
33
31
 
34
32
  export class FaustOfflineProcessor<Poly extends boolean = false> {
35
33
  protected fDSPCode!: Poly extends true
@@ -190,6 +188,26 @@ export class FaustOfflineProcessor<Poly extends boolean = false> {
190
188
  return this.fDSPCode.getUI();
191
189
  }
192
190
 
191
+ init() {
192
+ this.fDSPCode.init();
193
+ }
194
+
195
+ instanceInit() {
196
+ this.fDSPCode.instanceInit();
197
+ }
198
+
199
+ instanceClear() {
200
+ this.fDSPCode.instanceClear();
201
+ }
202
+
203
+ instanceConstants() {
204
+ this.fDSPCode.instanceConstants();
205
+ }
206
+
207
+ instanceResetUserInterface() {
208
+ this.fDSPCode.instanceResetUserInterface();
209
+ }
210
+
193
211
  start() {
194
212
  this.fDSPCode.start();
195
213
  }
@@ -26,7 +26,7 @@ export class FaustScriptProcessorNode<
26
26
  protected handleDeviceMotion = undefined as any;
27
27
  protected handleDeviceOrientation = undefined as any;
28
28
 
29
- init(
29
+ setupNode(
30
30
  instance: Poly extends true
31
31
  ? FaustPolyWebAudioDsp
32
32
  : FaustMonoWebAudioDsp
@@ -71,6 +71,26 @@ export class FaustScriptProcessorNode<
71
71
  this.start();
72
72
  }
73
73
 
74
+ init() {
75
+ this.fDSPCode.init();
76
+ }
77
+
78
+ instanceInit() {
79
+ this.fDSPCode.instanceInit();
80
+ }
81
+
82
+ instanceClear() {
83
+ this.fDSPCode.instanceClear();
84
+ }
85
+
86
+ instanceConstants() {
87
+ this.fDSPCode.instanceConstants();
88
+ }
89
+
90
+ instanceResetUserInterface() {
91
+ this.fDSPCode.instanceResetUserInterface();
92
+ }
93
+
74
94
  // Public API
75
95
 
76
96
  /** Start accelerometer and gyroscope handlers */
@@ -678,6 +678,31 @@ export interface IFaustBaseWebAudioDsp {
678
678
  event: Pick<DeviceOrientationEvent, 'alpha' | 'beta' | 'gamma'>
679
679
  ): void;
680
680
 
681
+ /**
682
+ * Reinitialize the DSP using its configured sample rate.
683
+ */
684
+ init(): void;
685
+
686
+ /**
687
+ * Reinitialize the DSP instance state using its configured sample rate.
688
+ */
689
+ instanceInit(): void;
690
+
691
+ /**
692
+ * Clear the DSP instance state.
693
+ */
694
+ instanceClear(): void;
695
+
696
+ /**
697
+ * Reinitialize the DSP instance constants using its configured sample rate.
698
+ */
699
+ instanceConstants(): void;
700
+
701
+ /**
702
+ * Reset DSP user interface parameters to their default values.
703
+ */
704
+ instanceResetUserInterface(): void;
705
+
681
706
  /**
682
707
  * Start the DSP audio processing.
683
708
  */
@@ -696,8 +721,7 @@ export interface IFaustBaseWebAudioDsp {
696
721
 
697
722
  export type IFaustMonoWebAudioDsp = IFaustBaseWebAudioDsp;
698
723
  export interface IFaustMonoWebAudioNode
699
- extends IFaustMonoWebAudioDsp,
700
- AudioNode {}
724
+ extends IFaustMonoWebAudioDsp, AudioNode {}
701
725
 
702
726
  export interface IFaustPolyWebAudioDsp extends IFaustBaseWebAudioDsp {
703
727
  /**
@@ -726,8 +750,7 @@ export interface IFaustPolyWebAudioDsp extends IFaustBaseWebAudioDsp {
726
750
  allNotesOff(hard: boolean): void;
727
751
  }
728
752
  export interface IFaustPolyWebAudioNode
729
- extends IFaustPolyWebAudioDsp,
730
- AudioNode {}
753
+ extends IFaustPolyWebAudioDsp, AudioNode {}
731
754
 
732
755
  export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
733
756
  protected fOutputHandler: OutputParamHandler | null = null;
@@ -1576,6 +1599,16 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
1576
1599
  this.stopSensors();
1577
1600
  }
1578
1601
 
1602
+ init() {}
1603
+
1604
+ instanceInit() {}
1605
+
1606
+ instanceClear() {}
1607
+
1608
+ instanceConstants() {}
1609
+
1610
+ instanceResetUserInterface() {}
1611
+
1579
1612
  start() {
1580
1613
  this.fProcessing = true;
1581
1614
  }
@@ -1599,6 +1632,7 @@ export class FaustMonoWebAudioDsp
1599
1632
  {
1600
1633
  private fInstance: FaustMonoDspInstance;
1601
1634
  private fDSP!: number;
1635
+ private fSampleRate: number;
1602
1636
 
1603
1637
  constructor(
1604
1638
  instance: FaustMonoDspInstance,
@@ -1609,6 +1643,7 @@ export class FaustMonoWebAudioDsp
1609
1643
  ) {
1610
1644
  super(sampleSize, bufferSize, soundfiles);
1611
1645
  this.fInstance = instance;
1646
+ this.fSampleRate = sampleRate;
1612
1647
 
1613
1648
  console.log(`sampleSize: ${sampleSize} bufferSize: ${bufferSize}`);
1614
1649
 
@@ -1637,6 +1672,26 @@ export class FaustMonoWebAudioDsp
1637
1672
  }
1638
1673
  }
1639
1674
 
1675
+ init() {
1676
+ this.fInstance.api.init(this.fDSP, this.fSampleRate);
1677
+ }
1678
+
1679
+ instanceInit() {
1680
+ this.fInstance.api.instanceInit(this.fDSP, this.fSampleRate);
1681
+ }
1682
+
1683
+ instanceClear() {
1684
+ this.fInstance.api.instanceClear(this.fDSP);
1685
+ }
1686
+
1687
+ instanceConstants() {
1688
+ this.fInstance.api.instanceConstants(this.fDSP, this.fSampleRate);
1689
+ }
1690
+
1691
+ instanceResetUserInterface() {
1692
+ this.fInstance.api.instanceResetUserInterface(this.fDSP);
1693
+ }
1694
+
1640
1695
  private initMemory(): number {
1641
1696
  // Start of DSP memory: Mono DSP is placed first with index 0
1642
1697
  this.fDSP = 0;
@@ -1888,6 +1943,7 @@ export class FaustWebAudioDspVoice {
1888
1943
  private fVelLabel: number[] = [];
1889
1944
  private fDSP: number; // Voice DSP location in wasm memory
1890
1945
  private fAPI: IFaustDspInstance; // Voice DSP code
1946
+ private fSampleRate: number;
1891
1947
  // Accessed by PolyDSPImp class
1892
1948
  fCurNote = FaustWebAudioDspVoice.kFreeVoice;
1893
1949
  fNextNote = -1;
@@ -1904,7 +1960,8 @@ export class FaustWebAudioDspVoice {
1904
1960
  ) {
1905
1961
  this.fDSP = $dsp;
1906
1962
  this.fAPI = api;
1907
- this.fAPI.init(this.fDSP, sampleRate);
1963
+ this.fSampleRate = sampleRate;
1964
+ this.init(sampleRate);
1908
1965
  this.extractPaths(inputItems, pathTable);
1909
1966
  }
1910
1967
 
@@ -1916,6 +1973,26 @@ export class FaustWebAudioDspVoice {
1916
1973
  return velocity / 127.0;
1917
1974
  }
1918
1975
 
1976
+ init(sampleRate: number) {
1977
+ this.fAPI.init(this.fDSP, sampleRate);
1978
+ }
1979
+
1980
+ instanceInit() {
1981
+ this.fAPI.instanceInit(this.fDSP, this.fSampleRate);
1982
+ }
1983
+
1984
+ instanceClear() {
1985
+ this.fAPI.instanceClear(this.fDSP);
1986
+ }
1987
+
1988
+ instanceConstants() {
1989
+ this.fAPI.instanceConstants(this.fDSP, this.fSampleRate);
1990
+ }
1991
+
1992
+ instanceResetUserInterface() {
1993
+ this.fAPI.instanceResetUserInterface(this.fDSP);
1994
+ }
1995
+
1919
1996
  private extractPaths(
1920
1997
  inputItems: string[],
1921
1998
  pathTable: { [address: string]: number }
@@ -2025,6 +2102,7 @@ export class FaustPolyWebAudioDsp
2025
2102
  private fAudioMixing!: number;
2026
2103
  private fAudioMixingHalf!: number;
2027
2104
  private fVoiceTable: FaustWebAudioDspVoice[];
2105
+ private fSampleRate: number;
2028
2106
 
2029
2107
  constructor(
2030
2108
  instance: FaustPolyDspInstance,
@@ -2035,6 +2113,7 @@ export class FaustPolyWebAudioDsp
2035
2113
  ) {
2036
2114
  super(sampleSize, bufferSize, soundfiles);
2037
2115
  this.fInstance = instance;
2116
+ this.fSampleRate = sampleRate;
2038
2117
 
2039
2118
  console.log(`sampleSize: ${sampleSize} bufferSize: ${bufferSize}`);
2040
2119
 
@@ -2087,6 +2166,42 @@ export class FaustPolyWebAudioDsp
2087
2166
  }
2088
2167
  }
2089
2168
 
2169
+ init() {
2170
+ this.fVoiceTable.forEach((voice) => voice.init(this.fSampleRate));
2171
+ if (this.fInstance.effectAPI)
2172
+ this.fInstance.effectAPI.init(this.fEffect, this.fSampleRate);
2173
+ }
2174
+
2175
+ instanceInit() {
2176
+ this.fVoiceTable.forEach((voice) => voice.instanceInit());
2177
+ if (this.fInstance.effectAPI)
2178
+ this.fInstance.effectAPI.instanceInit(
2179
+ this.fEffect,
2180
+ this.fSampleRate
2181
+ );
2182
+ }
2183
+
2184
+ instanceClear() {
2185
+ this.fVoiceTable.forEach((voice) => voice.instanceClear());
2186
+ if (this.fInstance.effectAPI)
2187
+ this.fInstance.effectAPI.instanceClear(this.fEffect);
2188
+ }
2189
+
2190
+ instanceConstants() {
2191
+ this.fVoiceTable.forEach((voice) => voice.instanceConstants());
2192
+ if (this.fInstance.effectAPI)
2193
+ this.fInstance.effectAPI.instanceConstants(
2194
+ this.fEffect,
2195
+ this.fSampleRate
2196
+ );
2197
+ }
2198
+
2199
+ instanceResetUserInterface() {
2200
+ this.fVoiceTable.forEach((voice) => voice.instanceResetUserInterface());
2201
+ if (this.fInstance.effectAPI)
2202
+ this.fInstance.effectAPI.instanceResetUserInterface(this.fEffect);
2203
+ }
2204
+
2090
2205
  private initMemory() {
2091
2206
  // Effet start at the end of all DSP voices
2092
2207
  this.fEffect = this.fJSONDsp.size * this.fInstance.voices;
@@ -729,6 +729,26 @@ export interface IFaustBaseWebAudioDsp {
729
729
  * event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">
730
730
  */
731
731
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
732
+ /**
733
+ * Reinitialize the DSP using its configured sample rate.
734
+ */
735
+ init(): void;
736
+ /**
737
+ * Reinitialize the DSP instance state using its configured sample rate.
738
+ */
739
+ instanceInit(): void;
740
+ /**
741
+ * Clear the DSP instance state.
742
+ */
743
+ instanceClear(): void;
744
+ /**
745
+ * Reinitialize the DSP instance constants using its configured sample rate.
746
+ */
747
+ instanceConstants(): void;
748
+ /**
749
+ * Reset DSP user interface parameters to their default values.
750
+ */
751
+ instanceResetUserInterface(): void;
732
752
  /**
733
753
  * Start the DSP audio processing.
734
754
  */
@@ -903,6 +923,11 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
903
923
  hasSoundfiles(): boolean;
904
924
  startSensors(): void;
905
925
  stopSensors(): void;
926
+ init(): void;
927
+ instanceInit(): void;
928
+ instanceClear(): void;
929
+ instanceConstants(): void;
930
+ instanceResetUserInterface(): void;
906
931
  start(): void;
907
932
  stop(): void;
908
933
  destroy(): void;
@@ -910,7 +935,13 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
910
935
  export declare class FaustMonoWebAudioDsp extends FaustBaseWebAudioDsp implements IFaustMonoWebAudioDsp {
911
936
  private fInstance;
912
937
  private fDSP;
938
+ private fSampleRate;
913
939
  constructor(instance: FaustMonoDspInstance, sampleRate: number, sampleSize: number, bufferSize: number, soundfiles: LooseFaustDspFactory["soundfiles"]);
940
+ init(): void;
941
+ instanceInit(): void;
942
+ instanceClear(): void;
943
+ instanceConstants(): void;
944
+ instanceResetUserInterface(): void;
914
945
  private initMemory;
915
946
  toString(): string;
916
947
  compute(input: Float32Array[] | ((input: Float32Array[] | Float64Array[]) => any), output: Float32Array[] | ((output: Float32Array[] | Float64Array[]) => any)): boolean;
@@ -938,6 +969,7 @@ export declare class FaustWebAudioDspVoice {
938
969
  private fVelLabel;
939
970
  private fDSP;
940
971
  private fAPI;
972
+ private fSampleRate;
941
973
  fCurNote: number;
942
974
  fNextNote: number;
943
975
  fNextVel: number;
@@ -948,6 +980,11 @@ export declare class FaustWebAudioDspVoice {
948
980
  }, sampleRate: number);
949
981
  static midiToFreq(note: number): number;
950
982
  static normalizeVelocity(velocity: number): number;
983
+ init(sampleRate: number): void;
984
+ instanceInit(): void;
985
+ instanceClear(): void;
986
+ instanceConstants(): void;
987
+ instanceResetUserInterface(): void;
951
988
  private extractPaths;
952
989
  keyOn(pitch: number, velocity: number, legato?: boolean): void;
953
990
  keyOff(hard?: boolean): void;
@@ -963,7 +1000,13 @@ export declare class FaustPolyWebAudioDsp extends FaustBaseWebAudioDsp implement
963
1000
  private fAudioMixing;
964
1001
  private fAudioMixingHalf;
965
1002
  private fVoiceTable;
1003
+ private fSampleRate;
966
1004
  constructor(instance: FaustPolyDspInstance, sampleRate: number, sampleSize: number, bufferSize: number, soundfiles: LooseFaustDspFactory["soundfiles"]);
1005
+ init(): void;
1006
+ instanceInit(): void;
1007
+ instanceClear(): void;
1008
+ instanceConstants(): void;
1009
+ instanceResetUserInterface(): void;
967
1010
  private initMemory;
968
1011
  toString(): string;
969
1012
  private allocVoice;
@@ -1258,6 +1301,11 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
1258
1301
  getJSON(): string;
1259
1302
  getDescriptors(): FaustUIInputItem[];
1260
1303
  getUI(): FaustUIDescriptor;
1304
+ init(): void;
1305
+ instanceInit(): void;
1306
+ instanceClear(): void;
1307
+ instanceConstants(): void;
1308
+ instanceResetUserInterface(): void;
1261
1309
  start(): void;
1262
1310
  stop(): void;
1263
1311
  destroy(): void;
@@ -1463,6 +1511,11 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1463
1511
  getJSON(): string;
1464
1512
  getUI(): FaustUIDescriptor;
1465
1513
  getDescriptors(): FaustUIInputItem[];
1514
+ init(): void;
1515
+ instanceInit(): void;
1516
+ instanceClear(): void;
1517
+ instanceConstants(): void;
1518
+ instanceResetUserInterface(): void;
1466
1519
  start(): void;
1467
1520
  stop(): void;
1468
1521
  destroy(): void;
@@ -1501,7 +1554,12 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1501
1554
  protected fOutputs: Float32Array[];
1502
1555
  protected handleDeviceMotion: any;
1503
1556
  protected handleDeviceOrientation: any;
1504
- init(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp): void;
1557
+ setupNode(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp): void;
1558
+ init(): void;
1559
+ instanceInit(): void;
1560
+ instanceClear(): void;
1561
+ instanceConstants(): void;
1562
+ instanceResetUserInterface(): void;
1505
1563
  /** Start accelerometer and gyroscope handlers */
1506
1564
  startSensors(): Promise<void>;
1507
1565
  /** Stop accelerometer and gyroscope handlers */