@grame/faustwasm 0.4.6 → 0.4.8
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 +4 -4
- package/assets/standalone/create-node.js +78 -0
- package/assets/standalone/faustwasm/index.js +12 -32
- package/assets/standalone/faustwasm/index.js.map +2 -2
- package/assets/standalone/index-template.html +17 -0
- package/assets/standalone/index-template.js +48 -0
- package/assets/standalone/index.html +4 -3
- package/assets/standalone/index.js +14 -71
- package/assets/standalone/manifest.json +5 -6
- package/assets/standalone/service-worker.js +51 -27
- package/dist/cjs/index.js +12 -32
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs-bundle/index.js +12 -32
- package/dist/cjs-bundle/index.js.map +2 -2
- package/dist/esm/index.js +12 -32
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/index.js +12 -32
- package/dist/esm-bundle/index.js.map +2 -2
- package/fileutils.js +19 -21
- package/package.json +1 -1
- package/scripts/faust2wasm.js +10 -5
- package/src/FaustAudioWorkletNode.ts +5 -14
- package/src/FaustScriptProcessorNode.ts +5 -14
- package/src/copyWebStandaloneAssets.d.ts +2 -2
- package/src/copyWebStandaloneAssets.js +30 -19
- package/src/faust2wasmFiles.js +5 -5
- package/test/faustlive-wasm/faustwasm/index.js +12 -32
- package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
- package/assets/standalone/index-poly.js +0 -234
- package/assets/standalone/service-worker-poly.js +0 -98
- package/assets/standalone/template-poly.html +0 -60
- package/assets/standalone/template.html +0 -50
- package/assets/standalone/template.js +0 -63
- package/assets/standalone/types.d.ts +0 -9
- package/node +0 -0
- package/src/instantiateFaustModule.js +0 -82
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<title>Faust DSP</title>
|
|
6
|
+
</head>
|
|
7
|
+
|
|
8
|
+
<body>
|
|
9
|
+
<main>
|
|
10
|
+
<span id="dsp-switch">
|
|
11
|
+
<center><button id="button-dsp">Activate DSP</button></center>
|
|
12
|
+
</span>
|
|
13
|
+
</main>
|
|
14
|
+
<script src="./index-template.js"></script>
|
|
15
|
+
</body>
|
|
16
|
+
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Set to > 0 if the DSP is polyphonic
|
|
2
|
+
const FAUST_DSP_VOICES = 0;
|
|
3
|
+
|
|
4
|
+
(async () => {
|
|
5
|
+
const { default: createFaustNode } = await import("./create-node.js");
|
|
6
|
+
|
|
7
|
+
// Create audio context
|
|
8
|
+
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
9
|
+
const audioContext = new AudioCtx({ latencyHint: 0.00001 });
|
|
10
|
+
audioContext.suspend();
|
|
11
|
+
|
|
12
|
+
// Create audio context activation button
|
|
13
|
+
/** @type {HTMLButtonElement} */
|
|
14
|
+
const $buttonDsp = document.getElementById("button-dsp");
|
|
15
|
+
|
|
16
|
+
const play = (node) => {
|
|
17
|
+
node.keyOn(0, 60, 100);
|
|
18
|
+
setTimeout(() => node.keyOn(0, 64, 100), 1000);
|
|
19
|
+
setTimeout(() => node.keyOn(0, 67, 100), 2000);
|
|
20
|
+
setTimeout(() => node.allNotesOff(), 5000);
|
|
21
|
+
setTimeout(() => play(node), 7000);
|
|
22
|
+
}
|
|
23
|
+
// Function to activate audio context
|
|
24
|
+
$buttonDsp.disabled = true;
|
|
25
|
+
$buttonDsp.onclick = () => {
|
|
26
|
+
if (audioContext.state === "running") {
|
|
27
|
+
$buttonDsp.textContent = "Suspended";
|
|
28
|
+
audioContext.suspend();
|
|
29
|
+
} else if (audioContext.state === "suspended") {
|
|
30
|
+
$buttonDsp.textContent = "Running";
|
|
31
|
+
audioContext.resume();
|
|
32
|
+
if (FAUST_DSP_VOICES) play(faustNode);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Create Faust node
|
|
37
|
+
const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "FAUST_DSP_NAME", FAUST_DSP_VOICES);
|
|
38
|
+
if (!faustNode) throw new Error("Faust DSP not compiled");
|
|
39
|
+
|
|
40
|
+
// Connect Faust node to audio context
|
|
41
|
+
faustNode.connect(audioContext.destination);
|
|
42
|
+
|
|
43
|
+
// Create Faust node activation button
|
|
44
|
+
$buttonDsp.disabled = false;
|
|
45
|
+
|
|
46
|
+
// Set page title to the DSP name
|
|
47
|
+
document.title = name;
|
|
48
|
+
})();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
|
|
4
|
-
<link rel="manifest" href="
|
|
4
|
+
<link rel="manifest" href="./manifest.json">
|
|
5
5
|
|
|
6
6
|
<head>
|
|
7
7
|
<meta charset="UTF-8">
|
|
@@ -59,9 +59,10 @@
|
|
|
59
59
|
display: flex;
|
|
60
60
|
position: relative;
|
|
61
61
|
flex-direction: column;
|
|
62
|
+
color: black;
|
|
62
63
|
}
|
|
63
64
|
</style>
|
|
64
|
-
<link rel="stylesheet" href="
|
|
65
|
+
<link rel="stylesheet" href="./faust-ui/index.css">
|
|
65
66
|
</head>
|
|
66
67
|
|
|
67
68
|
<body>
|
|
@@ -80,7 +81,7 @@
|
|
|
80
81
|
<div id="div-faust-ui">
|
|
81
82
|
</div>
|
|
82
83
|
</main>
|
|
83
|
-
<script src="
|
|
84
|
+
<script src="./index.js"></script>
|
|
84
85
|
</body>
|
|
85
86
|
|
|
86
87
|
</html>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
// Set to > 0 if the DSP is polyphonic
|
|
2
|
+
const FAUST_DSP_VOICES = 0;
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* @typedef {import("./types").FaustDspDistribution} FaustDspDistribution
|
|
3
5
|
* @typedef {import("./faustwasm").FaustAudioWorkletNode} FaustAudioWorkletNode
|
|
4
6
|
* @typedef {import("./faustwasm").FaustDspMeta} FaustDspMeta
|
|
5
7
|
* @typedef {import("./faustwasm").FaustUIDescriptor} FaustUIDescriptor
|
|
@@ -10,11 +12,11 @@
|
|
|
10
12
|
/**
|
|
11
13
|
* Registers the service worker.
|
|
12
14
|
*/
|
|
13
|
-
if (
|
|
14
|
-
window.addEventListener(
|
|
15
|
-
navigator.serviceWorker.register(
|
|
16
|
-
.then(reg => console.log(
|
|
17
|
-
.catch(err => console.log(
|
|
15
|
+
if ("serviceWorker" in navigator) {
|
|
16
|
+
window.addEventListener("load", () => {
|
|
17
|
+
navigator.serviceWorker.register("./service-worker.js")
|
|
18
|
+
.then(reg => console.log("Service Worker registered", reg))
|
|
19
|
+
.catch(err => console.log("Service Worker registration failed", err));
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
22
|
|
|
@@ -33,7 +35,7 @@ const $divFaustUI = document.getElementById("div-faust-ui");
|
|
|
33
35
|
|
|
34
36
|
/** @type {typeof AudioContext} */
|
|
35
37
|
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
36
|
-
const audioContext = new AudioCtx({ latencyHint: 0.00001
|
|
38
|
+
const audioContext = new AudioCtx({ latencyHint: 0.00001 });
|
|
37
39
|
audioContext.destination.channelInterpretation = "discrete";
|
|
38
40
|
audioContext.suspend();
|
|
39
41
|
$buttonDsp.disabled = true;
|
|
@@ -46,7 +48,7 @@ const buildAudioDeviceMenu = async (faustNode) => {
|
|
|
46
48
|
let inputStreamNode;
|
|
47
49
|
const handleDeviceChange = async () => {
|
|
48
50
|
const devicesInfo = await navigator.mediaDevices.enumerateDevices();
|
|
49
|
-
$selectAudioInput.innerHTML =
|
|
51
|
+
$selectAudioInput.innerHTML = "";
|
|
50
52
|
devicesInfo.forEach((deviceInfo, i) => {
|
|
51
53
|
const { kind, deviceId, label } = deviceInfo;
|
|
52
54
|
if (kind === "audioinput") {
|
|
@@ -119,67 +121,6 @@ const buildMidiDeviceMenu = async (faustNode) => {
|
|
|
119
121
|
};
|
|
120
122
|
};
|
|
121
123
|
|
|
122
|
-
/**
|
|
123
|
-
* Creates a Faust audio node for use in the Web Audio API.
|
|
124
|
-
*
|
|
125
|
-
* @param {AudioContext} audioContext - The Web Audio API AudioContext to which the Faust audio node will be connected.
|
|
126
|
-
* @param {string} dspName - The name of the DSP to be loaded.
|
|
127
|
-
* @param {number} voices - The number of voices to be used for polyphonic DSPs.
|
|
128
|
-
* @param {boolean} sp - Whether to create a ScriptProcessorNode instead of an AudioWorkletNode.
|
|
129
|
-
* @returns {Object} - An object containing the Faust audio node and the DSP metadata.
|
|
130
|
-
*/
|
|
131
|
-
const createFaustNode = async (audioContext, dspName = "template", voices = 0, sp = false) => {
|
|
132
|
-
// Import necessary Faust modules and data
|
|
133
|
-
const { FaustMonoDspGenerator, FaustPolyDspGenerator } = await import("./faustwasm/index.js");
|
|
134
|
-
|
|
135
|
-
// Load DSP metadata from JSON
|
|
136
|
-
/** @type {FaustDspMeta} */
|
|
137
|
-
const dspMeta = await (await fetch(`./${dspName}.json`)).json();
|
|
138
|
-
|
|
139
|
-
// Compile the DSP module from WebAssembly binary data
|
|
140
|
-
const dspModule = await WebAssembly.compileStreaming(await fetch(`./${dspName}.wasm`));
|
|
141
|
-
|
|
142
|
-
// Create an object representing Faust DSP with metadata and module
|
|
143
|
-
/** @type {FaustDspDistribution} */
|
|
144
|
-
const faustDsp = { dspMeta, dspModule };
|
|
145
|
-
|
|
146
|
-
/** @type {FaustAudioWorkletNode} */
|
|
147
|
-
let faustNode;
|
|
148
|
-
|
|
149
|
-
// Create either a polyphonic or monophonic Faust audio node based on the number of voices
|
|
150
|
-
if (voices > 0) {
|
|
151
|
-
|
|
152
|
-
// Try to load optional mixer and effect modules
|
|
153
|
-
try {
|
|
154
|
-
faustDsp.mixerModule = await WebAssembly.compileStreaming(await fetch("./mixerModule.wasm"));
|
|
155
|
-
faustDsp.effectMeta = await (await fetch(`./${dspName}_effect.json`)).json();
|
|
156
|
-
faustDsp.effectModule = await WebAssembly.compileStreaming(await fetch(`./${dspName}_effect.wasm`));
|
|
157
|
-
} catch (e) { }
|
|
158
|
-
|
|
159
|
-
const generator = new FaustPolyDspGenerator();
|
|
160
|
-
faustNode = await generator.createNode(
|
|
161
|
-
audioContext,
|
|
162
|
-
voices,
|
|
163
|
-
"FaustPolyDSP",
|
|
164
|
-
{ module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta) },
|
|
165
|
-
faustDsp.mixerModule,
|
|
166
|
-
faustDsp.effectModule ? { module: faustDsp.effectModule, json: JSON.stringify(faustDsp.effectMeta) } : undefined,
|
|
167
|
-
sp
|
|
168
|
-
);
|
|
169
|
-
} else {
|
|
170
|
-
const generator = new FaustMonoDspGenerator();
|
|
171
|
-
faustNode = await generator.createNode(
|
|
172
|
-
audioContext,
|
|
173
|
-
"FaustMonoDSP",
|
|
174
|
-
{ module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta) },
|
|
175
|
-
sp
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Return an object with the Faust audio node and the DSP metadata
|
|
180
|
-
return { faustNode, dspMeta };
|
|
181
|
-
}
|
|
182
|
-
|
|
183
124
|
/**
|
|
184
125
|
* @param {FaustAudioWorkletNode} faustNode
|
|
185
126
|
*/
|
|
@@ -208,9 +149,11 @@ const createFaustUI = async (faustNode) => {
|
|
|
208
149
|
};
|
|
209
150
|
|
|
210
151
|
(async () => {
|
|
152
|
+
const { default: createFaustNode } = await import("./create-node.js");
|
|
211
153
|
// To test the ScriptProcessorNode mode
|
|
212
|
-
//const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "
|
|
213
|
-
const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "
|
|
154
|
+
// const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "FAUST_DSP_NAME", FAUST_DSP_VOICES, true);
|
|
155
|
+
const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "FAUST_DSP_NAME", FAUST_DSP_VOICES);
|
|
156
|
+
if (!faustNode) throw new Error("Faust DSP not compiled");
|
|
214
157
|
await createFaustUI(faustNode);
|
|
215
158
|
faustNode.connect(audioContext.destination);
|
|
216
159
|
if (faustNode.numberOfInputs) await buildAudioDeviceMenu(faustNode);
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "Faust
|
|
3
|
-
"short_name": "
|
|
4
|
-
"start_url": "
|
|
5
|
-
"description": "Progressive Web App for
|
|
2
|
+
"name": "Faust FAUST_DSP_NAME",
|
|
3
|
+
"short_name": "FAUST_DSP_NAME",
|
|
4
|
+
"start_url": "./index.html",
|
|
5
|
+
"description": "Progressive Web App for FAUST_DSP_NAME",
|
|
6
6
|
"display": "standalone",
|
|
7
7
|
"background_color": "#ffffff",
|
|
8
8
|
"theme_color": "#000000",
|
|
9
|
-
"scope": "/FAUST_DSP/",
|
|
10
9
|
"orientation": "portrait",
|
|
11
10
|
"icons": [
|
|
12
11
|
{
|
|
13
|
-
"src": "icon.png",
|
|
12
|
+
"src": "./icon.png",
|
|
14
13
|
"sizes": "390x390",
|
|
15
14
|
"type": "image/png"
|
|
16
15
|
}
|
|
@@ -1,31 +1,55 @@
|
|
|
1
|
+
/// <reference lib="webworker" />
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
// Set to > 0 if the DSP is polyphonic
|
|
4
|
+
const FAUST_DSP_VOICES = 0;
|
|
5
|
+
// Set to true if the DSP has an effect
|
|
6
|
+
const FAUST_DSP_HAS_EFFECT = false;
|
|
7
|
+
|
|
8
|
+
const CACHE_NAME = "FAUST_DSP_NAME-static"; // Cache name without versioning
|
|
9
|
+
|
|
10
|
+
const MONO_RESOURCES = [
|
|
11
|
+
"./index.html",
|
|
12
|
+
"./faust-ui/index.js",
|
|
13
|
+
"./faust-ui/index.css",
|
|
14
|
+
"./faustwasm/index.js",
|
|
15
|
+
"./index.js",
|
|
16
|
+
"./dsp-module.wasm",
|
|
17
|
+
"./dsp-meta.json"
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const POLY_RESOURCES = [
|
|
21
|
+
...MONO_RESOURCES,
|
|
22
|
+
"./mixer-module.wasm",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const POLY_EFFECT_RESOURCES = [
|
|
26
|
+
...POLY_RESOURCES,
|
|
27
|
+
"./effect-module.wasm",
|
|
28
|
+
"./effect-meta.json",
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
/**@type {ServiceWorkerGlobalScope} */
|
|
32
|
+
const serviceWorkerGlobalScope = self;
|
|
23
33
|
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Install the service worker and cache the resources
|
|
36
|
+
*/
|
|
37
|
+
serviceWorkerGlobalScope.addEventListener("install", (event) => {
|
|
38
|
+
console.log("Service worker installed");
|
|
39
|
+
event.waitUntil((async () => {
|
|
40
|
+
const cache = await caches.open(CACHE_NAME);
|
|
41
|
+
const resources = (FAUST_DSP_VOICES && FAUST_DSP_HAS_EFFECT) ? POLY_EFFECT_RESOURCES : FAUST_DSP_VOICES ? POLY_RESOURCES : MONO_RESOURCES;
|
|
42
|
+
try {
|
|
43
|
+
return cache.addAll(resources);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error("Failed to cache resources during install:", error);
|
|
46
|
+
}
|
|
47
|
+
})());
|
|
26
48
|
});
|
|
27
49
|
|
|
28
|
-
|
|
50
|
+
serviceWorkerGlobalScope.addEventListener("activate", () => console.log("Service worker activated"));
|
|
51
|
+
|
|
52
|
+
serviceWorkerGlobalScope.addEventListener("fetch", (event) => {
|
|
29
53
|
event.respondWith((async () => {
|
|
30
54
|
const cache = await caches.open(CACHE_NAME);
|
|
31
55
|
const cachedResponse = await cache.match(event.request);
|
|
@@ -35,14 +59,14 @@ self.addEventListener('fetch', event => {
|
|
|
35
59
|
try {
|
|
36
60
|
const fetchResponse = await fetch(event.request);
|
|
37
61
|
// Ensure the response is valid before caching it
|
|
38
|
-
if (event.request.method ===
|
|
62
|
+
if (event.request.method === "GET" && fetchResponse && fetchResponse.status === 200 && fetchResponse.type === "basic") {
|
|
39
63
|
cache.put(event.request, fetchResponse.clone());
|
|
40
64
|
}
|
|
41
65
|
return fetchResponse;
|
|
42
66
|
} catch (e) {
|
|
43
67
|
// Network access failure
|
|
44
|
-
console.log(
|
|
68
|
+
console.log("Network access error", e);
|
|
45
69
|
}
|
|
46
70
|
}
|
|
47
71
|
})());
|
|
48
|
-
});
|
|
72
|
+
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -3749,22 +3749,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
3749
3749
|
async listenSensors() {
|
|
3750
3750
|
if (this.hasAccInput) {
|
|
3751
3751
|
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
this.propagateAcc({ x, y, z }, true);
|
|
3759
|
-
};
|
|
3760
|
-
} else {
|
|
3761
|
-
handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
3762
|
-
if (!accelerationIncludingGravity)
|
|
3763
|
-
return;
|
|
3764
|
-
const { x, y, z } = accelerationIncludingGravity;
|
|
3765
|
-
this.propagateAcc({ x, y, z });
|
|
3766
|
-
};
|
|
3767
|
-
}
|
|
3752
|
+
const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
3753
|
+
if (!accelerationIncludingGravity)
|
|
3754
|
+
return;
|
|
3755
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
3756
|
+
this.propagateAcc({ x, y, z }, isAndroid);
|
|
3757
|
+
};
|
|
3768
3758
|
if (window.DeviceMotionEvent) {
|
|
3769
3759
|
if (typeof window.DeviceMotionEvent.requestPermission === "function") {
|
|
3770
3760
|
try {
|
|
@@ -4013,22 +4003,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
4013
4003
|
async listenSensors() {
|
|
4014
4004
|
if (this.hasAccInput) {
|
|
4015
4005
|
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
this.propagateAcc({ x, y, z }, true);
|
|
4023
|
-
};
|
|
4024
|
-
} else {
|
|
4025
|
-
handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
4026
|
-
if (!accelerationIncludingGravity)
|
|
4027
|
-
return;
|
|
4028
|
-
const { x, y, z } = accelerationIncludingGravity;
|
|
4029
|
-
this.propagateAcc({ x, y, z });
|
|
4030
|
-
};
|
|
4031
|
-
}
|
|
4006
|
+
const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
4007
|
+
if (!accelerationIncludingGravity)
|
|
4008
|
+
return;
|
|
4009
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
4010
|
+
this.propagateAcc({ x, y, z }, isAndroid);
|
|
4011
|
+
};
|
|
4032
4012
|
if (window.DeviceMotionEvent) {
|
|
4033
4013
|
if (typeof window.DeviceMotionEvent.requestPermission === "function") {
|
|
4034
4014
|
try {
|