@grame/faustwasm 0.12.2 → 0.13.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.
Files changed (81) hide show
  1. package/.prettierrc +5 -0
  2. package/README.md +21 -3
  3. package/assets/standalone/faustwasm/index.d.ts +38 -16
  4. package/assets/standalone/faustwasm/index.js +1593 -404
  5. package/assets/standalone/faustwasm/index.js.map +2 -2
  6. package/dist/cjs/index.d.ts +38 -16
  7. package/dist/cjs/index.js +1592 -404
  8. package/dist/cjs/index.js.map +2 -2
  9. package/dist/cjs-bundle/index.d.ts +38 -16
  10. package/dist/cjs-bundle/index.js +1595 -406
  11. package/dist/cjs-bundle/index.js.map +2 -2
  12. package/dist/esm/index.d.ts +38 -16
  13. package/dist/esm/index.js +1593 -404
  14. package/dist/esm/index.js.map +2 -2
  15. package/dist/esm-bundle/index.d.ts +38 -16
  16. package/dist/esm-bundle/index.js +1595 -406
  17. package/dist/esm-bundle/index.js.map +2 -2
  18. package/eslint.config.js +11 -0
  19. package/package.json +57 -51
  20. package/sound.cpp +163 -0
  21. package/sound.dsp +4 -0
  22. package/sound.json +1 -0
  23. package/sound.wasm +0 -0
  24. package/src/FaustAudioWorkletCommunicator.ts +150 -143
  25. package/src/FaustAudioWorkletNode.ts +173 -75
  26. package/src/FaustAudioWorkletProcessor.ts +218 -90
  27. package/src/FaustCmajor.ts +9 -3
  28. package/src/FaustCompiler.ts +112 -35
  29. package/src/FaustDspGenerator.ts +589 -117
  30. package/src/FaustDspInstance.ts +58 -24
  31. package/src/FaustFFTAudioWorkletProcessor.ts +822 -612
  32. package/src/FaustOfflineProcessor.ts +187 -56
  33. package/src/FaustScriptProcessorNode.ts +156 -49
  34. package/src/FaustSensors.ts +426 -96
  35. package/src/FaustSvgDiagrams.ts +18 -5
  36. package/src/FaustWasmInstantiator.ts +224 -70
  37. package/src/FaustWebAudioDsp.ts +1060 -349
  38. package/src/LibFaust.ts +13 -4
  39. package/src/SoundfileReader.ts +175 -131
  40. package/src/WavDecoder.ts +42 -20
  41. package/src/WavEncoder.ts +35 -21
  42. package/src/copyWebStandaloneAssets.d.ts +20 -5
  43. package/src/copyWebStandaloneAssets.js +203 -75
  44. package/src/exports-bundle.ts +5 -5
  45. package/src/exports.ts +24 -24
  46. package/src/faust2CmajorFiles.d.ts +7 -3
  47. package/src/faust2cmajorFiles.js +10 -8
  48. package/src/faust2svgFiles.d.ts +7 -3
  49. package/src/faust2svgFiles.js +9 -7
  50. package/src/faust2wasmFiles.d.ts +10 -5
  51. package/src/faust2wasmFiles.js +34 -17
  52. package/src/faust2wavFiles.d.ts +12 -3
  53. package/src/faust2wavFiles.js +25 -12
  54. package/src/index-bundle-iife.ts +2 -2
  55. package/src/index-bundle.ts +1 -1
  56. package/src/index.ts +1 -1
  57. package/src/instantiateFaustModule.ts +43 -36
  58. package/src/instantiateFaustModuleFromFile.ts +30 -14
  59. package/src/types.ts +101 -25
  60. package/test/faustlive-wasm/faustwasm/index.d.ts +38 -16
  61. package/test/faustlive-wasm/faustwasm/index.js +1593 -404
  62. package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
  63. package/test/web/create-faust-node.html +53 -0
  64. package/test/web/create-faust-node.js +181 -0
  65. package/test/organ/create-node.js +0 -252
  66. package/test/organ/dsp-meta.json +0 -131
  67. package/test/organ/dsp-module.wasm +0 -0
  68. package/test/organ/faust-pwa.js +0 -344
  69. package/test/organ/faust-ui/index.css +0 -442
  70. package/test/organ/faust-ui/index.css.map +0 -1
  71. package/test/organ/faust-ui/index.d.ts +0 -1
  72. package/test/organ/faust-ui/index.js +0 -3756
  73. package/test/organ/faust-ui/index.js.map +0 -1
  74. package/test/organ/faustwasm/index.d.ts +0 -1705
  75. package/test/organ/faustwasm/index.js +0 -4773
  76. package/test/organ/faustwasm/index.js.map +0 -7
  77. package/test/organ/icon.png +0 -0
  78. package/test/organ/index.html +0 -76
  79. package/test/organ/index.js +0 -69
  80. package/test/organ/manifest.json +0 -17
  81. package/test/organ/service-worker.js +0 -165
@@ -1,7 +1,7 @@
1
1
  //@ts-check
2
- import * as fs from "fs";
3
- import * as path from "path";
4
- import * as process from "process";
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
+ import * as process from 'process';
5
5
  import {
6
6
  instantiateFaustModuleFromFile,
7
7
  LibFaust,
@@ -9,8 +9,8 @@ import {
9
9
  FaustMonoDspGenerator,
10
10
  WavDecoder,
11
11
  WavEncoder
12
- } from "../dist/esm/index.js";
13
- import { fileURLToPath } from "url";
12
+ } from '../dist/esm/index.js';
13
+ import { fileURLToPath } from 'url';
14
14
 
15
15
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
16
16
  const __filename = fileURLToPath(import.meta.url);
@@ -25,18 +25,29 @@ const __filename = fileURLToPath(import.meta.url);
25
25
  * @param {number} bitDepth
26
26
  * @param {string[]} [argv]
27
27
  */
28
- const faust2wavFiles = async (inputFile, inputWav, outputWav, bufferSize = 64, sampleRate = 44100, samples = 5 * sampleRate, bitDepth = 16, argv = []) => {
29
- const faustModule = await instantiateFaustModuleFromFile(path.join(__dirname, "../libfaust-wasm/libfaust-wasm.js"));
28
+ const faust2wavFiles = async (
29
+ inputFile,
30
+ inputWav,
31
+ outputWav,
32
+ bufferSize = 64,
33
+ sampleRate = 44100,
34
+ samples = 5 * sampleRate,
35
+ bitDepth = 16,
36
+ argv = []
37
+ ) => {
38
+ const faustModule = await instantiateFaustModuleFromFile(
39
+ path.join(__dirname, '../libfaust-wasm/libfaust-wasm.js')
40
+ );
30
41
  const libFaust = new LibFaust(faustModule);
31
42
  const compiler = new FaustCompiler(libFaust);
32
43
  console.log(`Faust Compiler version: ${compiler.version()}`);
33
44
  console.log(`Reading file ${inputFile}`);
34
- const code = fs.readFileSync(inputFile, { encoding: "utf8" });
45
+ const code = fs.readFileSync(inputFile, { encoding: 'utf8' });
35
46
  const { name } = path.parse(inputFile);
36
47
  const gen = new FaustMonoDspGenerator();
37
- await gen.compile(compiler, name, code, argv.join(" "));
48
+ await gen.compile(compiler, name, code, argv.join(' '));
38
49
  const processor = await gen.createOfflineProcessor(sampleRate, bufferSize);
39
- if (!processor) throw Error("Processor not generated");
50
+ if (!processor) throw Error('Processor not generated');
40
51
  /** @type {Float32Array[] | undefined} */
41
52
  let input = undefined;
42
53
  if (inputWav) {
@@ -46,8 +57,10 @@ const faust2wavFiles = async (inputFile, inputWav, outputWav, bufferSize = 64, s
46
57
  input = WavDecoder.decode(inputBuffer).channelData;
47
58
  }
48
59
  console.log(`Processing...`);
49
- const output = processor.render(input, samples, sample => process.stdout.write(`\r${sample} / ${samples}`));
50
- console.log("");
60
+ const output = processor.render(input, samples, (sample) =>
61
+ process.stdout.write(`\r${sample} / ${samples}`)
62
+ );
63
+ console.log('');
51
64
  console.log(`Encoding...`);
52
65
  const outputBuffer = WavEncoder.encode(output, { bitDepth, sampleRate });
53
66
  console.log(`Writing output wav file ${outputWav}.`);
@@ -1,7 +1,7 @@
1
- import * as faustwasm from "./exports-bundle";
1
+ import * as faustwasm from './exports-bundle';
2
2
  // export default faustwasm;
3
3
  // Bug with dts-bundle-generator
4
4
 
5
- export * from "./exports-bundle";
5
+ export * from './exports-bundle';
6
6
 
7
7
  (globalThis as any).faustwasm = faustwasm;
@@ -2,4 +2,4 @@
2
2
  // export default faustwasm;
3
3
  // Bug with dts-bundle-generator
4
4
 
5
- export * from "./exports-bundle";
5
+ export * from './exports-bundle';
package/src/index.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  // export default faustwasm;
3
3
  // Bug with dts-bundle-generator
4
4
 
5
- export * from "./exports";
5
+ export * from './exports';
@@ -1,36 +1,43 @@
1
- import factoryFn from "../libfaust-wasm/libfaust-wasm.cjs";
2
- import wasmBinary from "../libfaust-wasm/libfaust-wasm.wasm";
3
- import dataBinary from "../libfaust-wasm/libfaust-wasm.data";
4
-
5
- export const FaustModuleFactoryFn = factoryFn;
6
- export const FaustModuleFactoryWasm = wasmBinary;
7
- export const FaustModuleFactoryData = dataBinary;
8
-
9
- /**
10
- * Instantiate `FaustModule` using bundled binaries. Module constructor and files can be overriden.
11
- */
12
- const instantiateFaustModule = async (FaustModuleFactoryIn = factoryFn, dataBinaryIn = dataBinary, wasmBinaryIn = wasmBinary) => {
13
- const g = globalThis as any;
14
- if (g.AudioWorkletGlobalScope) {
15
- g.importScripts = () => { };
16
- g.self = { location: { href: "" } };
17
- }
18
- const faustModule = await FaustModuleFactoryIn({
19
- // Create a copy to guarantee a standard ArrayBuffer
20
- wasmBinary: (new Uint8Array(wasmBinaryIn)).buffer,
21
- getPreloadedPackage: (remotePackageName: string, remotePackageSize: number) => {
22
- if (remotePackageName === "libfaust-wasm.data") {
23
- // Create a copy to guarantee a standard ArrayBuffer
24
- return (new Uint8Array(dataBinaryIn)).buffer;
25
- }
26
- return new ArrayBuffer(0);
27
- }
28
- });
29
- if (g.AudioWorkletGlobalScope) {
30
- delete g.importScripts;
31
- delete g.self;
32
- }
33
- return faustModule;
34
- };
35
-
36
- export default instantiateFaustModule;
1
+ import factoryFn from '../libfaust-wasm/libfaust-wasm.cjs';
2
+ import wasmBinary from '../libfaust-wasm/libfaust-wasm.wasm';
3
+ import dataBinary from '../libfaust-wasm/libfaust-wasm.data';
4
+
5
+ export const FaustModuleFactoryFn = factoryFn;
6
+ export const FaustModuleFactoryWasm = wasmBinary;
7
+ export const FaustModuleFactoryData = dataBinary;
8
+
9
+ /**
10
+ * Instantiate `FaustModule` using bundled binaries. Module constructor and files can be overriden.
11
+ */
12
+ const instantiateFaustModule = async (
13
+ FaustModuleFactoryIn = factoryFn,
14
+ dataBinaryIn = dataBinary,
15
+ wasmBinaryIn = wasmBinary
16
+ ) => {
17
+ const g = globalThis as any;
18
+ if (g.AudioWorkletGlobalScope) {
19
+ g.importScripts = () => {};
20
+ g.self = { location: { href: '' } };
21
+ }
22
+ const faustModule = await FaustModuleFactoryIn({
23
+ // Create a copy to guarantee a standard ArrayBuffer
24
+ wasmBinary: new Uint8Array(wasmBinaryIn).buffer,
25
+ getPreloadedPackage: (
26
+ remotePackageName: string,
27
+ remotePackageSize: number
28
+ ) => {
29
+ if (remotePackageName === 'libfaust-wasm.data') {
30
+ // Create a copy to guarantee a standard ArrayBuffer
31
+ return new Uint8Array(dataBinaryIn).buffer;
32
+ }
33
+ return new ArrayBuffer(0);
34
+ }
35
+ });
36
+ if (g.AudioWorkletGlobalScope) {
37
+ delete g.importScripts;
38
+ delete g.self;
39
+ }
40
+ return faustModule;
41
+ };
42
+
43
+ export default instantiateFaustModule;
@@ -1,4 +1,4 @@
1
- import type { FaustModuleFactory } from "./types";
1
+ import type { FaustModuleFactory } from './types';
2
2
 
3
3
  /**
4
4
  * Load libfaust-wasm files, than instantiate libFaust
@@ -6,24 +6,31 @@ import type { FaustModuleFactory } from "./types";
6
6
  * @param dataFile path to `libfaust-wasm.data`
7
7
  * @param wasmFile path to `libfaust-wasm.wasm`
8
8
  */
9
- const instantiateFaustModuleFromFile = async (jsFile: string, dataFile = jsFile.replace(/c?js$/, "data"), wasmFile = jsFile.replace(/c?js$/, "wasm")) => {
9
+ const instantiateFaustModuleFromFile = async (
10
+ jsFile: string,
11
+ dataFile = jsFile.replace(/c?js$/, 'data'),
12
+ wasmFile = jsFile.replace(/c?js$/, 'wasm')
13
+ ) => {
10
14
  let FaustModule: FaustModuleFactory;
11
15
  let dataBinary: ArrayBuffer;
12
16
  let wasmBinary: ArrayBuffer;
13
17
  const jsCodeHead = /var (.+) = \(/;
14
- if (typeof window === "object") {
18
+ if (typeof window === 'object') {
15
19
  let jsCode = await (await fetch(jsFile)).text();
16
20
  jsCode = `${jsCode}
17
21
  export default ${jsCode.match(jsCodeHead)?.[1]};
18
22
  `;
19
- const jsFileMod = URL.createObjectURL(new Blob([jsCode], { type: "text/javascript" }));
20
- FaustModule = (await import(/* webpackIgnore: true */jsFileMod)).default;
23
+ const jsFileMod = URL.createObjectURL(
24
+ new Blob([jsCode], { type: 'text/javascript' })
25
+ );
26
+ FaustModule = (await import(/* webpackIgnore: true */ jsFileMod))
27
+ .default;
21
28
  dataBinary = await (await fetch(dataFile)).arrayBuffer();
22
29
  wasmBinary = await (await fetch(wasmFile)).arrayBuffer();
23
30
  } else {
24
- const { promises: fs } = await import("fs");
25
- const { pathToFileURL } = await import("url");
26
- let jsCode = (await fs.readFile(jsFile, { encoding: "utf-8" }));
31
+ const { promises: fs } = await import('fs');
32
+ const { pathToFileURL } = await import('url');
33
+ let jsCode = await fs.readFile(jsFile, { encoding: 'utf-8' });
27
34
  jsCode = `
28
35
  import process from "process";
29
36
  import * as path from "path";
@@ -38,18 +45,27 @@ ${jsCode}
38
45
 
39
46
  export default ${jsCode.match(jsCodeHead)?.[1]};
40
47
  `;
41
- const jsFileMod = jsFile.replace(/c?js$/, "mjs");
48
+ const jsFileMod = jsFile.replace(/c?js$/, 'mjs');
42
49
  await fs.writeFile(jsFileMod, jsCode);
43
- FaustModule = (await import(/* webpackIgnore: true */pathToFileURL(jsFileMod).href)).default;
50
+ FaustModule = (
51
+ await import(
52
+ /* webpackIgnore: true */ pathToFileURL(jsFileMod).href
53
+ )
54
+ ).default;
44
55
  await fs.unlink(jsFileMod);
45
56
  // Using a type assertion `as ArrayBuffer` to satisfy the strict type checking.
46
- dataBinary = (new Uint8Array(await fs.readFile(dataFile))).buffer as ArrayBuffer;
47
- wasmBinary = (new Uint8Array(await fs.readFile(wasmFile))).buffer as ArrayBuffer;
57
+ dataBinary = new Uint8Array(await fs.readFile(dataFile))
58
+ .buffer as ArrayBuffer;
59
+ wasmBinary = new Uint8Array(await fs.readFile(wasmFile))
60
+ .buffer as ArrayBuffer;
48
61
  }
49
62
  const faustModule = await FaustModule({
50
63
  wasmBinary,
51
- getPreloadedPackage: (remotePackageName: string, remotePackageSize: number) => {
52
- if (remotePackageName === "libfaust-wasm.data") return dataBinary;
64
+ getPreloadedPackage: (
65
+ remotePackageName: string,
66
+ remotePackageSize: number
67
+ ) => {
68
+ if (remotePackageName === 'libfaust-wasm.data') return dataBinary;
53
69
  return new ArrayBuffer(0);
54
70
  }
55
71
  });
package/src/types.ts CHANGED
@@ -3,8 +3,17 @@ export type FaustModuleFactory = EmscriptenModuleFactory<FaustModule>;
3
3
  export interface FaustModule extends EmscriptenModule {
4
4
  ccall: typeof ccall;
5
5
  cwrap: typeof cwrap;
6
- UTF8ArrayToString(u8Array: number[], ptr: number, maxBytesToRead?: number): string;
7
- stringToUTF8Array(str: string, outU8Array: number[], outIdx: number, maxBytesToWrite: number): number;
6
+ UTF8ArrayToString(
7
+ u8Array: number[],
8
+ ptr: number,
9
+ maxBytesToRead?: number
10
+ ): string;
11
+ stringToUTF8Array(
12
+ str: string,
13
+ outU8Array: number[],
14
+ outIdx: number,
15
+ maxBytesToWrite: number
16
+ ): number;
8
17
  UTF8ToString: typeof UTF8ToString;
9
18
  UTF16ToString: typeof UTF16ToString;
10
19
  UTF32ToString: typeof UTF32ToString;
@@ -19,7 +28,14 @@ export interface FaustModule extends EmscriptenModule {
19
28
  libFaustWasm: new () => LibFaustWasm;
20
29
  }
21
30
 
22
- export type FaustInfoType = "help" | "version" | "libdir" | "includedir" | "archdir" | "dspdir" | "pathslist";
31
+ export type FaustInfoType =
32
+ | 'help'
33
+ | 'version'
34
+ | 'libdir'
35
+ | 'includedir'
36
+ | 'archdir'
37
+ | 'dspdir'
38
+ | 'pathslist';
23
39
 
24
40
  export interface IntVector {
25
41
  size(): number;
@@ -39,7 +55,7 @@ export interface FaustDspWasm {
39
55
  export interface LibFaustWasm {
40
56
  /**
41
57
  * Return the Faust compiler version.
42
- *
58
+ *
43
59
  * @returns the version
44
60
  */
45
61
  version(): string;
@@ -53,7 +69,12 @@ export interface LibFaustWasm {
53
69
  * @param useInternalMemory - tell the compiler to generate static embedded memory or not
54
70
  * @returns an opaque reference to the factory
55
71
  */
56
- createDSPFactory(name: string, code: string, args: string, useInternalMemory: boolean): FaustDspWasm;
72
+ createDSPFactory(
73
+ name: string,
74
+ code: string,
75
+ args: string,
76
+ useInternalMemory: boolean
77
+ ): FaustDspWasm;
57
78
 
58
79
  /**
59
80
  * Delete a dsp factory.
@@ -104,7 +125,7 @@ export interface LibFaustWasm {
104
125
  getInfos(what: FaustInfoType): string;
105
126
  }
106
127
 
107
- export interface FaustDspFactory extends Required<LooseFaustDspFactory> { }
128
+ export type FaustDspFactory = Required<LooseFaustDspFactory>;
108
129
 
109
130
  /**
110
131
  * The Factory structure.
@@ -167,20 +188,29 @@ export interface FaustUIMeta {
167
188
  [order: number]: string;
168
189
  style?: string; // "knob" | "menu{'Name0':value0;'Name1':value1}" | "radio{'Name0':value0;'Name1':value1}" | "led";
169
190
  unit?: string;
170
- scale?: "linear" | "exp" | "log";
191
+ scale?: 'linear' | 'exp' | 'log';
171
192
  tooltip?: string;
172
193
  hidden?: string;
173
194
  [key: string]: string | undefined;
174
195
  }
175
- export type FaustUIGroupType = "vgroup" | "hgroup" | "tgroup";
176
- export type FaustUIOutputType = "hbargraph" | "vbargraph";
177
- export type FaustUIInputType = "vslider" | "hslider" | "button" | "checkbox" | "nentry" | "soundfile";
196
+ export type FaustUIGroupType = 'vgroup' | 'hgroup' | 'tgroup';
197
+ export type FaustUIOutputType = 'hbargraph' | 'vbargraph';
198
+ export type FaustUIInputType =
199
+ | 'vslider'
200
+ | 'hslider'
201
+ | 'button'
202
+ | 'checkbox'
203
+ | 'nentry'
204
+ | 'soundfile';
178
205
  export interface FaustUIGroup {
179
206
  type: FaustUIGroupType;
180
207
  label: string;
181
208
  items: FaustUIItem[];
182
209
  }
183
- export type FaustUIType = FaustUIGroupType | FaustUIOutputType | FaustUIInputType;
210
+ export type FaustUIType =
211
+ | FaustUIGroupType
212
+ | FaustUIOutputType
213
+ | FaustUIInputType;
184
214
 
185
215
  export interface AudioParamDescriptor {
186
216
  automationRate?: AutomationRate;
@@ -192,18 +222,25 @@ export interface AudioParamDescriptor {
192
222
 
193
223
  export interface AudioWorkletProcessor {
194
224
  port: MessagePort;
195
- process(inputs: Float32Array[][], outputs: Float32Array[][], parameters: Record<string, Float32Array>): boolean;
225
+ process(
226
+ inputs: Float32Array[][],
227
+ outputs: Float32Array[][],
228
+ parameters: Record<string, Float32Array>
229
+ ): boolean;
196
230
  }
197
231
  export declare const AudioWorkletProcessor: {
198
232
  prototype: AudioWorkletProcessor;
199
233
  parameterDescriptors: AudioParamDescriptor[];
200
- new(options: AudioWorkletNodeOptions): AudioWorkletProcessor;
234
+ new (options: AudioWorkletNodeOptions): AudioWorkletProcessor;
201
235
  };
202
236
 
203
237
  export interface AudioWorkletGlobalScope {
204
238
  AudioWorkletGlobalScope: any;
205
239
  globalThis: AudioWorkletGlobalScope;
206
- registerProcessor: (name: string, constructor: new (options: any) => AudioWorkletProcessor) => void;
240
+ registerProcessor: (
241
+ name: string,
242
+ constructor: new (options: any) => AudioWorkletProcessor
243
+ ) => void;
207
244
  currentFrame: number;
208
245
  currentTime: number;
209
246
  sampleRate: number;
@@ -211,18 +248,44 @@ export interface AudioWorkletGlobalScope {
211
248
  }
212
249
 
213
250
  export interface InterfaceFFT {
214
- forward(arr: ArrayLike<number> | ((arr: Float32Array) => any)): Float32Array;
215
- inverse(arr: ArrayLike<number> | ((arr: Float32Array) => any)): Float32Array;
251
+ forward(
252
+ arr: ArrayLike<number> | ((arr: Float32Array) => any)
253
+ ): Float32Array;
254
+ inverse(
255
+ arr: ArrayLike<number> | ((arr: Float32Array) => any)
256
+ ): Float32Array;
216
257
  dispose(): void;
217
258
  }
218
259
  export declare const InterfaceFFT: {
219
- new(size: number): InterfaceFFT;
220
- }
260
+ new (size: number): InterfaceFFT;
261
+ };
221
262
 
222
- export type TWindowFunction = (index: number, length: number, ...args: any[]) => number;
263
+ export type TWindowFunction = (
264
+ index: number,
265
+ length: number,
266
+ ...args: any[]
267
+ ) => number;
223
268
  export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
224
- export type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array;
225
- export type TypedArrayConstructor = typeof Int8Array | typeof Uint8Array | typeof Int16Array | typeof Uint16Array | typeof Int32Array | typeof Uint32Array | typeof Uint8ClampedArray | typeof Float32Array | typeof Float64Array;
269
+ export type TypedArray =
270
+ | Int8Array
271
+ | Uint8Array
272
+ | Int16Array
273
+ | Uint16Array
274
+ | Int32Array
275
+ | Uint32Array
276
+ | Uint8ClampedArray
277
+ | Float32Array
278
+ | Float64Array;
279
+ export type TypedArrayConstructor =
280
+ | typeof Int8Array
281
+ | typeof Uint8Array
282
+ | typeof Int16Array
283
+ | typeof Uint16Array
284
+ | typeof Int32Array
285
+ | typeof Uint32Array
286
+ | typeof Uint8ClampedArray
287
+ | typeof Float32Array
288
+ | typeof Float64Array;
226
289
 
227
290
  export declare const FFTUtils: {
228
291
  /** Inject window functions as array, no need to add rectangular (no windowing) */
@@ -230,12 +293,25 @@ export declare const FFTUtils: {
230
293
  /** Get a FFT interface constructor */
231
294
  getFFT: () => Promise<typeof InterfaceFFT>;
232
295
  /** Convert from FFTed (spectral) signal to three arrays for Faust processor's input, fft is readonly, real/imag/index length = *fftSize* / 2 + 1; fft length depends on the FFT implementation */
233
- fftToSignal: (fft: Float32Array | Float64Array, real: Float32Array | Float64Array, imag?: Float32Array | Float64Array, index?: Float32Array | Float64Array) => any;
296
+ fftToSignal: (
297
+ fft: Float32Array | Float64Array,
298
+ real: Float32Array | Float64Array,
299
+ imag?: Float32Array | Float64Array,
300
+ index?: Float32Array | Float64Array
301
+ ) => any;
234
302
  /** Convert from Faust processor's output to spectral data for Inversed FFT, real/imag are readonly, real/imag length = *fftSize* / 2 + 1; fft length depends on the FFT implementation */
235
- signalToFFT: (real: Float32Array | Float64Array, imag: Float32Array | Float64Array, fft: Float32Array | Float64Array) => any;
303
+ signalToFFT: (
304
+ real: Float32Array | Float64Array,
305
+ imag: Float32Array | Float64Array,
306
+ fft: Float32Array | Float64Array
307
+ ) => any;
236
308
  /** Convert from Faust processor's output to direct audio output, real/imag are readonly, fft length = fftSize = (real/imag length - 1) * 2 */
237
- signalToNoFFT: (real: Float32Array | Float64Array, imag: Float32Array | Float64Array, fft: Float32Array | Float64Array) => any;
238
- }
309
+ signalToNoFFT: (
310
+ real: Float32Array | Float64Array,
311
+ imag: Float32Array | Float64Array,
312
+ fft: Float32Array | Float64Array
313
+ ) => any;
314
+ };
239
315
 
240
316
  export interface AudioData {
241
317
  sampleRate: number;
@@ -91,8 +91,7 @@ export interface LibFaustWasm {
91
91
  */
92
92
  getInfos(what: FaustInfoType): string;
93
93
  }
94
- export interface FaustDspFactory extends Required<LooseFaustDspFactory> {
95
- }
94
+ export type FaustDspFactory = Required<LooseFaustDspFactory>;
96
95
  /**
97
96
  * The Factory structure.
98
97
  */
@@ -404,7 +403,7 @@ export declare class FaustWasmInstantiator {
404
403
  private static createMemoryMono;
405
404
  private static createMemoryPoly;
406
405
  private static createMixerAux;
407
- static loadDSPFactory(wasmPath: string, jsonPath: string): Promise<FaustDspFactory>;
406
+ static loadDSPFactory(wasmPath: string, jsonPath: string): Promise<Required<LooseFaustDspFactory>>;
408
407
  static loadDSPMixer(mixerPath: string, fs?: typeof FS): Promise<WebAssembly.Module>;
409
408
  static createAsyncMonoDSPInstance(factory: LooseFaustDspFactory): Promise<FaustMonoDspInstance>;
410
409
  static createSyncMonoDSPInstance(factory: LooseFaustDspFactory): FaustMonoDspInstance;
@@ -673,10 +672,10 @@ export interface IFaustBaseWebAudioDsp {
673
672
  */
674
673
  getUI(): FaustUIDescriptor;
675
674
  /**
676
- * Get DSP UI items description.
677
- *
678
- * @return the DSP UI items description
679
- */
675
+ * Get DSP UI items description.
676
+ *
677
+ * @return the DSP UI items description
678
+ */
680
679
  getDescriptors(): FaustUIInputItem[];
681
680
  /**
682
681
  * Get DSP JSON description with its UI and metadata.
@@ -685,8 +684,8 @@ export interface IFaustBaseWebAudioDsp {
685
684
  */
686
685
  getJSON(): string;
687
686
  /**
688
- * Start accelerometer and gyroscope handlers.
689
- */
687
+ * Start accelerometer and gyroscope handlers.
688
+ */
690
689
  startSensors(): void;
691
690
  /**
692
691
  * Stop accelerometer and gyroscope handlers.
@@ -720,8 +719,7 @@ export interface IFaustBaseWebAudioDsp {
720
719
  */
721
720
  destroy(): void;
722
721
  }
723
- export interface IFaustMonoWebAudioDsp extends IFaustBaseWebAudioDsp {
724
- }
722
+ export type IFaustMonoWebAudioDsp = IFaustBaseWebAudioDsp;
725
723
  export interface IFaustMonoWebAudioNode extends IFaustMonoWebAudioDsp, AudioNode {
726
724
  }
727
725
  export interface IFaustPolyWebAudioDsp extends IFaustBaseWebAudioDsp {
@@ -849,7 +847,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
849
847
  *
850
848
  * @param allocator : the wasm memory allocator
851
849
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
852
- */
850
+ */
853
851
  protected initSoundfileMemory(allocator: WasmAllocator, baseDSP: number): void;
854
852
  protected updateOutputs(): void;
855
853
  metadata(handler: MetadataHandler): void;
@@ -1164,18 +1162,18 @@ export declare class FaustCompiler implements IFaustCompiler {
1164
1162
  code: string;
1165
1163
  json: any;
1166
1164
  poly: boolean;
1167
- }>): Promise<Map<string, FaustDspFactory>[]>;
1165
+ }>): Promise<Map<string, Required<LooseFaustDspFactory>>[]>;
1168
1166
  /**
1169
1167
  * Import a stringified DSP factories table
1170
1168
  */
1171
- static importDSPFactories(tableStr: string): Promise<Map<string, FaustDspFactory>[]>;
1169
+ static importDSPFactories(tableStr: string): Promise<Map<string, Required<LooseFaustDspFactory>>[]>;
1172
1170
  constructor(libFaust: ILibFaust);
1173
1171
  private intVec2intArray;
1174
1172
  private createDSPFactory;
1175
1173
  version(): string;
1176
1174
  getErrorMessage(): string;
1177
- createMonoDSPFactory(name: string, code: string, args: string): Promise<FaustDspFactory | null>;
1178
- createPolyDSPFactory(name: string, code: string, args: string): Promise<FaustDspFactory | null>;
1175
+ createMonoDSPFactory(name: string, code: string, args: string): Promise<Required<LooseFaustDspFactory> | null>;
1176
+ createPolyDSPFactory(name: string, code: string, args: string): Promise<Required<LooseFaustDspFactory> | null>;
1179
1177
  deleteDSPFactory(factory: FaustDspFactory): void;
1180
1178
  expandDSP(code: string, args: string): string;
1181
1179
  generateAuxFiles(name: string, code: string, args: string): boolean;
@@ -1524,6 +1522,20 @@ export interface GeneratorSupportingSoundfiles {
1524
1522
  */
1525
1523
  getSoundfileList(): string[];
1526
1524
  }
1525
+ export interface IFaustDspGenerator {
1526
+ /**
1527
+ * Create a monophonic or polyphonic WebAudio node (either ScriptProcessorNode or AudioWorkletNode).
1528
+ * Analyze the code to decide whether to create a monophonic or polyphonic node.
1529
+ *
1530
+ * @param context - the WebAudio context
1531
+ * @param name - DSP name, can be used for processorName
1532
+ * @param code - the DSP code
1533
+ * @param sp - whether to compile a ScriptProcessorNode or an AudioWorkletNode
1534
+ * @param bufferSize - the buffer size in frames to be used in ScriptProcessorNode only, since AudioWorkletNode always uses 128 frames
1535
+ * @returns the compiled monophonic or polyphonic WebAudio node or 'null' if failure
1536
+ */
1537
+ createFaustNode(context: BaseAudioContext, name: string, code: string, sp?: boolean, bufferSize?: number): Promise<IFaustMonoWebAudioNode | IFaustPolyWebAudioNode | null>;
1538
+ }
1527
1539
  export interface IFaustMonoDspGenerator extends GeneratorSupportingSoundfiles {
1528
1540
  /**
1529
1541
  * Compile a monophonic DSP factory from given code.
@@ -1697,6 +1709,16 @@ export declare class FaustPolyDspGenerator implements IFaustPolyDspGenerator {
1697
1709
  getJSON(): string;
1698
1710
  getUI(): FaustUIDescriptor;
1699
1711
  }
1712
+ export declare class FaustDspGenerator implements IFaustDspGenerator {
1713
+ private static compilerPromise;
1714
+ private extractMidiAndNvoices;
1715
+ /**
1716
+ * Compile DSP code, inspect metadata for [nvoices:] (and optionally [midi:on]), and build either a mono
1717
+ * or poly WebAudio node (ScriptProcessor or AudioWorklet depending on `sp`). Compilation uses a shared,
1718
+ * lazily-created libfaust instance to avoid repeatedly instantiating the WASM compiler.
1719
+ */
1720
+ createFaustNode(context: BaseAudioContext, name: string, code: string, sp?: boolean, bufferSize?: number): Promise<IFaustMonoWebAudioNode | IFaustPolyWebAudioNode | null>;
1721
+ }
1700
1722
 
1701
1723
  export {
1702
1724
  AudioData$1 as AudioData,