grame-cncm / faust2webaudio

faust2webaudio for npm
GNU General Public License v3.0
21 stars 2 forks source link

Difficulty getting faust2webaudio to work on Windows #16

Closed barnabycollins closed 2 years ago

barnabycollins commented 2 years ago

I'm looking to use this module for an academic project, since I need a framework to generate synthesisers in the browser and Faust seems ideal for this. I see that it's used in the Faust IDE, but I am having problems getting it to work and am wondering if I'm missing some documentation somewhere.

barnabycollins commented 2 years ago

The main problems I'm currently having are:

I'm trying to import and use Faust in a similar way to the file in README.md (but adjusted based on index.ts in the Faust IDE repo):

import {Faust, FaustAudioWorkletNode, FaustScriptProcessorNode} from "faust2webaudio";
const audioCtx = new window.AudioContext();
const code = `
import("stdfaust.lib");
process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1) <: dm.freeverb_demo;`;

const faust = new Faust({
  debug: true,
  wasmLocation: "src/libfaust/libfaust-wasm.wasm",
  dataLocation: "src/libfaust/libfaust-wasm.data"
});

await faust.ready;

let node: FaustScriptProcessorNode | FaustAudioWorkletNode;
node = await faust.getNode(code, { audioCtx, useWorklet: window.AudioWorklet ? true : false, args: { "-I": "https://raw.githubusercontent.com/grame-cncm/faustlibraries/4cd48b91f1170498c1cf5d8ee5b87cda6cd797df/" } })
.then(node => node.connect(audioCtx.destination));

I've downloaded libfaust-wasm.data and libfaust-wasm.wasm from the Faust IDE in case the hardcoded URLs or included WASM files were wrong (after trying both of these first), and also pointed the compiler to the up-to-date faustlibraries repo rather than the faust website as you can see, because https://faust.grame.fr/tools/editor/libraries/stdfaust.lib seemed to be 404ing. I'm also using the same, latest version (1f9a20e8ec21139ab002c2f3e37574764a510903) of faust2wasm as the IDE.

Is there anything else I should be doing / anything else I should know about? I've tried to replicate the (obviously working) state of the Faust IDE as far as I can with no success so far.

TIA!

Fr0stbyteR commented 2 years ago

Hi @barnabycollins, If I understood correctly, you wan't to use faust2webaudio in another project.

  1. In that case, you may need to ensure that libfaust-wasm.data and libfaust-wasm.wasm match the version of faust2webaudio. You can simply use the files under ./dist folder in this project. (Those from the Faust IDE may not be the latest.)
  2. the entire faustlibraries is just inside libfaust-wasm.data, so no need to have another copy or point elsewhere. They are built-in, just neet to use the argument -I libraries/ as in the test/mono.html
  3. The module is still maintained but we are planning to migrate to a new build. @sletz
barnabycollins commented 2 years ago

Hi there @Fr0stbyteR; thanks for the super-quick response and clear instructions! Yes; I am hoping to use it in my own web tool as part of my undergraduate final Master's project.

I've switched to the bundled libfaust-wasm.* files and changed the -I argument back.

I was then getting the following error: image

which seems to be similar to the error in issue #13. I saw you just mentioned CRLF might cause issues on that thread and I am running Windows, and you were right - converting libfaust-wasm.data to LF instead of CRLF in my IDE appears to have fixed it, and I was instantly blessed with some beautiful djembe noises!

Thanks for your help! 😁

barnabycollins commented 2 years ago

To summarise, I think my problem was that I saw the error appearing when I used the copy from dist, so looked at #13 and decided to try another copy from the IDE, which was the wrong version and therefore also didn't work. Switching back to the copy bundled with the module and making sure it was using LF fixed all my problems.

Fr0stbyteR commented 2 years ago

Wow glad to know that it works! ;)

barnabycollins commented 2 years ago

Renaming to reflect discussion and closing 😁