@noonesimg/mosfez-faust
v0.0.20
Published
fork of https://www.npmjs.com/package/mosfez-faust with added functionality.
Downloads
2
Readme
mosfez-faust
Fork of https://www.npmjs.com/package/mosfez-faust
Makes dynamic compilation of Faust on the web a little easier, and has a dev project to run values through dsp offline, and preview dsp live. It's an opinionated version of some parts of Faust for webaudio, mostly just the Web Assembly Faust compiler, wrapped up in a library that has:
- full typescript compatibility
- ESM exports, so no need to add
<script>
tags - have any async functions chain seamlessly off any prior initialisation steps, so if a required resource is not yet ready, the API function simply waits until it is ready
- error reporting is more idiomatic for JavaScript - error objects are thrown containing details of the problem when compilation does not work
Note: "opinionated" means this library has a much narrower set of concerns than the original Faust webaudio API it's using. This is mainly just for compilation on the web, playback using AudioWorket
nodes, no in-built-polyphonic compilation. Some compilation options may be inaccessible via this API.
Installation
npm install mosfez-faust
or yarn add mosfez-faust
Then you'll need to copy the files from node_modules/mosfez-faust/public
and put it in your projects public-facing root directory that will be accessible once deployed. e.g. if you are using Vite, put them in your Vite project's public
directory. This library will make a request for libfaust-wasm.wasm
and libfaust-wasm.data
when it starts up, and will not work if those files can't be found.
Usage
import { compile } from "mosfez-faust/faust";
import { touchStart } from "mosfez-faust/touch-start";
const audioContext = new window.AudioContext();
touchStart(audioContext);
async function startSines() {
const dsp = `
import("stdfaust.lib");
process = os.osc(440.0),os.osc(441.0);
`;
const node = await compile(audioContext, dsp);
node.connect(audioContext.destination);
}
Also some general purpose web audio conversion utilities can be found at:
import { * as conversions } from "mosfez-faust/convert";
See source code for details.