1.3.0 • Published 6 months ago

faust-loader v1.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

faust-loader

Import Faust .dsp files, and get back an AudioWorklet or ScriptProcessor node.

This loader is confirmed working with Faust v2.30.5, but may break on lower versions. Help is wanted on getting the WASM version of libfaust working in NodeJS.

Installation

  1. Install the Faust compiler version >=2.30.5. You can download it or build it from source. It's also available from the AUR.

  2. Install faust-loader:

npm install --save-dev faust-loader
# OR
yarn add -D faust-loader
  1. Add faust-loader to your webpack config:
module: {
    rules: [
    // ...
      {
        test: /\.dsp$/,
        use: [
          {
            loader: "faust-loader",
            options: {
              outputPath: "processors",       // Where the generated files will be placed relative to the output directory
              publicPath: "/build/processors" // Where the generated files will be served from
            }
          },
        ],
      },
    ],
  },

Usage

import { AudioContext } from "standardized-audio-context";
import createCompressor from "./Compressor.dsp";

const context = new AudioContext();
createCompressor(context).then((node) => {
  node.connect(context.destination);
  node.getParams();
  node.setParam("attack", 0.3);
});

faust-loader makes use of standardized-audio-context for instantiating AudioWorkletNodes. This allows it to automatically fallback to a ScriptProcessorNode on Safari and other browsers that don't support AudioWorklets, as well as interoperate seamlessly with Tone.js, a popular web audio framework.

Because of this, you have to use an AudioContext from standardized-audio-context when creating Faust nodes. If you want to use this loader with a vanilla AudioContext, please submit an issue or PR!

With Tone.js

import { getContext, connect } from "tone";
import createSynth from "./Synthesizer.dsp";

async function connectSynth() {
  const context = getContext();

  // `context` is the Tone Context, we need to get the raw standardized-audio-context.
  const node = await createSynth(context.rawContext);

  // We also need to use the global `connect` function since the node isn't a Tone AudioNode.
  connect(node, context.destination);
}

With Next.js

// next.config.js

module.exports = {
  webpack: (config, { isServer }) => {
    config.module.rules.push({
      test: [/\.dsp$/],
      loader: "faust-loader",
      options: {
        outputPath: `${isServer ? "../" : ""}static/processors/`,
        publicPath: "/_next/static/processors",
      },
    });

    return config;
  },
};
1.3.1-alpha0

6 months ago

1.4.0-alpha0

6 months ago

1.3.0

10 months ago

1.3.0-beta.1

10 months ago

1.3.0-beta.0

10 months ago

1.2.3

1 year ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.0-beta.2

3 years ago

1.1.0-beta.1

3 years ago

1.1.0-beta.6

3 years ago

1.1.0-beta.5

3 years ago

1.1.0-beta.4

3 years ago

1.1.0-beta.3

3 years ago

1.0.0

3 years ago

0.5.7

3 years ago

0.3.0

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago