@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.
- package/.prettierrc +5 -0
- package/README.md +21 -3
- package/assets/standalone/faustwasm/index.d.ts +38 -16
- package/assets/standalone/faustwasm/index.js +1574 -404
- package/assets/standalone/faustwasm/index.js.map +2 -2
- package/dist/cjs/index.d.ts +38 -16
- package/dist/cjs/index.js +1573 -404
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs-bundle/index.d.ts +38 -16
- package/dist/cjs-bundle/index.js +1576 -406
- package/dist/cjs-bundle/index.js.map +2 -2
- package/dist/esm/index.d.ts +38 -16
- package/dist/esm/index.js +1574 -404
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/index.d.ts +38 -16
- package/dist/esm-bundle/index.js +1576 -406
- package/dist/esm-bundle/index.js.map +2 -2
- package/eslint.config.js +11 -0
- package/package.json +57 -51
- package/sound.cpp +163 -0
- package/sound.dsp +4 -0
- package/sound.json +1 -0
- package/sound.wasm +0 -0
- package/src/FaustAudioWorkletCommunicator.ts +150 -143
- package/src/FaustAudioWorkletNode.ts +173 -75
- package/src/FaustAudioWorkletProcessor.ts +218 -90
- package/src/FaustCmajor.ts +9 -3
- package/src/FaustCompiler.ts +112 -35
- package/src/FaustDspGenerator.ts +561 -117
- package/src/FaustDspInstance.ts +58 -24
- package/src/FaustFFTAudioWorkletProcessor.ts +822 -612
- package/src/FaustOfflineProcessor.ts +187 -56
- package/src/FaustScriptProcessorNode.ts +156 -49
- package/src/FaustSensors.ts +426 -96
- package/src/FaustSvgDiagrams.ts +18 -5
- package/src/FaustWasmInstantiator.ts +224 -70
- package/src/FaustWebAudioDsp.ts +1060 -349
- package/src/LibFaust.ts +13 -4
- package/src/SoundfileReader.ts +175 -131
- package/src/WavDecoder.ts +42 -20
- package/src/WavEncoder.ts +35 -21
- package/src/copyWebStandaloneAssets.d.ts +20 -5
- package/src/copyWebStandaloneAssets.js +203 -75
- package/src/exports-bundle.ts +5 -5
- package/src/exports.ts +24 -24
- package/src/faust2CmajorFiles.d.ts +7 -3
- package/src/faust2cmajorFiles.js +10 -8
- package/src/faust2svgFiles.d.ts +7 -3
- package/src/faust2svgFiles.js +9 -7
- package/src/faust2wasmFiles.d.ts +10 -5
- package/src/faust2wasmFiles.js +34 -17
- package/src/faust2wavFiles.d.ts +12 -3
- package/src/faust2wavFiles.js +25 -12
- package/src/index-bundle-iife.ts +2 -2
- package/src/index-bundle.ts +1 -1
- package/src/index.ts +1 -1
- package/src/instantiateFaustModule.ts +43 -36
- package/src/instantiateFaustModuleFromFile.ts +30 -14
- package/src/types.ts +101 -25
- package/test/faustlive-wasm/faustwasm/index.d.ts +38 -16
- package/test/faustlive-wasm/faustwasm/index.js +1574 -404
- package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
- package/test/web/create-faust-node.html +53 -0
- package/test/web/create-faust-node.js +186 -0
- package/test/organ/create-node.js +0 -252
- package/test/organ/dsp-meta.json +0 -131
- package/test/organ/dsp-module.wasm +0 -0
- package/test/organ/faust-pwa.js +0 -344
- package/test/organ/faust-ui/index.css +0 -442
- package/test/organ/faust-ui/index.css.map +0 -1
- package/test/organ/faust-ui/index.d.ts +0 -1
- package/test/organ/faust-ui/index.js +0 -3756
- package/test/organ/faust-ui/index.js.map +0 -1
- package/test/organ/faustwasm/index.d.ts +0 -1705
- package/test/organ/faustwasm/index.js +0 -4773
- package/test/organ/faustwasm/index.js.map +0 -7
- package/test/organ/icon.png +0 -0
- package/test/organ/index.html +0 -76
- package/test/organ/index.js +0 -69
- package/test/organ/manifest.json +0 -17
- package/test/organ/service-worker.js +0 -165
package/src/FaustSvgDiagrams.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type FaustCompiler from
|
|
1
|
+
import type FaustCompiler from './FaustCompiler';
|
|
2
2
|
|
|
3
3
|
interface IFaustSvgDiagrams {
|
|
4
4
|
/**
|
|
@@ -23,13 +23,26 @@ class FaustSvgDiagrams implements IFaustSvgDiagrams {
|
|
|
23
23
|
const fs = this.compiler.fs();
|
|
24
24
|
try {
|
|
25
25
|
const files: string[] = fs.readdir(`/${name}-svg/`);
|
|
26
|
-
files
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
files
|
|
27
|
+
.filter((file) => file !== '.' && file !== '..')
|
|
28
|
+
.forEach((file) => fs.unlink(`/${name}-svg/${file}`));
|
|
29
|
+
} catch {}
|
|
30
|
+
const success = this.compiler.generateAuxFiles(
|
|
31
|
+
name,
|
|
32
|
+
code,
|
|
33
|
+
`-lang wasm -o binary -svg ${args}`
|
|
34
|
+
);
|
|
29
35
|
if (!success) throw new Error(this.compiler.getErrorMessage());
|
|
30
36
|
const svgs: Record<string, string> = {};
|
|
31
37
|
const files: string[] = fs.readdir(`/${name}-svg/`);
|
|
32
|
-
files
|
|
38
|
+
files
|
|
39
|
+
.filter((file) => file !== '.' && file !== '..')
|
|
40
|
+
.forEach(
|
|
41
|
+
(file) =>
|
|
42
|
+
(svgs[file] = fs.readFile(`/${name}-svg/${file}`, {
|
|
43
|
+
encoding: 'utf8'
|
|
44
|
+
}) as string)
|
|
45
|
+
);
|
|
33
46
|
return svgs;
|
|
34
47
|
}
|
|
35
48
|
}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
FaustDspInstance,
|
|
3
|
+
FaustMonoDspInstance,
|
|
4
|
+
FaustPolyDspInstance,
|
|
5
|
+
IFaustDspInstance,
|
|
6
|
+
IFaustMixerInstance
|
|
7
|
+
} from './FaustDspInstance';
|
|
8
|
+
import type {
|
|
9
|
+
FaustDspFactory,
|
|
10
|
+
FaustDspMeta,
|
|
11
|
+
LooseFaustDspFactory
|
|
12
|
+
} from './types';
|
|
3
13
|
|
|
4
14
|
class FaustWasmInstantiator {
|
|
5
15
|
private static createWasmImport(memory?: WebAssembly.Memory) {
|
|
@@ -11,92 +21,172 @@ class FaustWasmInstantiator {
|
|
|
11
21
|
// Integer version
|
|
12
22
|
_abs: Math.abs,
|
|
13
23
|
// Float version
|
|
14
|
-
_acosf: Math.acos,
|
|
15
|
-
|
|
24
|
+
_acosf: Math.acos,
|
|
25
|
+
_asinf: Math.asin,
|
|
26
|
+
_atanf: Math.atan,
|
|
27
|
+
_atan2f: Math.atan2,
|
|
28
|
+
_ceilf: Math.ceil,
|
|
29
|
+
_cosf: Math.cos,
|
|
30
|
+
_expf: Math.exp,
|
|
31
|
+
_floorf: Math.floor,
|
|
16
32
|
_fmodf: (x: number, y: number) => x % y,
|
|
17
|
-
_logf: Math.log,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
_logf: Math.log,
|
|
34
|
+
_log10f: Math.log10,
|
|
35
|
+
_max_f: Math.max,
|
|
36
|
+
_min_f: Math.min,
|
|
37
|
+
_remainderf: (x: number, y: number) =>
|
|
38
|
+
x - Math.round(x / y) * y,
|
|
39
|
+
_powf: Math.pow,
|
|
40
|
+
_roundf: Math.round,
|
|
41
|
+
_sinf: Math.sin,
|
|
42
|
+
_sqrtf: Math.sqrt,
|
|
43
|
+
_tanf: Math.tan,
|
|
44
|
+
_acoshf: Math.acosh,
|
|
45
|
+
_asinhf: Math.asinh,
|
|
46
|
+
_atanhf: Math.atanh,
|
|
47
|
+
_coshf: Math.cosh,
|
|
48
|
+
_sinhf: Math.sinh,
|
|
49
|
+
_tanhf: Math.tanh,
|
|
50
|
+
_isnanf: Number.isNaN,
|
|
51
|
+
_isinff: (x: number) => !isFinite(x),
|
|
52
|
+
_copysignf: (x: number, y: number) =>
|
|
53
|
+
Math.sign(x) === Math.sign(y) ? x : -x,
|
|
24
54
|
|
|
25
55
|
// Double version
|
|
26
|
-
_acos: Math.acos,
|
|
27
|
-
|
|
56
|
+
_acos: Math.acos,
|
|
57
|
+
_asin: Math.asin,
|
|
58
|
+
_atan: Math.atan,
|
|
59
|
+
_atan2: Math.atan2,
|
|
60
|
+
_ceil: Math.ceil,
|
|
61
|
+
_cos: Math.cos,
|
|
62
|
+
_exp: Math.exp,
|
|
63
|
+
_floor: Math.floor,
|
|
28
64
|
_fmod: (x: number, y: number) => x % y,
|
|
29
|
-
_log: Math.log,
|
|
65
|
+
_log: Math.log,
|
|
66
|
+
_log10: Math.log10,
|
|
67
|
+
_max_: Math.max,
|
|
68
|
+
_min_: Math.min,
|
|
30
69
|
_remainder: (x: number, y: number) => x - Math.round(x / y) * y,
|
|
31
|
-
_pow: Math.pow,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
70
|
+
_pow: Math.pow,
|
|
71
|
+
_round: Math.round,
|
|
72
|
+
_sin: Math.sin,
|
|
73
|
+
_sqrt: Math.sqrt,
|
|
74
|
+
_tan: Math.tan,
|
|
75
|
+
_acosh: Math.acosh,
|
|
76
|
+
_asinh: Math.asinh,
|
|
77
|
+
_atanh: Math.atanh,
|
|
78
|
+
_cosh: Math.cosh,
|
|
79
|
+
_sinh: Math.sinh,
|
|
80
|
+
_tanh: Math.tanh,
|
|
81
|
+
_isnan: Number.isNaN,
|
|
82
|
+
_isinf: (x: number) => !isFinite(x),
|
|
83
|
+
_copysign: (x: number, y: number) =>
|
|
84
|
+
Math.sign(x) === Math.sign(y) ? x : -x,
|
|
36
85
|
|
|
37
|
-
table: new WebAssembly.Table({ initial: 0, element:
|
|
86
|
+
table: new WebAssembly.Table({ initial: 0, element: 'anyfunc' })
|
|
38
87
|
}
|
|
39
88
|
};
|
|
40
89
|
}
|
|
41
|
-
private static createWasmMemoryPoly(
|
|
90
|
+
private static createWasmMemoryPoly(
|
|
91
|
+
voicesIn: number,
|
|
92
|
+
sampleSize: number,
|
|
93
|
+
dspMeta: FaustDspMeta,
|
|
94
|
+
effectMeta: FaustDspMeta,
|
|
95
|
+
bufferSize: number
|
|
96
|
+
) {
|
|
42
97
|
// Hack : at least 4 voices (to avoid weird wasm memory bug?)
|
|
43
98
|
const voices = Math.max(4, voicesIn);
|
|
44
99
|
// Memory allocator
|
|
45
100
|
const ptrSize = sampleSize; // Done on wast/wasm backend side
|
|
46
101
|
const pow2limit = (x: number) => {
|
|
47
102
|
let n = 65536; // Minimum = 64 kB
|
|
48
|
-
while (n < x) {
|
|
103
|
+
while (n < x) {
|
|
104
|
+
n *= 2;
|
|
105
|
+
}
|
|
49
106
|
return n;
|
|
50
107
|
};
|
|
51
108
|
const effectSize = effectMeta ? effectMeta.size : 0;
|
|
52
|
-
let memorySize =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
109
|
+
let memorySize =
|
|
110
|
+
pow2limit(
|
|
111
|
+
effectSize +
|
|
112
|
+
dspMeta.size * voices +
|
|
113
|
+
(dspMeta.inputs + dspMeta.outputs * 2) * // + 2 for effect
|
|
114
|
+
(ptrSize + bufferSize * sampleSize)
|
|
115
|
+
) / 65536;
|
|
58
116
|
memorySize = Math.max(2, memorySize); // At least 2
|
|
59
117
|
return new WebAssembly.Memory({ initial: memorySize });
|
|
60
|
-
}
|
|
118
|
+
}
|
|
61
119
|
|
|
62
|
-
private static createWasmMemoryMono(
|
|
120
|
+
private static createWasmMemoryMono(
|
|
121
|
+
sampleSize: number,
|
|
122
|
+
dspMeta: FaustDspMeta,
|
|
123
|
+
bufferSize: number
|
|
124
|
+
) {
|
|
63
125
|
// Memory allocator
|
|
64
126
|
const ptrSize = sampleSize; // Done on wast/wasm backend side
|
|
65
|
-
const memorySize =
|
|
127
|
+
const memorySize =
|
|
128
|
+
(dspMeta.size +
|
|
129
|
+
(dspMeta.inputs + dspMeta.outputs) *
|
|
130
|
+
(ptrSize + bufferSize * sampleSize)) /
|
|
131
|
+
65536;
|
|
66
132
|
return new WebAssembly.Memory({ initial: memorySize * 2 }); // Safer to have a bit more memory
|
|
67
133
|
}
|
|
68
134
|
|
|
69
|
-
private static createMonoDSPInstanceAux(
|
|
70
|
-
|
|
135
|
+
private static createMonoDSPInstanceAux(
|
|
136
|
+
instance: WebAssembly.Instance,
|
|
137
|
+
json: string,
|
|
138
|
+
mem: WebAssembly.Memory | null = null
|
|
139
|
+
) {
|
|
140
|
+
const functions = instance.exports as IFaustDspInstance &
|
|
141
|
+
WebAssembly.Exports;
|
|
71
142
|
const api = new FaustDspInstance(functions);
|
|
72
|
-
const memory: any =
|
|
143
|
+
const memory: any = mem ? mem : instance.exports.memory;
|
|
73
144
|
return { memory, api, json } as FaustMonoDspInstance;
|
|
74
145
|
}
|
|
75
146
|
|
|
76
147
|
private static createMemoryMono(monoFactory: LooseFaustDspFactory) {
|
|
77
148
|
// Parse JSON to get 'size' and 'inputs/outputs' infos
|
|
78
149
|
const monoMeta: FaustDspMeta = JSON.parse(monoFactory.json);
|
|
79
|
-
const sampleSize = monoMeta.compile_options.match(
|
|
150
|
+
const sampleSize = monoMeta.compile_options.match('-double') ? 8 : 4;
|
|
80
151
|
return this.createWasmMemoryMono(sampleSize, monoMeta, 8192);
|
|
81
|
-
|
|
82
152
|
}
|
|
83
|
-
private static createMemoryPoly(
|
|
153
|
+
private static createMemoryPoly(
|
|
154
|
+
voices: number,
|
|
155
|
+
voiceFactory: LooseFaustDspFactory,
|
|
156
|
+
effectFactory?: LooseFaustDspFactory
|
|
157
|
+
) {
|
|
84
158
|
// Parse JSON to get 'size' and 'inputs/outputs' infos
|
|
85
159
|
const voiceMeta: FaustDspMeta = JSON.parse(voiceFactory.json);
|
|
86
|
-
const effectMeta: FaustDspMeta =
|
|
87
|
-
|
|
160
|
+
const effectMeta: FaustDspMeta =
|
|
161
|
+
effectFactory && effectFactory.json
|
|
162
|
+
? JSON.parse(effectFactory.json)
|
|
163
|
+
: null;
|
|
164
|
+
const sampleSize = voiceMeta.compile_options.match('-double') ? 8 : 4;
|
|
88
165
|
// Memory will be shared by voice, mixer and (possibly) effect instances
|
|
89
|
-
return this.createWasmMemoryPoly(
|
|
166
|
+
return this.createWasmMemoryPoly(
|
|
167
|
+
voices,
|
|
168
|
+
sampleSize,
|
|
169
|
+
voiceMeta,
|
|
170
|
+
effectMeta,
|
|
171
|
+
8192
|
|
172
|
+
);
|
|
90
173
|
}
|
|
91
174
|
|
|
92
|
-
private static createMixerAux(
|
|
175
|
+
private static createMixerAux(
|
|
176
|
+
mixerModule: WebAssembly.Module,
|
|
177
|
+
memory: WebAssembly.Memory
|
|
178
|
+
) {
|
|
93
179
|
// Create mixer instance
|
|
94
180
|
const mixerImport = {
|
|
95
181
|
imports: { print: console.log },
|
|
96
182
|
memory: { memory }
|
|
97
183
|
};
|
|
98
|
-
const mixerInstance = new WebAssembly.Instance(
|
|
99
|
-
|
|
184
|
+
const mixerInstance = new WebAssembly.Instance(
|
|
185
|
+
mixerModule,
|
|
186
|
+
mixerImport
|
|
187
|
+
);
|
|
188
|
+
const mixerFunctions = mixerInstance.exports as IFaustMixerInstance &
|
|
189
|
+
WebAssembly.Exports;
|
|
100
190
|
return mixerFunctions;
|
|
101
191
|
}
|
|
102
192
|
|
|
@@ -104,7 +194,9 @@ class FaustWasmInstantiator {
|
|
|
104
194
|
static async loadDSPFactory(wasmPath: string, jsonPath: string) {
|
|
105
195
|
const wasmFile = await fetch(wasmPath);
|
|
106
196
|
if (!wasmFile.ok) {
|
|
107
|
-
throw new Error(
|
|
197
|
+
throw new Error(
|
|
198
|
+
`=> exception raised while running loadDSPFactory, file not found: ${wasmPath}`
|
|
199
|
+
);
|
|
108
200
|
}
|
|
109
201
|
try {
|
|
110
202
|
const wasmBuffer = await wasmFile.arrayBuffer();
|
|
@@ -114,7 +206,13 @@ class FaustWasmInstantiator {
|
|
|
114
206
|
const meta: FaustDspMeta = JSON.parse(json);
|
|
115
207
|
const cOptions = meta.compile_options;
|
|
116
208
|
const poly = cOptions.indexOf('wasm-e') !== -1;
|
|
117
|
-
return {
|
|
209
|
+
return {
|
|
210
|
+
cfactory: 0,
|
|
211
|
+
code: new Uint8Array(wasmBuffer),
|
|
212
|
+
module,
|
|
213
|
+
json,
|
|
214
|
+
poly
|
|
215
|
+
} as FaustDspFactory;
|
|
118
216
|
} catch (e) {
|
|
119
217
|
// console.error(`=> exception raised while running loadDSPFactory: ${e}`);
|
|
120
218
|
throw e;
|
|
@@ -125,7 +223,9 @@ class FaustWasmInstantiator {
|
|
|
125
223
|
try {
|
|
126
224
|
let mixerBuffer: BufferSource | null = null;
|
|
127
225
|
if (fs) {
|
|
128
|
-
mixerBuffer = new Uint8Array(
|
|
226
|
+
mixerBuffer = new Uint8Array(
|
|
227
|
+
fs.readFile(mixerPath, { encoding: 'binary' })
|
|
228
|
+
);
|
|
129
229
|
} else {
|
|
130
230
|
const mixerFile = await fetch(mixerPath);
|
|
131
231
|
mixerBuffer = await mixerFile.arrayBuffer();
|
|
@@ -139,7 +239,6 @@ class FaustWasmInstantiator {
|
|
|
139
239
|
}
|
|
140
240
|
|
|
141
241
|
static async createAsyncMonoDSPInstance(factory: LooseFaustDspFactory) {
|
|
142
|
-
|
|
143
242
|
// Regular expression to match the 'type: soundfile' pattern
|
|
144
243
|
const pattern = /"type":\s*"soundfile"/;
|
|
145
244
|
// Check if the pattern exists in the JSON string
|
|
@@ -147,17 +246,26 @@ class FaustWasmInstantiator {
|
|
|
147
246
|
|
|
148
247
|
if (isDetected) {
|
|
149
248
|
const memory = this.createMemoryMono(factory);
|
|
150
|
-
const instance = await WebAssembly.instantiate(
|
|
151
|
-
|
|
249
|
+
const instance = await WebAssembly.instantiate(
|
|
250
|
+
factory.module,
|
|
251
|
+
this.createWasmImport(memory)
|
|
252
|
+
);
|
|
253
|
+
return this.createMonoDSPInstanceAux(
|
|
254
|
+
instance,
|
|
255
|
+
factory.json,
|
|
256
|
+
memory
|
|
257
|
+
);
|
|
152
258
|
} else {
|
|
153
259
|
// Otherwise, we can create the instance using the wasm internal memory allocated by the wasm module
|
|
154
|
-
const instance = await WebAssembly.instantiate(
|
|
260
|
+
const instance = await WebAssembly.instantiate(
|
|
261
|
+
factory.module,
|
|
262
|
+
this.createWasmImport()
|
|
263
|
+
);
|
|
155
264
|
return this.createMonoDSPInstanceAux(instance, factory.json);
|
|
156
265
|
}
|
|
157
266
|
}
|
|
158
267
|
|
|
159
268
|
static createSyncMonoDSPInstance(factory: LooseFaustDspFactory) {
|
|
160
|
-
|
|
161
269
|
// Regular expression to match the 'type: soundfile' pattern
|
|
162
270
|
const pattern = /"type":\s*"soundfile"/;
|
|
163
271
|
// Check if the pattern exists in the JSON string
|
|
@@ -166,28 +274,56 @@ class FaustWasmInstantiator {
|
|
|
166
274
|
// If the JSON contains a soundfile UI element, we need to create a memory object
|
|
167
275
|
if (isDetected) {
|
|
168
276
|
const memory = this.createMemoryMono(factory);
|
|
169
|
-
const instance = new WebAssembly.Instance(
|
|
170
|
-
|
|
277
|
+
const instance = new WebAssembly.Instance(
|
|
278
|
+
factory.module,
|
|
279
|
+
this.createWasmImport(memory)
|
|
280
|
+
);
|
|
281
|
+
return this.createMonoDSPInstanceAux(
|
|
282
|
+
instance,
|
|
283
|
+
factory.json,
|
|
284
|
+
memory
|
|
285
|
+
);
|
|
171
286
|
} else {
|
|
172
287
|
// Otherwise, we can create the instance using the wasm internal memory allocated by the wasm module
|
|
173
|
-
const instance = new WebAssembly.Instance(
|
|
288
|
+
const instance = new WebAssembly.Instance(
|
|
289
|
+
factory.module,
|
|
290
|
+
this.createWasmImport()
|
|
291
|
+
);
|
|
174
292
|
return this.createMonoDSPInstanceAux(instance, factory.json);
|
|
175
293
|
}
|
|
176
294
|
}
|
|
177
295
|
|
|
178
|
-
static async createAsyncPolyDSPInstance(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
296
|
+
static async createAsyncPolyDSPInstance(
|
|
297
|
+
voiceFactory: LooseFaustDspFactory,
|
|
298
|
+
mixerModule: WebAssembly.Module,
|
|
299
|
+
voices: number,
|
|
300
|
+
effectFactory?: LooseFaustDspFactory
|
|
301
|
+
): Promise<FaustPolyDspInstance> {
|
|
302
|
+
const memory = this.createMemoryPoly(
|
|
303
|
+
voices,
|
|
304
|
+
voiceFactory,
|
|
305
|
+
effectFactory
|
|
306
|
+
);
|
|
307
|
+
// Create voice
|
|
308
|
+
const voiceInstance = await WebAssembly.instantiate(
|
|
309
|
+
voiceFactory.module,
|
|
310
|
+
this.createWasmImport(memory)
|
|
311
|
+
);
|
|
312
|
+
const voiceFunctions = voiceInstance.exports as IFaustDspInstance &
|
|
313
|
+
WebAssembly.Exports;
|
|
183
314
|
const voiceAPI = new FaustDspInstance(voiceFunctions);
|
|
184
315
|
// Create mixer
|
|
185
316
|
const mixerAPI = this.createMixerAux(mixerModule, memory);
|
|
186
317
|
|
|
187
|
-
// Possibly create effect instance
|
|
318
|
+
// Possibly create effect instance
|
|
188
319
|
if (effectFactory) {
|
|
189
|
-
const effectInstance = await WebAssembly.instantiate(
|
|
190
|
-
|
|
320
|
+
const effectInstance = await WebAssembly.instantiate(
|
|
321
|
+
effectFactory.module,
|
|
322
|
+
this.createWasmImport(memory)
|
|
323
|
+
);
|
|
324
|
+
const effectFunctions =
|
|
325
|
+
effectInstance.exports as IFaustDspInstance &
|
|
326
|
+
WebAssembly.Exports;
|
|
191
327
|
const effectAPI = new FaustDspInstance(effectFunctions);
|
|
192
328
|
return {
|
|
193
329
|
memory,
|
|
@@ -209,19 +345,37 @@ class FaustWasmInstantiator {
|
|
|
209
345
|
}
|
|
210
346
|
}
|
|
211
347
|
|
|
212
|
-
static createSyncPolyDSPInstance(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
348
|
+
static createSyncPolyDSPInstance(
|
|
349
|
+
voiceFactory: LooseFaustDspFactory,
|
|
350
|
+
mixerModule: WebAssembly.Module,
|
|
351
|
+
voices: number,
|
|
352
|
+
effectFactory?: LooseFaustDspFactory
|
|
353
|
+
): FaustPolyDspInstance {
|
|
354
|
+
const memory = this.createMemoryPoly(
|
|
355
|
+
voices,
|
|
356
|
+
voiceFactory,
|
|
357
|
+
effectFactory
|
|
358
|
+
);
|
|
359
|
+
// Create voice
|
|
360
|
+
const voiceInstance = new WebAssembly.Instance(
|
|
361
|
+
voiceFactory.module,
|
|
362
|
+
this.createWasmImport(memory)
|
|
363
|
+
);
|
|
364
|
+
const voiceFunctions = voiceInstance.exports as IFaustDspInstance &
|
|
365
|
+
WebAssembly.Exports;
|
|
217
366
|
const voiceAPI = new FaustDspInstance(voiceFunctions);
|
|
218
367
|
// Create mixer
|
|
219
368
|
const mixerAPI = this.createMixerAux(mixerModule, memory);
|
|
220
369
|
|
|
221
|
-
// Possibly create effect instance
|
|
370
|
+
// Possibly create effect instance
|
|
222
371
|
if (effectFactory) {
|
|
223
|
-
const effectInstance = new WebAssembly.Instance(
|
|
224
|
-
|
|
372
|
+
const effectInstance = new WebAssembly.Instance(
|
|
373
|
+
effectFactory.module,
|
|
374
|
+
this.createWasmImport(memory)
|
|
375
|
+
);
|
|
376
|
+
const effectFunctions =
|
|
377
|
+
effectInstance.exports as IFaustDspInstance &
|
|
378
|
+
WebAssembly.Exports;
|
|
225
379
|
const effectAPI = new FaustDspInstance(effectFunctions);
|
|
226
380
|
return {
|
|
227
381
|
memory,
|