@grame/faustwasm 0.0.27 → 0.0.29

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 CHANGED
@@ -1,6 +1,8 @@
1
1
  # FaustWasm
2
2
 
3
- The Faust Web Audio library provides a high level Javascript API over the [Faust](https://faust.grame.fr) compiler. The interface is designed to be used with [TypeScript](https://www.typescriptlang.org/), but describes and documents the API for pure Javascript as well. The WebAssembly version of [Faust Compiler](https://github.com/grame-cncm/faust) is for [Node.js](https://nodejs.org) and web browsers, built with [Emscripten](https://emscripten.org/) 3.1.31.
3
+ The FaustWasm library presents a convenient, high-level API that wraps around [Faust](https://faust.grame.fr) compiler. This library's interface is primarily designed for [TypeScript](https://www.typescriptlang.org/) usage, although it also provides API descriptions and documentation for pure JavaScript. The WebAssembly version of the Faust Compiler, compatible with both [Node.js](https://nodejs.org) and web browsers, has been compiled using [Emscripten](https://emscripten.org/) 3.1.31.
4
+
5
+ The library offers functionality for compiling Faust DSP code into WebAssembly, enabling its utilization as WebAudio nodes within a standard WebAudio node graph. Moreover, it supports offline rendering scenarios. Furthermore, supplementary tools can be employed for generating SVGs from Faust DSP programs.
4
6
 
5
7
  ## Usage
6
8
 
@@ -72,12 +74,12 @@ node scripts/faust2sndfile.js test/rev.dsp test/out/p-dj-rev.wav -c 192000 -sr 4
72
74
  ### Use the JavaScript Module
73
75
 
74
76
  ```bash
75
- npm i -D @shren/faustwasm
77
+ npm i -D @grame/faustwasm
76
78
  ```
77
79
 
78
80
  In JavaScript:
79
81
  ```JavaScript
80
- const FaustWasm = require("@shren/faustwasm");
82
+ const FaustWasm = require("@grame/faustwasm");
81
83
  const path = require("path");
82
84
  const fs = require("fs");
83
85
 
@@ -91,7 +93,7 @@ const {
91
93
  } = FaustWasm;
92
94
 
93
95
  (async () => {
94
- const faustModulePath = path.join(__dirname, "../node_modules/@shren/faustwasm/ libfaust-wasm/libfaust-wasm.js");
96
+ const faustModulePath = path.join(__dirname, "../node_modules/@grame/faustwasm/libfaust-wasm/libfaust-wasm.js");
95
97
 
96
98
  // initialize the libfaust wasm
97
99
  const faustModule = await instantiateFaustModuleFromFile(faustModulePath);
@@ -136,10 +138,10 @@ process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1);
136
138
  FaustMonoDspGenerator,
137
139
  FaustCompiler,
138
140
  FaustSvgDiagrams
139
- } = await import("../node_modules/@shren/faustwasm/dist/esm/index.js");
141
+ } = await import("../node_modules/@grame/faustwasm/dist/esm/index.js");
140
142
 
141
143
  // initialize the libfaust wasm
142
- const faustModule = await instantiateFaustModuleFromFile("../node_modules/@shren/faustwasm/libfaust-wasm/libfaust-wasm.js");
144
+ const faustModule = await instantiateFaustModuleFromFile("../node_modules/@grame/faustwasm/libfaust-wasm/libfaust-wasm.js");
143
145
 
144
146
  // Get the Faust compiler
145
147
  const libFaust = new LibFaust(faustModule);
@@ -217,11 +219,11 @@ It provides *classic* Faust compilation services, which output is a raw WebAssem
217
219
 
218
220
  ### Faust Wasm Instance <a name="wasm"></a>
219
221
 
220
- This level takes a WebAssembly module produced by the Faust compiler or a precompiled module loaded from a file, and builds an instance of this module with the proper Wasm memory layout, ready to run, but not yet connected to any audio node. It is described in `FaustDspGenerator.ts`, `FaustWasmInstantiator.ts`, `FaustWebAudioDsp.ts` and `FaustDspInstance.ts` files.
222
+ This level takes a WebAssembly module produced by the Faust compiler or a precompiled module loaded from a file, and builds an instance of this module with the proper Wasm memory layout, ready to run. It is described in `FaustDspGenerator.ts`, `FaustWasmInstantiator.ts`, `FaustWebAudioDsp.ts` and `FaustDspInstance.ts` files.
221
223
 
222
224
  ### Faust Audio Nodes Instances and Offline Processor <a name="audio"></a>
223
225
 
224
- This level takes a Faust Wasm instance to build an audio node. [AudioWorklet](https://developer.mozilla.org/fr/docs/Web/API/AudioWorklet) and [ScriptProcessor](https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode) nodes are supported. It is described in `FaustAudioWorkletNode.ts` and `FaustAudioWorkletProcessor.ts` files.
226
+ This level takes a Faust Wasm instance to build an audio node. [AudioWorklet](https://developer.mozilla.org/fr/docs/Web/API/AudioWorklet) and [ScriptProcessor](https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode) nodes are supported. It is described in `FaustAudioWorkletNode.ts` and `FaustAudioWorkletProcessor.ts` files.
225
227
 
226
228
  **Warning**: AudioWorklet is a recent technology and may not be supported by all the browsers. Check the [compatibility](https://developer.mozilla.org/fr/docs/Web/API/AudioWorklet) chart.
227
229
 
@@ -3,7 +3,7 @@
3
3
  /// <reference types="emscripten" />
4
4
  /// <reference types="node" />
5
5
 
6
- export declare type FaustModuleFactory = EmscriptenModuleFactory<FaustModule>;
6
+ export type FaustModuleFactory = EmscriptenModuleFactory<FaustModule>;
7
7
  export interface FaustModule extends EmscriptenModule {
8
8
  ccall: typeof ccall;
9
9
  cwrap: typeof cwrap;
@@ -22,7 +22,7 @@ export interface FaustModule extends EmscriptenModule {
22
22
  FS: typeof FS;
23
23
  libFaustWasm: new () => LibFaustWasm;
24
24
  }
25
- export declare type FaustInfoType = "help" | "version" | "libdir" | "includedir" | "archdir" | "dspdir" | "pathslist";
25
+ export type FaustInfoType = "help" | "version" | "libdir" | "includedir" | "archdir" | "dspdir" | "pathslist";
26
26
  export interface IntVector {
27
27
  size(): number;
28
28
  get(i: number): number;
@@ -125,8 +125,8 @@ export interface FaustDspMeta {
125
125
  }[];
126
126
  ui: FaustUIDescriptor;
127
127
  }
128
- export declare type FaustUIDescriptor = FaustUIGroup[];
129
- export declare type FaustUIItem = FaustUIInputItem | FaustUIOutputItem | FaustUIGroup;
128
+ export type FaustUIDescriptor = FaustUIGroup[];
129
+ export type FaustUIItem = FaustUIInputItem | FaustUIOutputItem | FaustUIGroup;
130
130
  export interface FaustUIInputItem {
131
131
  type: FaustUIInputType;
132
132
  label: string;
@@ -156,15 +156,15 @@ export interface FaustUIMeta {
156
156
  hidden?: string;
157
157
  [key: string]: string | undefined;
158
158
  }
159
- export declare type FaustUIGroupType = "vgroup" | "hgroup" | "tgroup";
160
- export declare type FaustUIOutputType = "hbargraph" | "vbargraph";
161
- export declare type FaustUIInputType = "vslider" | "hslider" | "button" | "checkbox" | "nentry";
159
+ export type FaustUIGroupType = "vgroup" | "hgroup" | "tgroup";
160
+ export type FaustUIOutputType = "hbargraph" | "vbargraph";
161
+ export type FaustUIInputType = "vslider" | "hslider" | "button" | "checkbox" | "nentry";
162
162
  export interface FaustUIGroup {
163
163
  type: FaustUIGroupType;
164
164
  label: string;
165
165
  items: FaustUIItem[];
166
166
  }
167
- export declare type FaustUIType = FaustUIGroupType | FaustUIOutputType | FaustUIInputType;
167
+ export type FaustUIType = FaustUIGroupType | FaustUIOutputType | FaustUIInputType;
168
168
  export interface AudioParamDescriptor {
169
169
  automationRate?: AutomationRate;
170
170
  defaultValue?: number;
@@ -198,12 +198,12 @@ export interface InterfaceFFT {
198
198
  export declare const InterfaceFFT: {
199
199
  new (size: number): InterfaceFFT;
200
200
  };
201
- export declare type TWindowFunction = (index: number, length: number, ...args: any[]) => number;
202
- export declare type Writeable<T> = {
201
+ export type TWindowFunction = (index: number, length: number, ...args: any[]) => number;
202
+ export type Writeable<T> = {
203
203
  -readonly [P in keyof T]: T[P];
204
204
  };
205
- export declare type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array;
206
- export declare type TypedArrayConstructor = typeof Int8Array | typeof Uint8Array | typeof Int16Array | typeof Uint16Array | typeof Int32Array | typeof Uint32Array | typeof Uint8ClampedArray | typeof Float32Array | typeof Float64Array;
205
+ export type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array;
206
+ export type TypedArrayConstructor = typeof Int8Array | typeof Uint8Array | typeof Int16Array | typeof Uint16Array | typeof Int32Array | typeof Uint32Array | typeof Uint8ClampedArray | typeof Float32Array | typeof Float64Array;
207
207
  export declare const FFTUtils: {
208
208
  /** Inject window functions as array, no need to add rectangular (no windowing) */
209
209
  windowFunctions?: TWindowFunction[];
@@ -359,14 +359,14 @@ export declare class FaustWasmInstantiator {
359
359
  static createAsyncPolyDSPInstance(voiceFactory: LooseFaustDspFactory, mixerModule: WebAssembly.Module, voices: number, effectFactory?: LooseFaustDspFactory): Promise<FaustPolyDspInstance>;
360
360
  static createSyncPolyDSPInstance(voiceFactory: LooseFaustDspFactory, mixerModule: WebAssembly.Module, voices: number, effectFactory?: LooseFaustDspFactory): FaustPolyDspInstance;
361
361
  }
362
- export declare type OutputParamHandler = (path: string, value: number) => void;
363
- export declare type ComputeHandler = (buffer_size: number) => void;
364
- export declare type PlotHandler = (plotted: Float32Array[] | Float64Array[], index: number, events?: {
362
+ export type OutputParamHandler = (path: string, value: number) => void;
363
+ export type ComputeHandler = (buffer_size: number) => void;
364
+ export type PlotHandler = (plotted: Float32Array[] | Float64Array[], index: number, events?: {
365
365
  type: string;
366
366
  data: any;
367
367
  }[]) => void;
368
- export declare type MetadataHandler = (key: string, value: string) => void;
369
- export declare type UIHandler = (item: FaustUIItem) => void;
368
+ export type MetadataHandler = (key: string, value: string) => void;
369
+ export type UIHandler = (item: FaustUIItem) => void;
370
370
  /**
371
371
  * DSP implementation: mimic the C++ 'dsp' class:
372
372
  * - adding MIDI control: metadata are decoded and incoming MIDI messages will control the associated controllers
@@ -15,7 +15,10 @@ var __copyProps = (to, from, except, desc) => {
15
15
  }
16
16
  return to;
17
17
  };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
20
+ mod
21
+ ));
19
22
 
20
23
  // node_modules/tslib/tslib.js
21
24
  var require_tslib = __commonJS({
@@ -846,8 +849,8 @@ var require_jsSha256 = __commonJS({
846
849
  return this.hash.digest();
847
850
  };
848
851
  Sha2563.prototype.digest = function() {
849
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function() {
850
- return (0, tslib_1.__generator)(this, function(_a) {
852
+ return tslib_1.__awaiter(this, void 0, void 0, function() {
853
+ return tslib_1.__generator(this, function(_a) {
851
854
  return [2, this.digestSync()];
852
855
  });
853
856
  });
@@ -875,7 +878,7 @@ var require_build2 = __commonJS({
875
878
  "use strict";
876
879
  Object.defineProperty(exports, "__esModule", { value: true });
877
880
  var tslib_1 = require_tslib();
878
- (0, tslib_1.__exportStar)(require_jsSha256(), exports);
881
+ tslib_1.__exportStar(require_jsSha256(), exports);
879
882
  }
880
883
  });
881
884
 
@@ -1720,7 +1723,6 @@ var FaustDspInstance = class {
1720
1723
  this.fExports.setParamValue($dsp, index, value);
1721
1724
  }
1722
1725
  };
1723
- var FaustDspInstance_default = FaustDspInstance;
1724
1726
 
1725
1727
  // src/FaustWasmInstantiator.ts
1726
1728
  var FaustWasmInstantiator = class {
@@ -1802,13 +1804,15 @@ var FaustWasmInstantiator = class {
1802
1804
  return n;
1803
1805
  };
1804
1806
  const effectSize = effectMeta ? effectMeta.size : 0;
1805
- let memorySize = pow2limit(effectSize + dspMeta.size * voices + (dspMeta.inputs + dspMeta.outputs * 2) * (ptrSize + bufferSize * sampleSize)) / 65536;
1807
+ let memorySize = pow2limit(
1808
+ effectSize + dspMeta.size * voices + (dspMeta.inputs + dspMeta.outputs * 2) * (ptrSize + bufferSize * sampleSize)
1809
+ ) / 65536;
1806
1810
  memorySize = Math.max(2, memorySize);
1807
1811
  return new WebAssembly.Memory({ initial: memorySize, maximum: memorySize });
1808
1812
  }
1809
1813
  static createMonoDSPInstanceAux(instance, json) {
1810
1814
  const functions = instance.exports;
1811
- const api = new FaustDspInstance_default(functions);
1815
+ const api = new FaustDspInstance(functions);
1812
1816
  const memory = instance.exports.memory;
1813
1817
  return { memory, api, json };
1814
1818
  }
@@ -1871,12 +1875,12 @@ var FaustWasmInstantiator = class {
1871
1875
  const memory = this.createMemoryAux(voices, voiceFactory, effectFactory);
1872
1876
  const voiceInstance = await WebAssembly.instantiate(voiceFactory.module, this.createWasmImport(memory));
1873
1877
  const voiceFunctions = voiceInstance.exports;
1874
- const voiceAPI = new FaustDspInstance_default(voiceFunctions);
1878
+ const voiceAPI = new FaustDspInstance(voiceFunctions);
1875
1879
  const mixerAPI = this.createMixerAux(mixerModule, memory);
1876
1880
  if (effectFactory) {
1877
1881
  const effectInstance = await WebAssembly.instantiate(effectFactory.module, this.createWasmImport(memory));
1878
1882
  const effectFunctions = effectInstance.exports;
1879
- const effectAPI = new FaustDspInstance_default(effectFunctions);
1883
+ const effectAPI = new FaustDspInstance(effectFunctions);
1880
1884
  return {
1881
1885
  memory,
1882
1886
  voices,
@@ -1900,12 +1904,12 @@ var FaustWasmInstantiator = class {
1900
1904
  const memory = this.createMemoryAux(voices, voiceFactory, effectFactory);
1901
1905
  const voiceInstance = new WebAssembly.Instance(voiceFactory.module, this.createWasmImport(memory));
1902
1906
  const voiceFunctions = voiceInstance.exports;
1903
- const voiceAPI = new FaustDspInstance_default(voiceFunctions);
1907
+ const voiceAPI = new FaustDspInstance(voiceFunctions);
1904
1908
  const mixerAPI = this.createMixerAux(mixerModule, memory);
1905
1909
  if (effectFactory) {
1906
1910
  const effectInstance = new WebAssembly.Instance(effectFactory.module, this.createWasmImport(memory));
1907
1911
  const effectFunctions = effectInstance.exports;
1908
- const effectAPI = new FaustDspInstance_default(effectFunctions);
1912
+ const effectAPI = new FaustDspInstance(effectFunctions);
1909
1913
  return {
1910
1914
  memory,
1911
1915
  voices,
@@ -2316,7 +2320,13 @@ var FaustPolyWebAudioDsp = class extends FaustBaseWebAudioDsp {
2316
2320
  this.initMemory();
2317
2321
  this.fVoiceTable = [];
2318
2322
  for (let voice = 0; voice < this.fInstance.voices; voice++) {
2319
- this.fVoiceTable.push(new FaustWebAudioDspVoice(this.fJSONDsp.size * voice, this.fInstance.voiceAPI, this.fInputsItems, this.fPathTable, sampleRate));
2323
+ this.fVoiceTable.push(new FaustWebAudioDspVoice(
2324
+ this.fJSONDsp.size * voice,
2325
+ this.fInstance.voiceAPI,
2326
+ this.fInputsItems,
2327
+ this.fPathTable,
2328
+ sampleRate
2329
+ ));
2320
2330
  }
2321
2331
  if (this.fInstance.effectAPI)
2322
2332
  this.fInstance.effectAPI.init(this.fEffect, sampleRate);
@@ -3283,14 +3293,20 @@ var FaustMonoAudioWorkletNode = class extends FaustAudioWorkletNode {
3283
3293
  };
3284
3294
  var FaustPolyAudioWorkletNode = class extends FaustAudioWorkletNode {
3285
3295
  constructor(context, name, voiceFactory, mixerModule, voices, sampleSize, effectFactory, nodeOptions = {}) {
3286
- super(context, name, voiceFactory, {
3296
+ super(
3297
+ context,
3287
3298
  name,
3288
3299
  voiceFactory,
3289
- mixerModule,
3290
- voices,
3291
- sampleSize,
3292
- effectFactory
3293
- }, nodeOptions);
3300
+ {
3301
+ name,
3302
+ voiceFactory,
3303
+ mixerModule,
3304
+ voices,
3305
+ sampleSize,
3306
+ effectFactory
3307
+ },
3308
+ nodeOptions
3309
+ );
3294
3310
  this.onprocessorerror = (e) => {
3295
3311
  throw e;
3296
3312
  };
@@ -3482,15 +3498,15 @@ const faustData = ${JSON.stringify({
3482
3498
  poly: false
3483
3499
  })};
3484
3500
  // Implementation needed classes of functions
3485
- const ${FaustDspInstance_default.name}_default = ${FaustDspInstance_default.toString()}
3501
+ const ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
3486
3502
  const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
3487
3503
  const ${FaustMonoWebAudioDsp.name} = ${FaustMonoWebAudioDsp.toString()}
3488
3504
  const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3489
3505
  // Put them in dependencies
3490
3506
  const dependencies = {
3491
- ${FaustBaseWebAudioDsp.name},
3492
- ${FaustMonoWebAudioDsp.name},
3493
- ${FaustWasmInstantiator_default.name}
3507
+ FaustBaseWebAudioDsp: ${FaustBaseWebAudioDsp.name},
3508
+ FaustMonoWebAudioDsp: ${FaustMonoWebAudioDsp.name},
3509
+ FaustWasmInstantiator: ${FaustWasmInstantiator_default.name}
3494
3510
  };
3495
3511
  // Generate the actual AudioWorkletProcessor code
3496
3512
  (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
@@ -3525,16 +3541,16 @@ const faustData = ${JSON.stringify({
3525
3541
  fftOptions
3526
3542
  })};
3527
3543
  // Implementation needed classes of functions
3528
- const ${FaustDspInstance_default.name}_default = ${FaustDspInstance_default.toString()}
3544
+ const ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
3529
3545
  const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
3530
3546
  const ${FaustMonoWebAudioDsp.name} = ${FaustMonoWebAudioDsp.toString()}
3531
3547
  const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3532
3548
  const FFTUtils = ${fftUtils.toString()}
3533
3549
  // Put them in dependencies
3534
3550
  const dependencies = {
3535
- ${FaustBaseWebAudioDsp.name},
3536
- ${FaustMonoWebAudioDsp.name},
3537
- ${FaustWasmInstantiator_default.name},
3551
+ FaustBaseWebAudioDsp: ${FaustBaseWebAudioDsp.name},
3552
+ FaustMonoWebAudioDsp: ${FaustMonoWebAudioDsp.name},
3553
+ FaustWasmInstantiator: ${FaustWasmInstantiator_default.name},
3538
3554
  FFTUtils
3539
3555
  };
3540
3556
  // Generate the actual AudioWorkletProcessor code
@@ -3661,16 +3677,16 @@ const faustData = ${JSON.stringify({
3661
3677
  effectMeta
3662
3678
  })};
3663
3679
  // Implementation needed classes of functions
3664
- const ${FaustDspInstance_default.name}_default = ${FaustDspInstance_default.toString()}
3680
+ const ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
3665
3681
  const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
3666
3682
  const ${FaustPolyWebAudioDsp.name} = ${FaustPolyWebAudioDsp.toString()}
3667
3683
  const ${FaustWebAudioDspVoice.name} = ${FaustWebAudioDspVoice.toString()}
3668
3684
  const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3669
3685
  // Put them in dependencies
3670
3686
  const dependencies = {
3671
- ${FaustBaseWebAudioDsp.name},
3672
- ${FaustPolyWebAudioDsp.name},
3673
- ${FaustWasmInstantiator_default.name}
3687
+ FaustBaseWebAudioDsp: ${FaustBaseWebAudioDsp.name},
3688
+ FaustPolyWebAudioDsp: ${FaustPolyWebAudioDsp.name},
3689
+ FaustWasmInstantiator: ${FaustWasmInstantiator_default.name}
3674
3690
  };
3675
3691
  // Generate the actual AudioWorkletProcessor code
3676
3692
  (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
@@ -3730,7 +3746,7 @@ export {
3730
3746
  FaustAudioWorkletNode,
3731
3747
  FaustBaseWebAudioDsp,
3732
3748
  FaustCompiler_default as FaustCompiler,
3733
- FaustDspInstance_default as FaustDspInstance,
3749
+ FaustDspInstance,
3734
3750
  FaustMonoAudioWorkletNode,
3735
3751
  FaustMonoDspGenerator,
3736
3752
  FaustMonoOfflineProcessor,