@grame/faustwasm 0.12.2 → 0.13.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.
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 +1574 -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 +1573 -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 +1576 -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 +1574 -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 +1576 -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 +561 -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 +1574 -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 +186 -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,8 +1,8 @@
1
1
  //@ts-check
2
- import * as fs from "fs";
3
- import * as path from "path";
4
- import { cpSync, cpSyncModify } from "../fileutils.js";
5
- import { fileURLToPath } from "url";
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
+ import { cpSync, cpSyncModify } from '../fileutils.js';
5
+ import { fileURLToPath } from 'url';
6
6
 
7
7
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
8
  const __filename = fileURLToPath(import.meta.url);
@@ -13,39 +13,86 @@ const __filename = fileURLToPath(import.meta.url);
13
13
  * @param {boolean} [poly] - Whether the DSP is polyphonic.
14
14
  * @param {boolean} [effect] - Whether the DSP has an effect module.
15
15
  */
16
- const copyWebStandaloneAssets = (outputDir, dspName, poly = false, effect = false) => {
17
- console.log(`Writing assets files.`)
16
+ const copyWebStandaloneAssets = (
17
+ outputDir,
18
+ dspName,
19
+ poly = false,
20
+ effect = false
21
+ ) => {
22
+ console.log(`Writing assets files.`);
18
23
  if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
19
24
 
20
25
  // Define find and replace patterns
21
- const findAndReplace = ["FAUST_DSP_NAME", dspName];
22
- if (poly) findAndReplace.push("FAUST_DSP_VOICES = 0", "FAUST_DSP_VOICES = 16");
23
- if (poly && effect) findAndReplace.push("FAUST_DSP_HAS_EFFECT = false", "FAUST_DSP_HAS_EFFECT = true");
26
+ const findAndReplace = ['FAUST_DSP_NAME', dspName];
27
+ if (poly)
28
+ findAndReplace.push('FAUST_DSP_VOICES = 0', 'FAUST_DSP_VOICES = 16');
29
+ if (poly && effect)
30
+ findAndReplace.push(
31
+ 'FAUST_DSP_HAS_EFFECT = false',
32
+ 'FAUST_DSP_HAS_EFFECT = true'
33
+ );
24
34
 
25
35
  // Copy some files
26
- const createNodeJSPath = path.join(__dirname, "../assets/standalone/create-node.js");
27
- cpSyncModify(createNodeJSPath, outputDir + `/create-node.js`, ...findAndReplace);
28
-
29
- const templateJSPath = path.join(__dirname, "../assets/standalone/index.js");
36
+ const createNodeJSPath = path.join(
37
+ __dirname,
38
+ '../assets/standalone/create-node.js'
39
+ );
40
+ cpSyncModify(
41
+ createNodeJSPath,
42
+ outputDir + `/create-node.js`,
43
+ ...findAndReplace
44
+ );
45
+
46
+ const templateJSPath = path.join(
47
+ __dirname,
48
+ '../assets/standalone/index.js'
49
+ );
30
50
  cpSyncModify(templateJSPath, outputDir + `/index.js`, ...findAndReplace);
31
51
 
32
- const templateHTMLPath = path.join(__dirname, "../assets/standalone/index.html");
33
- cpSyncModify(templateHTMLPath, outputDir + `/index.html`, ...findAndReplace);
34
-
35
- const templateWorkerPath = path.join(__dirname, "../assets/standalone/service-worker.js");
36
- cpSyncModify(templateWorkerPath, outputDir + `/service-worker.js`, ...findAndReplace);
37
-
38
- const templateIconPath = path.join(__dirname, "../assets/standalone/icon.png");
52
+ const templateHTMLPath = path.join(
53
+ __dirname,
54
+ '../assets/standalone/index.html'
55
+ );
56
+ cpSyncModify(
57
+ templateHTMLPath,
58
+ outputDir + `/index.html`,
59
+ ...findAndReplace
60
+ );
61
+
62
+ const templateWorkerPath = path.join(
63
+ __dirname,
64
+ '../assets/standalone/service-worker.js'
65
+ );
66
+ cpSyncModify(
67
+ templateWorkerPath,
68
+ outputDir + `/service-worker.js`,
69
+ ...findAndReplace
70
+ );
71
+
72
+ const templateIconPath = path.join(
73
+ __dirname,
74
+ '../assets/standalone/icon.png'
75
+ );
39
76
  cpSync(templateIconPath, outputDir + `/icon.png`);
40
77
 
41
- const faustwasmPath = path.join(__dirname, "../assets/standalone/faustwasm");
42
- cpSync(faustwasmPath, outputDir + "/faustwasm");
43
-
44
- const faustuiPath = path.join(__dirname, "../assets/standalone/faust-ui");
45
- cpSync(faustuiPath, outputDir + "/faust-ui");
46
-
47
- const templateManifestPath = path.join(__dirname, "../assets/standalone/manifest.json");
48
- cpSyncModify(templateManifestPath, outputDir + `/manifest.json`, ...findAndReplace);
78
+ const faustwasmPath = path.join(
79
+ __dirname,
80
+ '../assets/standalone/faustwasm'
81
+ );
82
+ cpSync(faustwasmPath, outputDir + '/faustwasm');
83
+
84
+ const faustuiPath = path.join(__dirname, '../assets/standalone/faust-ui');
85
+ cpSync(faustuiPath, outputDir + '/faust-ui');
86
+
87
+ const templateManifestPath = path.join(
88
+ __dirname,
89
+ '../assets/standalone/manifest.json'
90
+ );
91
+ cpSyncModify(
92
+ templateManifestPath,
93
+ outputDir + `/manifest.json`,
94
+ ...findAndReplace
95
+ );
49
96
  };
50
97
 
51
98
  /**
@@ -55,51 +102,102 @@ const copyWebStandaloneAssets = (outputDir, dspName, poly = false, effect = fals
55
102
  * @param {boolean} [effect] - Whether the DSP has an effect module.
56
103
  */
57
104
  const copyWebPWAAssets = (outputDir, dspName, poly = false, effect = false) => {
58
- console.log(`Writing assets files.`)
105
+ console.log(`Writing assets files.`);
59
106
  if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
60
107
 
61
108
  // Generate VERSION_DATE
62
109
  const now = new Date();
63
- const VERSION_DATE = now.getFullYear().toString() +
64
- ("0" + (now.getMonth() + 1)).slice(-2) +
65
- ("0" + now.getDate()).slice(-2) + "-" +
66
- ("0" + now.getHours()).slice(-2) +
67
- ("0" + now.getMinutes()).slice(-2);
110
+ const VERSION_DATE =
111
+ now.getFullYear().toString() +
112
+ ('0' + (now.getMonth() + 1)).slice(-2) +
113
+ ('0' + now.getDate()).slice(-2) +
114
+ '-' +
115
+ ('0' + now.getHours()).slice(-2) +
116
+ ('0' + now.getMinutes()).slice(-2);
68
117
 
69
118
  // Define find and replace patterns
70
- const findAndReplace = ["FAUST_DSP_NAME", dspName];
71
- findAndReplace.push("VERSION_DATE", VERSION_DATE);
119
+ const findAndReplace = ['FAUST_DSP_NAME', dspName];
120
+ findAndReplace.push('VERSION_DATE', VERSION_DATE);
72
121
 
73
- if (poly) findAndReplace.push("FAUST_DSP_VOICES = 0", "FAUST_DSP_VOICES = 16");
74
- if (poly && effect) findAndReplace.push("FAUST_DSP_HAS_EFFECT = false", "FAUST_DSP_HAS_EFFECT = true");
122
+ if (poly)
123
+ findAndReplace.push('FAUST_DSP_VOICES = 0', 'FAUST_DSP_VOICES = 16');
124
+ if (poly && effect)
125
+ findAndReplace.push(
126
+ 'FAUST_DSP_HAS_EFFECT = false',
127
+ 'FAUST_DSP_HAS_EFFECT = true'
128
+ );
75
129
 
76
130
  // Copy some files
77
- const createNodeJSPath = path.join(__dirname, "../assets/standalone/create-node.js");
78
- cpSyncModify(createNodeJSPath, outputDir + `/create-node.js`, ...findAndReplace);
79
-
80
- const templateJSPath = path.join(__dirname, "../assets/standalone/index-pwa.js");
131
+ const createNodeJSPath = path.join(
132
+ __dirname,
133
+ '../assets/standalone/create-node.js'
134
+ );
135
+ cpSyncModify(
136
+ createNodeJSPath,
137
+ outputDir + `/create-node.js`,
138
+ ...findAndReplace
139
+ );
140
+
141
+ const templateJSPath = path.join(
142
+ __dirname,
143
+ '../assets/standalone/index-pwa.js'
144
+ );
81
145
  cpSyncModify(templateJSPath, outputDir + `/index.js`, ...findAndReplace);
82
146
 
83
- const templatePWAJSPath = path.join(__dirname, "../assets/standalone/faust-pwa.js");
84
- cpSyncModify(templatePWAJSPath, outputDir + `/faust-pwa.js`, ...findAndReplace);
85
-
86
- const templateHTMLPath = path.join(__dirname, "../assets/standalone/index-pwa.html");
87
- cpSyncModify(templateHTMLPath, outputDir + `/index.html`, ...findAndReplace);
88
-
89
- const templateWorkerPath = path.join(__dirname, "../assets/standalone/service-worker.js");
90
- cpSyncModify(templateWorkerPath, outputDir + `/service-worker.js`, ...findAndReplace);
91
-
92
- const templateIconPath = path.join(__dirname, "../assets/standalone/icon.png");
147
+ const templatePWAJSPath = path.join(
148
+ __dirname,
149
+ '../assets/standalone/faust-pwa.js'
150
+ );
151
+ cpSyncModify(
152
+ templatePWAJSPath,
153
+ outputDir + `/faust-pwa.js`,
154
+ ...findAndReplace
155
+ );
156
+
157
+ const templateHTMLPath = path.join(
158
+ __dirname,
159
+ '../assets/standalone/index-pwa.html'
160
+ );
161
+ cpSyncModify(
162
+ templateHTMLPath,
163
+ outputDir + `/index.html`,
164
+ ...findAndReplace
165
+ );
166
+
167
+ const templateWorkerPath = path.join(
168
+ __dirname,
169
+ '../assets/standalone/service-worker.js'
170
+ );
171
+ cpSyncModify(
172
+ templateWorkerPath,
173
+ outputDir + `/service-worker.js`,
174
+ ...findAndReplace
175
+ );
176
+
177
+ const templateIconPath = path.join(
178
+ __dirname,
179
+ '../assets/standalone/icon.png'
180
+ );
93
181
  cpSync(templateIconPath, outputDir + `/icon.png`);
94
182
 
95
- const faustwasmPath = path.join(__dirname, "../assets/standalone/faustwasm");
96
- cpSync(faustwasmPath, outputDir + "/faustwasm");
97
-
98
- const faustuiPath = path.join(__dirname, "../assets/standalone/faust-ui");
99
- cpSync(faustuiPath, outputDir + "/faust-ui");
100
-
101
- const templateManifestPath = path.join(__dirname, "../assets/standalone/manifest.json");
102
- cpSyncModify(templateManifestPath, outputDir + `/manifest.json`, ...findAndReplace);
183
+ const faustwasmPath = path.join(
184
+ __dirname,
185
+ '../assets/standalone/faustwasm'
186
+ );
187
+ cpSync(faustwasmPath, outputDir + '/faustwasm');
188
+
189
+ const faustuiPath = path.join(__dirname, '../assets/standalone/faust-ui');
190
+ cpSync(faustuiPath, outputDir + '/faust-ui');
191
+
192
+ const templateManifestPath = path.join(
193
+ __dirname,
194
+ '../assets/standalone/manifest.json'
195
+ );
196
+ cpSyncModify(
197
+ templateManifestPath,
198
+ outputDir + `/manifest.json`,
199
+ ...findAndReplace
200
+ );
103
201
  };
104
202
  /**
105
203
  * @param {string} outputDir - The output directory.
@@ -107,30 +205,60 @@ const copyWebPWAAssets = (outputDir, dspName, poly = false, effect = false) => {
107
205
  * @param {boolean} [poly] - Whether the DSP is polyphonic.
108
206
  * @param {boolean} [effect] - Whether the DSP has an effect module.
109
207
  */
110
- const copyWebTemplateAssets = (outputDir, dspName, poly = false, effect = false) => {
111
-
208
+ const copyWebTemplateAssets = (
209
+ outputDir,
210
+ dspName,
211
+ poly = false,
212
+ effect = false
213
+ ) => {
112
214
  // Create output directory if it doesn't exist
113
215
  if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
114
216
 
115
217
  // Define find and replace patterns
116
- const findAndReplace = ["FAUST_DSP_NAME", dspName];
218
+ const findAndReplace = ['FAUST_DSP_NAME', dspName];
117
219
 
118
- if (poly) findAndReplace.push("FAUST_DSP_VOICES = 0", "FAUST_DSP_VOICES = 16");
119
- if (poly && effect) findAndReplace.push("FAUST_DSP_HAS_EFFECT = false", "FAUST_DSP_HAS_EFFECT = true");
220
+ if (poly)
221
+ findAndReplace.push('FAUST_DSP_VOICES = 0', 'FAUST_DSP_VOICES = 16');
222
+ if (poly && effect)
223
+ findAndReplace.push(
224
+ 'FAUST_DSP_HAS_EFFECT = false',
225
+ 'FAUST_DSP_HAS_EFFECT = true'
226
+ );
120
227
 
121
228
  // Copy some files
122
- const createNodeJSPath = path.join(__dirname, "../assets/standalone/create-node.js");
123
- cpSyncModify(createNodeJSPath, outputDir + `/create-node.js`, ...findAndReplace);
124
-
125
- const templateJSPath = path.join(__dirname, "../assets/standalone/index-template.js");
229
+ const createNodeJSPath = path.join(
230
+ __dirname,
231
+ '../assets/standalone/create-node.js'
232
+ );
233
+ cpSyncModify(
234
+ createNodeJSPath,
235
+ outputDir + `/create-node.js`,
236
+ ...findAndReplace
237
+ );
238
+
239
+ const templateJSPath = path.join(
240
+ __dirname,
241
+ '../assets/standalone/index-template.js'
242
+ );
126
243
  cpSyncModify(templateJSPath, outputDir + `/index.js`, ...findAndReplace);
127
244
 
128
- const templateHTMLPath = path.join(__dirname, "../assets/standalone/index-template.html");
129
- cpSyncModify(templateHTMLPath, outputDir + `/index.html`, "index-template.js", "index.js", ...findAndReplace);
130
-
131
- const faustwasmPath = path.join(__dirname, "../assets/standalone/faustwasm");
132
- cpSync(faustwasmPath, outputDir + "/faustwasm");
245
+ const templateHTMLPath = path.join(
246
+ __dirname,
247
+ '../assets/standalone/index-template.html'
248
+ );
249
+ cpSyncModify(
250
+ templateHTMLPath,
251
+ outputDir + `/index.html`,
252
+ 'index-template.js',
253
+ 'index.js',
254
+ ...findAndReplace
255
+ );
256
+
257
+ const faustwasmPath = path.join(
258
+ __dirname,
259
+ '../assets/standalone/faustwasm'
260
+ );
261
+ cpSync(faustwasmPath, outputDir + '/faustwasm');
133
262
  };
134
263
 
135
264
  export { copyWebStandaloneAssets, copyWebPWAAssets, copyWebTemplateAssets };
136
-
@@ -1,5 +1,5 @@
1
- export { default as instantiateFaustModule } from "./instantiateFaustModule";
2
-
3
- export * from "./instantiateFaustModule";
4
-
5
- export * from "./exports";
1
+ export { default as instantiateFaustModule } from './instantiateFaustModule';
2
+
3
+ export * from './instantiateFaustModule';
4
+
5
+ export * from './exports';
package/src/exports.ts CHANGED
@@ -1,26 +1,26 @@
1
- export { default as instantiateFaustModuleFromFile } from "./instantiateFaustModuleFromFile";
2
- export { default as getFaustAudioWorkletProcessor } from "./FaustAudioWorkletProcessor";
3
- export { default as getFaustFFTAudioWorkletProcessor } from "./FaustFFTAudioWorkletProcessor";
4
- export { default as FaustCompiler } from "./FaustCompiler";
5
- export { FaustDspInstance } from "./FaustDspInstance";
6
- export { default as FaustWasmInstantiator } from "./FaustWasmInstantiator";
7
- export { default as FaustOfflineProcessor } from "./FaustOfflineProcessor";
8
- export { default as FaustSvgDiagrams } from "./FaustSvgDiagrams";
9
- export { default as FaustCmajor } from "./FaustCmajor";
10
- export { default as LibFaust } from "./LibFaust";
11
- export { default as WavEncoder } from "./WavEncoder";
12
- export { default as WavDecoder } from "./WavDecoder";
13
- export { default as SoundfileReader } from "./SoundfileReader";
1
+ export { default as instantiateFaustModuleFromFile } from './instantiateFaustModuleFromFile';
2
+ export { default as getFaustAudioWorkletProcessor } from './FaustAudioWorkletProcessor';
3
+ export { default as getFaustFFTAudioWorkletProcessor } from './FaustFFTAudioWorkletProcessor';
4
+ export { default as FaustCompiler } from './FaustCompiler';
5
+ export { FaustDspInstance } from './FaustDspInstance';
6
+ export { default as FaustWasmInstantiator } from './FaustWasmInstantiator';
7
+ export { default as FaustOfflineProcessor } from './FaustOfflineProcessor';
8
+ export { default as FaustSvgDiagrams } from './FaustSvgDiagrams';
9
+ export { default as FaustCmajor } from './FaustCmajor';
10
+ export { default as LibFaust } from './LibFaust';
11
+ export { default as WavEncoder } from './WavEncoder';
12
+ export { default as WavDecoder } from './WavDecoder';
13
+ export { default as SoundfileReader } from './SoundfileReader';
14
14
 
15
- export * from "./FaustAudioWorkletNode";
16
- export * from "./FaustAudioWorkletProcessor";
17
- export * from "./FaustFFTAudioWorkletProcessor";
18
- export * from "./FaustCompiler";
19
- export * from "./FaustDspInstance";
20
- export * from "./FaustOfflineProcessor";
21
- export * from "./FaustScriptProcessorNode";
22
- export * from "./FaustWebAudioDsp";
23
- export * from "./FaustDspGenerator";
24
- export * from "./LibFaust";
15
+ export * from './FaustAudioWorkletNode';
16
+ export * from './FaustAudioWorkletProcessor';
17
+ export * from './FaustFFTAudioWorkletProcessor';
18
+ export * from './FaustCompiler';
19
+ export * from './FaustDspInstance';
20
+ export * from './FaustOfflineProcessor';
21
+ export * from './FaustScriptProcessorNode';
22
+ export * from './FaustWebAudioDsp';
23
+ export * from './FaustDspGenerator';
24
+ export * from './LibFaust';
25
25
 
26
- export * from "./types";
26
+ export * from './types';
@@ -1,3 +1,7 @@
1
- declare const faust2CmajorFiles: (inputFile: string, outputDir: string, argv?: string[]) => Promise<string>;
2
-
3
- export default faust2CmajorFiles;
1
+ declare const faust2CmajorFiles: (
2
+ inputFile: string,
3
+ outputDir: string,
4
+ argv?: string[]
5
+ ) => Promise<string>;
6
+
7
+ export default faust2CmajorFiles;
@@ -1,13 +1,13 @@
1
1
  //@ts-check
2
- import * as fs from "fs";
3
- import * as path from "path";
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
4
  import {
5
5
  instantiateFaustModuleFromFile,
6
6
  LibFaust,
7
7
  FaustCompiler,
8
8
  FaustCmajor
9
- } from "../dist/esm/index.js";
10
- import { fileURLToPath } from "url";
9
+ } from '../dist/esm/index.js';
10
+ import { fileURLToPath } from 'url';
11
11
 
12
12
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
13
13
  const __filename = fileURLToPath(import.meta.url);
@@ -18,16 +18,18 @@ const __filename = fileURLToPath(import.meta.url);
18
18
  * @param {string[]} [argv]
19
19
  */
20
20
  const faust2CmajorFiles = async (inputFile, outputDir, argv = []) => {
21
- const faustModule = await instantiateFaustModuleFromFile(path.join(__dirname, "../libfaust-wasm/libfaust-wasm.js"));
21
+ const faustModule = await instantiateFaustModuleFromFile(
22
+ path.join(__dirname, '../libfaust-wasm/libfaust-wasm.js')
23
+ );
22
24
  const libFaust = new LibFaust(faustModule);
23
25
  const compiler = new FaustCompiler(libFaust);
24
26
  console.log(`Faust Compiler version: ${compiler.version()}`);
25
27
  console.log(`Reading file ${inputFile}`);
26
- const code = fs.readFileSync(inputFile, { encoding: "utf8" });
28
+ const code = fs.readFileSync(inputFile, { encoding: 'utf8' });
27
29
  const { name } = path.parse(inputFile);
28
30
  const cmajor = new FaustCmajor(compiler);
29
- if (!argv.find(a => a === "-I")) argv.push("-I", "libraries/");
30
- const cmajor_file = cmajor.compile(name, code, argv.join(" "));
31
+ if (!argv.find((a) => a === '-I')) argv.push('-I', 'libraries/');
32
+ const cmajor_file = cmajor.compile(name, code, argv.join(' '));
31
33
  console.log(`Writing files to ${outputDir}`);
32
34
  if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
33
35
  const cmajorPath = path.join(outputDir, `${name}.cmajor`);
@@ -1,3 +1,7 @@
1
- declare const faust2svgFiles: (inputFile: string, outputDir: string, argv?: string[]) => Promise<Record<string, string>>;
2
-
3
- export default faust2svgFiles;
1
+ declare const faust2svgFiles: (
2
+ inputFile: string,
3
+ outputDir: string,
4
+ argv?: string[]
5
+ ) => Promise<Record<string, string>>;
6
+
7
+ export default faust2svgFiles;
@@ -1,13 +1,13 @@
1
1
  //@ts-check
2
- import * as fs from "fs";
3
- import * as path from "path";
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
4
  import {
5
5
  instantiateFaustModuleFromFile,
6
6
  LibFaust,
7
7
  FaustCompiler,
8
8
  FaustSvgDiagrams
9
- } from "../dist/esm/index.js";
10
- import { fileURLToPath } from "url";
9
+ } from '../dist/esm/index.js';
10
+ import { fileURLToPath } from 'url';
11
11
 
12
12
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
13
13
  const __filename = fileURLToPath(import.meta.url);
@@ -18,15 +18,17 @@ const __filename = fileURLToPath(import.meta.url);
18
18
  * @param {string[]} [argv]
19
19
  */
20
20
  const faust2svgFiles = async (inputFile, outputDir, argv = []) => {
21
- const faustModule = await instantiateFaustModuleFromFile(path.join(__dirname, "../libfaust-wasm/libfaust-wasm.js"));
21
+ const faustModule = await instantiateFaustModuleFromFile(
22
+ path.join(__dirname, '../libfaust-wasm/libfaust-wasm.js')
23
+ );
22
24
  const libFaust = new LibFaust(faustModule);
23
25
  const compiler = new FaustCompiler(libFaust);
24
26
  console.log(`Faust Compiler version: ${compiler.version()}`);
25
27
  console.log(`Reading file ${inputFile}`);
26
- const code = fs.readFileSync(inputFile, { encoding: "utf8" });
28
+ const code = fs.readFileSync(inputFile, { encoding: 'utf8' });
27
29
  const { name } = path.parse(inputFile);
28
30
  const diagram = new FaustSvgDiagrams(compiler);
29
- const svgs = diagram.from(name, code, argv.join(" "));
31
+ const svgs = diagram.from(name, code, argv.join(' '));
30
32
  console.log(`Generated ${Object.keys(svgs).length} files.`);
31
33
  console.log(`Writing files to ${outputDir}`);
32
34
  if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
@@ -1,5 +1,10 @@
1
- import { FaustDspMeta } from "./types";
2
-
3
- declare const faust2wasmFiles: (inputFile: string, outputDir: string, argv?: string[], poly?: boolean) => Promise<{ dspMeta: FaustDspMeta; effectMeta: FaustDspMeta | null }>;
4
-
5
- export default faust2wasmFiles;
1
+ import { FaustDspMeta } from './types';
2
+
3
+ declare const faust2wasmFiles: (
4
+ inputFile: string,
5
+ outputDir: string,
6
+ argv?: string[],
7
+ poly?: boolean
8
+ ) => Promise<{ dspMeta: FaustDspMeta; effectMeta: FaustDspMeta | null }>;
9
+
10
+ export default faust2wasmFiles;
@@ -1,43 +1,50 @@
1
1
  //@ts-check
2
- import * as fs from "fs";
3
- import * as path from "path";
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
4
  import {
5
5
  instantiateFaustModuleFromFile,
6
6
  LibFaust,
7
7
  FaustCompiler,
8
8
  FaustMonoDspGenerator,
9
9
  FaustPolyDspGenerator
10
- } from "../dist/esm/index.js";
11
- import { fileURLToPath } from "url";
10
+ } from '../dist/esm/index.js';
11
+ import { fileURLToPath } from 'url';
12
12
 
13
13
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
14
14
  const __filename = fileURLToPath(import.meta.url);
15
15
 
16
16
  /**
17
17
  * Script to compile a Faust DSP file to WebAssembly and write the output to files.
18
- *
18
+ *
19
19
  * @param {string} inputFile : The path to the Faust DSP file.
20
20
  * @param {string} outputDir : The path to the output directory.
21
21
  * @param {string[]} [argv] : An array of command-line arguments to pass to the Faust compiler.
22
22
  * @param {boolean} [poly] : Whether to compile the DSP as a polyphonic instrument.
23
23
  */
24
- const faust2wasmFiles = async (inputFile, outputDir, argv = [], poly = false) => {
25
- const faustModule = await instantiateFaustModuleFromFile(path.join(__dirname, "../libfaust-wasm/libfaust-wasm.js"));
24
+ const faust2wasmFiles = async (
25
+ inputFile,
26
+ outputDir,
27
+ argv = [],
28
+ poly = false
29
+ ) => {
30
+ const faustModule = await instantiateFaustModuleFromFile(
31
+ path.join(__dirname, '../libfaust-wasm/libfaust-wasm.js')
32
+ );
26
33
  const libFaust = new LibFaust(faustModule);
27
34
  const compiler = new FaustCompiler(libFaust);
28
35
  console.log(`Faust Compiler version: ${compiler.version()}`);
29
36
  console.log(`Reading file ${inputFile}`);
30
- const code = fs.readFileSync(inputFile, { encoding: "utf8" });
37
+ const code = fs.readFileSync(inputFile, { encoding: 'utf8' });
31
38
 
32
- const fileName = /** @type {string} */(inputFile.split('/').pop());
39
+ const fileName = /** @type {string} */ (inputFile.split('/').pop());
33
40
  const dspName = fileName.replace(/\.dsp$/, '');
34
41
  // Flush to zero to avoid costly denormalized numbers
35
- argv.push("-ftz", "2");
42
+ argv.push('-ftz', '2');
36
43
  const dspModulePath = path.join(outputDir, `dsp-module.wasm`);
37
44
  const dspMetaPath = path.join(outputDir, `dsp-meta.json`);
38
45
  const effectModulePath = path.join(outputDir, `effect-module.wasm`);
39
46
  const effectMetaPath = path.join(outputDir, `effect-meta.json`);
40
- const mixerModulePath = path.join(outputDir, "mixer-module.wasm");
47
+ const mixerModulePath = path.join(outputDir, 'mixer-module.wasm');
41
48
  /** @type {Uint8Array} */
42
49
  let dspModule;
43
50
  /** @type {import("./types").FaustDspMeta} */
@@ -52,10 +59,15 @@ const faust2wasmFiles = async (inputFile, outputDir, argv = [], poly = false) =>
52
59
  if (poly) {
53
60
  const generator = new FaustPolyDspGenerator();
54
61
  const t1 = Date.now();
55
- const dsp = await generator.compile(compiler, name, code, argv.join(" "));
56
- if (!dsp) throw new Error("Faust DSP not compiled");
62
+ const dsp = await generator.compile(
63
+ compiler,
64
+ name,
65
+ code,
66
+ argv.join(' ')
67
+ );
68
+ if (!dsp) throw new Error('Faust DSP not compiled');
57
69
  const { voiceFactory, effectFactory, mixerBuffer } = dsp;
58
- if (!voiceFactory) throw new Error("Faust DSP Factory not compiled");
70
+ if (!voiceFactory) throw new Error('Faust DSP Factory not compiled');
59
71
  console.log(`Compilation successful (${Date.now() - t1} ms).`);
60
72
  dspModule = voiceFactory.code;
61
73
  dspMeta = JSON.parse(voiceFactory.json);
@@ -67,10 +79,15 @@ const faust2wasmFiles = async (inputFile, outputDir, argv = [], poly = false) =>
67
79
  } else {
68
80
  const generator = new FaustMonoDspGenerator();
69
81
  const t1 = Date.now();
70
- const dsp = await generator.compile(compiler, name, code, argv.join(" "));
71
- if (!dsp) throw new Error("Faust DSP not compiled");
82
+ const dsp = await generator.compile(
83
+ compiler,
84
+ name,
85
+ code,
86
+ argv.join(' ')
87
+ );
88
+ if (!dsp) throw new Error('Faust DSP not compiled');
72
89
  const { factory } = dsp;
73
- if (!factory) throw new Error("Faust DSP Factory not compiled");
90
+ if (!factory) throw new Error('Faust DSP Factory not compiled');
74
91
  console.log(`Compilation successful (${Date.now() - t1} ms).`);
75
92
  dspModule = factory.code;
76
93
  dspMeta = JSON.parse(factory.json);
@@ -1,3 +1,12 @@
1
- declare const faust2wavFiles: (inputFile: string, inputWav: string, outputWav: string, bufferSize?: number, sampleRate?: number, samples?: number, bitDepth?: number, argv?: string[]) => Promise<void>;
2
-
3
- export default faust2wavFiles;
1
+ declare const faust2wavFiles: (
2
+ inputFile: string,
3
+ inputWav: string,
4
+ outputWav: string,
5
+ bufferSize?: number,
6
+ sampleRate?: number,
7
+ samples?: number,
8
+ bitDepth?: number,
9
+ argv?: string[]
10
+ ) => Promise<void>;
11
+
12
+ export default faust2wavFiles;