This guide helps you set up FluexGL DSP for your project. The setup is straightforward but requires a few specific settings.
To use FluexGL DSP, install the following components.
From your project directory, install FluexGL DSP with NPM. Always use the latest version to stay up to date.
$ npm install @fluex/fluexgl-dsp
FluexGL DSP uses WebAssembly for high-performance audio processing. The WebAssembly build lives in a separate repository and is not bundled with the NPM package (@fluex/fluexgl-dsp), so you must provide it manually.
Go to the GitHub releases page to find the latest version: https://github.com/rohankanhaisingh/FluexGL-DSP-WebAssembly/releases.
Download the latest release (a .zip file) containing the required files. The filename is usually fluexgl-dsp-wasm-release-x.x.x.zip.
Note: Install the WebAssembly version that matches the NPM package version. Mixing versions can break features.
Extract the .zip file into a new folder. The folder contains the following files:
fluexgl-dsp-processor.worklet (important)fluexgl-dsp.wasm.old.jsfluexgl-dsp-wasm.jsfluexgl-dsp-wasm_bg.wasm (important)package.json.gitignorefluexgl-dsp-wasm.d.tsfluexgl-dsp-wasm_bg.wasm.d.tsMove the important files into a folder in your project and ensure your server can serve them. A common path is /public/data/fluexgl-dsp/. FluexGL DSP uses the built-in fetch method to load both the processor worklet and the WebAssembly file.
After installing the NPM package and the WebAssembly release, you are ready to initialize the DSP pipeline in your client code.
First, set up the initialization pipeline with the DspPipeline class. Wrap the code in an asynchronous scope.
import { DspPipeline } from "@fluex/fluexgl-dsp";
(async function() {
const pipeline = new DspPipeline({
pathToWasm: "path_to_wasm.wasm",
pathToWorklet: "path_to_worklet.worklet"
});
})();
This class requires an options object. The required options are pathToWasm and pathToWorklet.
Enter the paths to the .wasm and .worklet files that the DspPipeline can reach. If the files are not accessible, the console shows a detailed error.
Correct example usage:
(async function() {
const pipeline = new DspPipeline({
pathToWasm: "/data/fluexgl-dsp/fluexgl-dsp-wasm_bg.wasm",
pathToWorklet: "/data/fluexgl-dsp/fluexgl-dsp-processor.worklet"
});
})();
After providing the required data, initialize the pipeline using InitializeDpsPipeline() or the shorthand Init() method.
(async function() {
const pipeline = new DspPipeline({
pathToWasm: "/data/fluexgl-dsp/fluexgl-dsp-wasm_bg.wasm",
pathToWorklet: "/data/fluexgl-dsp/fluexgl-dsp-processor.worklet"
});
await pipeline.InitializeDpsPipeline();
})();
Check the console to follow the initialization process. Each step is logged.
Great! You are now ready to use FluexGL DSP.
The DspPipeline class has additional configuration options. For example, you can control logging or allow FluexGL DSP to override the maximum audio buffer nodes.
When deploying your application, you can disable logs so the console stays clean for users. Set this option manually:
(async function() {
const pipeline = new DspPipeline({
pathToWasm: "/data/fluexgl-dsp/fluexgl-dsp-wasm_bg.wasm",
pathToWorklet: "/data/fluexgl-dsp/fluexgl-dsp-processor.worklet",
options: {
debugger: {
breakOnError: true,
showInfo: false,
showErrors: false,
showWarnings: false
}
}
});
await pipeline.InitializeDpsPipeline();
})();
This is useful in scenarios like video games where you do not want to create a new AudioClip every time a sound plays. Instead, reuse audio buffer nodes within the same clip to keep the audio thread fast and optimized.
Enable the option:
(async function() {
const pipeline = new DspPipeline({
pathToWasm: "/data/fluexgl-dsp/fluexgl-dsp-wasm_bg.wasm",
pathToWorklet: "/data/fluexgl-dsp/fluexgl-dsp-processor.worklet",
options: {
overrideMaxAudioBufferNodes: true
}
});
await pipeline.InitializeDpsPipeline();
})();
In your AudioClip, manually set the maximum number of buffer source nodes:
import { AudioClip } from "@fluex/fluexgl-dsp";
const myAudioClip = new AudioClip(sourceData);
myAudioClip.SetMaxAudioBufferSourceNodes(200);