Skip to content

Commit

Permalink
Fix up & setup build for faustlive-wasm.html
Browse files Browse the repository at this point in the history
  • Loading branch information
ijc8 committed Jun 26, 2023
1 parent 15481cd commit ebe61da
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
6 changes: 4 additions & 2 deletions faustlive-wasm.html
Expand Up @@ -6,7 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FaustLive WASM</title>
<link rel="stylesheet" href="css/faustlive-wasm.css">
<link rel="stylesheet" href="scripts/faust-ui/index.css">
</head>
<body>
<center>
Expand Down Expand Up @@ -125,6 +124,9 @@ <H3>Float denormals handling</H3>

<div id="faust-ui"></div>

<script src="src/faustlive-wasm.js"></script>
<script type="module">
import { setBufferSize, setPoly, setPolyVoices, setRenderingMode, setFTZ, setSampleFormat, setLocalStorage } from "./src/faustlive-wasm";
Object.assign(window, { setBufferSize, setPoly, setPolyVoices, setRenderingMode, setFTZ, setSampleFormat, setLocalStorage })
</script>
</body>
</html>
22 changes: 13 additions & 9 deletions src/faustlive-wasm.js
@@ -1,4 +1,8 @@
//@ts-check
// @ts-check
import jsURL from "@shren/faustwasm/libfaust-wasm/libfaust-wasm.js?url"
import dataURL from "@shren/faustwasm/libfaust-wasm/libfaust-wasm.data?url"
import wasmURL from "@shren/faustwasm/libfaust-wasm/libfaust-wasm.wasm?url"

/** @type {typeof AudioContext} */
const AudioContextConstructor = globalThis.AudioContext || globalThis.webkitAudioContext;
const audio_context = new AudioContextConstructor({ latencyHint: 0.00001 });
Expand Down Expand Up @@ -42,7 +46,7 @@ let output_handler = (path, value) => faustUI.paramChangeByDSP(path, value);
/**
* @param {HTMLSelectElement} bs_item
*/
const setBufferSize = (bs_item) => {
export const setBufferSize = (bs_item) => {
buffer_size = parseInt(bs_item.options[bs_item.selectedIndex].value);
if (buffer_size === 128 && rendering_mode === "ScriptProcessor") {
console.log("buffer_size cannot be set to 128 in ScriptProcessor mode !");
Expand All @@ -55,23 +59,23 @@ const setBufferSize = (bs_item) => {
/**
* @param {HTMLSelectElement} poly_item
*/
const setPoly = (poly_item) => {
export const setPoly = (poly_item) => {
poly_flag = poly_item.options[poly_item.selectedIndex].value;
compileDSP();
}

/**
* @param {HTMLSelectElement} voices_item
*/
const setPolyVoices = (voices_item) => {
export const setPolyVoices = (voices_item) => {
poly_nvoices = parseInt(voices_item.options[voices_item.selectedIndex].value);
compileDSP();
}

/**
* @param {HTMLSelectElement} rendering_item
*/
const setRenderingMode = (rendering_item) => {
export const setRenderingMode = (rendering_item) => {
rendering_mode = rendering_item.options[rendering_item.selectedIndex].value;
/** @type {HTMLSelectElement} */
const selectedBuffer = document.getElementById("selectedBuffer");
Expand All @@ -90,15 +94,15 @@ const setRenderingMode = (rendering_item) => {
/**
* @param {HTMLSelectElement} ftz_item
*/
const setFTZ = (ftz_item) => {
export const setFTZ = (ftz_item) => {
ftz_flag = ftz_item.options[ftz_item.selectedIndex].value;
compileDSP();
}

/**
* @param {HTMLSelectElement} sample_item
*/
const setSampleFormat = (sample_item) => {
export const setSampleFormat = (sample_item) => {
sample_format = sample_item.options[sample_item.selectedIndex].value;
compileDSP();
}
Expand Down Expand Up @@ -238,7 +242,7 @@ const getDevice = (device) => {
audio_input.connect(DSP);
}

const setLocalStorage = (state) => {
export const setLocalStorage = (state) => {
console.log(state);
setStorageItemValue('FaustLibTester', 'FaustLocalStorage', ((state) ? "on" : "off"));
}
Expand Down Expand Up @@ -584,7 +588,7 @@ const init = async () => {
} = await import("@shren/faustwasm");
FaustUI = (await import("@shren/faust-ui")).FaustUI;
// Init Faust compiler and node factory
const module = await instantiateFaustModuleFromFile("../node_modules/@shren/faustwasm/libfaust-wasm/libfaust-wasm.js");
const module = await instantiateFaustModuleFromFile(jsURL, dataURL, wasmURL);
// const module = await instantiateFaustModule();
const libFaust = new LibFaust(module);
faust_compiler = new FaustCompiler(libFaust);
Expand Down
13 changes: 13 additions & 0 deletions vite.config.js
@@ -0,0 +1,13 @@
import { resolve } from 'path'
import { defineConfig } from 'vite'

export default defineConfig({
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
other: resolve(__dirname, 'faustlive-wasm.html'),
},
},
},
})

0 comments on commit ebe61da

Please sign in to comment.