# @grame/faustwasm 中文文档

规范地址：https://npmcn.com/package/%40grame/faustwasm/

版本：0\.21\.1
npm 元数据更新时间：2026-11-15T17:22:43.980Z
中文译文更新时间：2026-11-16T21:56:35.298Z
软件包许可：LGPL-2\.1

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40grame/faustwasm
原文对照：https://npmcn.com/package/%40grame/faustwasm/?lang=original
项目主页：https://github.com/grame-cncm/faustwasm#readme
源码仓库：https://github.com/grame-cncm/faustwasm

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：31.4 MB，51 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2023-06-28T11:55:44.710Z
- 最新版本发布：2026-11-15T17:22:43.823Z
- 近 30 天下载量：45786（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：151（近 12 个月 47 个）

## 中文简介

浮士德编译器的 WebAssembly 版本

## 安装

```sh
npm install @grame/faustwasm
```

也可以使用：`pnpm add @grame/faustwasm`、`yarn add @grame/faustwasm`、`bun add @grame/faustwasm`

## README

# 浮出水面

FaustWasm 图书馆提供了一个方便的高级API [浮士德](https://faust.grame.fr/) 编译器. 这个库的界面主要设计于 [类型脚本](https://www.typescriptlang.org/) 使用,虽然它也为纯JavaScript提供了API描述和文档. Faust 编译器的WebAssembly版本与两者兼容 [节点.js](https://nodejs.org/) 和网页浏览器,已使用 [标记](https://emscripten.org/) 6.0.3 (英语).

库提供了将Faust DSP代码汇编到WebAssembly的功能,使其能在标准WebAudio节点图中作为WebAudio节点使用. 此外,它支持离线渲染情景。 此外,还可以使用补充工具,从Faust DSP方案生成SVG.

合成器和效应单节点,以及 [多声道](https://faustdoc.grame.fr/manual/midi/#midi-polyphony-support) 可以创建多节点. 一旦启动 MIDI 支持 [MIDI 元数据](https://faustdoc.grame.fr/manual/midi/#configuring-midi-in-faust) 用于单节点的DSP编码中,并始终采用多声模式.

[传感器](https://faustdoc.grame.fr/manual/syntax/#sensors-control-metadatas) 支持(加速计和陀螺仪)元数据以及 [渐进式网络应用](https://en.wikipedia.org/wiki/Progressive_web_app) 型号.

## 使用量

请使用稳定版本 [节点.js](https://nodejs.org/) 16+与该项目合作.

### 使用命令行接口

克隆人进入这个项目:

```bash
git clone https://github.com/grame-cncm/faustwasm.git
cd faustwasm
```

安装开发依赖性 :

```bash
npm install
```

也许:

```bash
npm update
```

构建文件 :

```bash
npm run build
```

源代码使用 [物质的高级代码](https://prettier.io/) 正确格式化所有TS和JS文件。 使用 :

```bash
npm run format
```

应用格式规则 `src`,并:

```bash
npm run lint
```

以检查格式规则 `src`。 。 。 .

### 版本

你必须提高软件包的版本号 `package.json` 在此之前 `npm run build` 以适当的工作.

#### 生成 Faust DSP 的 Web Assembly 版本

例如:

```bash
rm -rf test/out # make sure you are under the faustwasm directory.
node scripts/faust2wasm.js test/mono.dsp test/out
```

将创建一组文件 : `index.js`, (中文(简体) ), `create-node.js`, (中文(简体) ), `dsp-module.wasm`, (中文(简体) ), `dsp-meta.json`, (中文(简体) ), `index.html` 编辑 `faustwasm` 文件夹中 `out` 文件夹。 这个 `-no-template` 选项省略所有事项,但 `dsp-module.wasm` 财务报告和审定财务报表 `dsp-meta.json`。 。 。 .

配有:

```bash
rm -rf test/out # make sure you are under the faustwasm directory.
node scripts/faust2wasm.js test/poly.dsp test/out -poly
```

将创建一组文件 : `index.js`, (中文(简体) ), `create-node.js`, (中文(简体) ), `dsp-module.wasm`, (中文(简体) ), `dsp-meta.json`, (中文(简体) ), `mixer-module.wasm`, (中文(简体) ), `index.html` 编辑 `faustwasm` 文件夹(和,当 DSP 源定义 `effect`, (中文(简体) ), `effect-module.wasm` 财务报告和审定财务报表 `effect-meta.json`)在 `out` 文件夹.

#### 本地文件 `-I`

CLI 在 Web Assembly 文件系统中运行 Faust 编译器, 因此它不能直接读取您的主机文件系统 。 让本地 `import("something.lib")` 任务:

-   包含输入的目录 `.dsp` 自动复制到内存FS并添加到编译器中包含路径.
-   任意 `-I <dir>` 您的通过被镜像 入内膜FS 并添加到包含路径.
-   仅 `.dsp` 财务报告和审定财务报表 `.lib` 文件被镜像.

这意味着您可以从任何工作目录中运行 CLI , 只要您的本地地址包含 DSP 旁边的活字或列表中 `-I`。 。 。 .

示例,使用 `test/foo.dsp` 财务报告和审定财务报表 `test/includes/mylib.lib` 与存放处同船的固定装置`mylib.lib` 故意不坐旁边 `foo.dsp`,因此该建筑只与 `-I`:

```bash
node scripts/faust2wasm.js -I test/includes test/foo.dsp test/out
```

#### 创建Faust DSP的渐进网络应用程序

您可以使用命令行创建独立的进步网络应用程序 :

```bash
node scripts/faust2wasm.js test/rev.dsp test/rev -pwa
```

将创建一组文件 : `icon.png`, (中文(简体) ), `service-worker.js`, (中文(简体) ), `manifest.json`, (中文(简体) ), `index.js`, (中文(简体) ), `create-node.js`, (中文(简体) ), `faust-pwa.js`, (中文(简体) ), `dsp-module.wasm`, (中文(简体) ), `dsp-meta.json`, (中文(简体) ), `index.html`,则 `faustwasm`, (中文(简体) ), `faust-ui` 文件夹在 `rev` 文件夹.

该文件夹包含将浮士德应用程序作为PWA部署在服务器上的必要源代码,将安装并下线使用. 注意: `soundfile` dSP代码中的原始语必须被曼努尔添加到文件夹中.

可通过以下方式创建独立的多声道和MIDI独立渐进网络应用程序:

```bash
node scripts/faust2wasm.js test/organ1.dsp test/organ1 -poly -pwa
```

将创建相同的文件集,加 `mixer-module.wasm` 并且,自从 `organ1.dsp` 定义 `effect`, (中文(简体) ), `effect-module.wasm` 财务报告和审定财务报表 `effect-meta.json`,在 `organ1` 文件夹.

#### 创建独立版本的 Faust DSP, 配有音频和 MIDI 设备选择器

您可以使用命令行创建一个独立的 :

```bash
node scripts/faust2wasm.js test/rev.dsp test/rev -standalone
```

将创建一组文件 : `icon.png`, (中文(简体) ), `service-worker.js`, (中文(简体) ), `manifest.json`, (中文(简体) ), `index.js`, (中文(简体) ), `create-node.js`, (中文(简体) ), `dsp-module.wasm`, (中文(简体) ), `dsp-meta.json`, (中文(简体) ), `index.html`,则 `faustwasm`, (中文(简体) ), `faust-ui` 文件夹在 `rev` 文件夹.

该文件夹包含将浮士德应用程序作为PWA部署在服务器上的必要源代码,将安装并下线使用. 注意: `soundfile` dSP代码中的原始语必须被曼努尔添加到文件夹中.

可通过以下方式创建独立的多声道和MIDI独立渐进网络应用程序:

```bash
node scripts/faust2wasm.js test/organ1.dsp test/organ1 -poly -standalone
```

将创建相同的文件集,加 `mixer-module.wasm` 并且,自从 `organ1.dsp` 定义 `effect`, (中文(简体) ), `effect-module.wasm` 财务报告和审定财务报表 `effect-meta.json`,在 `organ1` 文件夹.

#### 生成 Faust DSP 的 SVG 图

例如:

```bash
rm -rf test/out # make sure you are under the faustwasm directory.
node scripts/faust2svg.js test/mono.dsp test/out
```

主图应该包含在 `test/out/process.svg`。 。 。 .

#### 在 Cmajor 文件内编译 Faust DSP

例如:

```bash
rm -rf test/out # make sure you are under the faustwasm directory.
node scripts/faust2cmajor.js test/organ.dsp test/out
```

Cmajor 文档应包含在 `test/out/organ.cmajor`。 。 。 .

#### 生成或处理音频文件

选项 :

-   `-bs <num>` 设置帧中的渲染缓冲大小( 默认: 64)
-   `-bd 16|24|32` 设置输出文件位深( 默认: 16)
-   `-c <samples>` 在框中设置输出文件长度, 当 -ct 不使用时( 默认: SR\* 5)
-   `-in <inputWav.wav>` 指定要处理的输入文件
-   `-sr <num>` 设置输出文件样本率( 默认: 44100) 见此帮助:

```bash
node scripts/faust2sndfile.js -h
```

例如:

```bash
rm -rf test/out # make sure you are under the faustwasm directory.
node scripts/faust2sndfile.js test/djembe.dsp test/out/djembe.wav -c 192000 -sr 48000 -bd 24
```

现在 `test/out/djembe.wav` 应生成。 根据需要创建了输出文件的文件夹.

生成的文件又可以由另一个 DSP 处理 `-in`数字 :

```bash
node scripts/faust2sndfile.js test/rev.dsp test/out/djembe-rev.wav -c 192000 -sr 48000 -bd 24 -in test/out/djembe.wav
```

### 使用 JavaScript 模块

```bash
npm i -D @grame/faustwasm
```

在 Java 脚本中 :

```JavaScript
const FaustWasm = require("@grame/faustwasm");
const path = require("path");
const fs = require("fs");

const {
    instantiateFaustModuleFromFile,
    LibFaust,
    WavEncoder,
    FaustMonoDspGenerator,
    FaustCompiler,
    FaustSvgDiagrams
} = FaustWasm;

(async () => {
    const faustModulePath = path.join(__dirname, "../node_modules/@grame/faustwasm/libfaust-wasm/libfaust-wasm.js");

    // initialize the libfaust wasm
    const faustModule = await instantiateFaustModuleFromFile(faustModulePath);

    // Get the Faust compiler
    const libFaust = new LibFaust(faustModule);
    console.log(libFaust.version());
    const compiler = new FaustCompiler(libFaust);
    const generator = new FaustMonoDspGenerator();
    const sampleRate = 48000;
    const name = "Djembe"
    const argv = ["-I", "libraries/"];
    const code = `
import("stdfaust.lib");
process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1);
`;
    // Compile the DSP
    await generator.compile(compiler, name, code, argv.join(" "));
    const processor = await generator.createOfflineProcessor(sampleRate, 1024);

    // Generate SVG diagrams.
    const svgDiagrams = new FaustSvgDiagrams(compiler);
    const svgs = svgDiagrams.from(name, code, argv.join(" "));
    console.log(Object.keys(svgs));

    const out = processor.render(null, 192000);
    const wav = WavEncoder.encode(out, { sampleRate, bitDepth: 24 });

    // The wav file is generated
    fs.writeFileSync(`${__dirname}/out.wav`, new Uint8Array(wav));
})();
```

### 在网页浏览器中使用

```JavaScript

(async () => {
    const {
        instantiateFaustModuleFromFile,
        LibFaust,
        WavEncoder,
        FaustMonoDspGenerator,
        FaustCompiler,
        FaustSvgDiagrams
    } = await import("../node_modules/@grame/faustwasm/dist/esm/index.js");

    // initialize the libfaust wasm
    const faustModule = await instantiateFaustModuleFromFile("../node_modules/@grame/faustwasm/libfaust-wasm/libfaust-wasm.js");

    // Get the Faust compiler
    const libFaust = new LibFaust(faustModule);
    window.libFaust = libFaust;
    console.log(libFaust.version());
    const compiler = new FaustCompiler(libFaust);
    const generator = new FaustMonoDspGenerator();
    const sampleRate = 48000;
    const name = "Djembe"
    const argv = ["-I", "libraries/"];
    const code = `
import("stdfaust.lib");
process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1);
`;
    // Compile the DSP
    await generator.compile(compiler, name, code, argv.join(" "));
    const processor = await generator.createOfflineProcessor(sampleRate, 1024);

    // Generate SVG diagrams.
    const svgDiagrams = new FaustSvgDiagrams(compiler);
    const svgs = svgDiagrams.from(name, code, argv.join(" "));
    console.log(Object.keys(svgs));

    const out = processor.render(null, 192000);
    const wav = WavEncoder.encode(out, { sampleRate, bitDepth: 24 });

    // The wav file is generated
    const blob = new Blob([wav], { type: "audio/wav" });
    const player = document.createElement("audio");
    player.controls = true;
    player.src = URL.createObjectURL(blob);
    document.body.appendChild(player);
    const svg = document.createElement("div");
    svg.innerHTML = svgs["process.svg"];
    document.body.appendChild(svg);
})();
```

### 多声乐器的平滑控制

空闲多声调没有计算,所以控制平滑 `si.smoo` 可以保留一个旧值,直到声音被再利用。 对于在笔记开始时应当取出其当前值的控件,使用 [`si.polySmooth`](https://faustlibraries.grame.fr/libs/signals/#sipolysmooth) 与乐器的 `gate`数字 :

```faust
import("stdfaust.lib");

freq = nentry("freq", 440, 20, 20000, 1);
gain = nentry("gain", 1, 0, 1, 0.01);
gate = button("gate");
level = hslider("level", 1, 0, 1, 0.01)
    : si.polySmooth(gate, 0.999, 32);

process = os.osc(freq) * gain
    * en.adsr(0.01, 0.1, 0.8, 0.2, gate) * level <: _, _;
```

这里, `0.999` 是平滑系数,而且 `32` 是闸口起伏后平滑恢复前的样品数量。 所持音符的后期控制变化仍然平滑.

### 正在计算活动声音

多声节点和离线处理器有一个 `getNumActiveVoices()` 方法,它返回声音仍然发声的数:播放,在放出时,或在legato. 释放出的声音数到它死了, 这使得它适合一个语音表:

```JavaScript
const meter = () => {
    voicesLabel.textContent = `${node.getNumActiveVoices()} voices`;
    requestAnimationFrame(meter);
};
meter();
```

使用 AudioWorklet 节点,声音会活在音频线索上:处理器在它所变化的每个块的结尾报告其编号,节点返回最新的报告. 脚本处理器节点和离线处理器直接计数. 吻合点 `getNumActiveVoices()` c++ 多声道架构`faust/dsp/poly-dsp.h`) (中文(简体) ).

### 早点释放出声音

释放出的声音被计算到其水平下至-90分贝,然后其插槽再次被自由. 认为更高水平的无声主机可以给出自己的阈值,即 _停止关卡_,并更快地将CPU调回. 这是 `stopLevel` 会 议 日 程 和 议 程 `processorOptions` 联 合 国 `createNode`,对于一个音频Worklet节点,对于一个脚本处理器,以及最后一个参数 `createOfflineProcessor`数字 :

```JavaScript
// Voices are freed under -60 dB
const node = await generator.createNode(
    audioContext, 16, "synth", undefined, undefined, undefined, false, 1024, undefined,
    { stopLevel: 0.001 }
);
const processor = await generator.createOfflineProcessor(
    sampleRate, 1024, 16, undefined, undefined, undefined, undefined, 0.001
);
```

停止水平是线性的振幅, `10^(dB/20)`,与每个块上的声音的RMS级别相比,在其所有输出通道上. 它必须在里面 `]0, 0.01]`,即最多-40分贝:在控制台上发出警告而拒绝任何其他值,并使用-90分贝。 它是在节点创建后设定的,之后无法被更改. 和那个差不多 `stoplevel` 论点 `mydsp_poly` c++ 多声道架构中`faust/dsp/poly-dsp.h`) (中文(简体) ).

### 样本准确的时间安排

Faust AudioWorklet 节点上的每个控制方法都有一个可选 `time` 参数: `setParamValue(path, value, time)`, (中文(简体) ), `keyOn(channel, pitch, velocity, time)`, (中文(简体) ), `keyOff(channel, pitch, velocity, time)`, (中文(简体) ), `midiMessage(data, time)`, (中文(简体) ), `ctrlChange(channel, ctrl, value, time)`, (中文(简体) ), `pitchWheel(channel, wheel, time)`。 。 。 . `time` 以 AudioContext 秒表示——与 `audioCtx.currentTime` 财务报告和审定财务报表 `AudioParam.setValueAtTime` 动作在即时名称的精确样本上, 在包含它的音频块内。 单位为第二(一个JavaScript双人),颗粒性为样本:处理器将其与 `Math.round(time * sampleRate)` 在音频时钟上的帧,所以一个瞬间被纪念到最近的样本(大约21μs at 48 kHz):

```JavaScript
const t0 = audioCtx.currentTime + 0.1;

// A parameter change on the exact sample
node.setParamValue("/mydsp/gate", 1, t0);
node.setParamValue("/mydsp/gate", 0, t0 + 0.05);

// A polyphonic pattern scheduled ahead of time
node.keyOn(0, 60, 100, t0);
node.keyOff(0, 60, 0, t0 + 0.5);
node.keyOn(0, 63, 100, t0 + 0.25);
```

经常 `AudioParam` 节点参数上的自动化(`setValueAtTime`, (中文(简体) ), `linearRampToValueAtTime`,.)也被精确地跟踪样本,因此可以安排一个注释和一个参数斜坡对接. 由Web音频模块(WAM)活动所携带的时标同样受到尊重.

别管了, `time` 行为如前: 消息在到达时, 在下一个音频块开始时应用 。 A 类 `time` 已经在过去的应用 尽快,顺序。 注释:

-   fFT 处理器荣誉 `time` (一) 块颗粒性,而不是样品颗粒性;
-   脚本处理器节点( S)`sp: true`接受论点,并在抵达时应用信息;
-   `setParamValue` 负数 `time` 抛出( 它被拒绝 ) `AudioParam.setValueAtTime`) (中文(简体) ).

页面 `test/web/poly-schedule.html` 显示API,以及 `test/timing/measure.mjs` 衡量样本的准确性(见下文).

### 运行测试

单位测试 `test/unit` 并运行在平原节点(不需要浏览器). 首先建立无害环境管理捆绑,然后逐一运行 `*.test.mjs` 带有节点内置测试运行器的文件 :

```bash
npm test
```

计时标准 `test/timing/measure.mjs`:它通过一个无头铬中真正的AudioWorklet使MIDI注释和参数改变,并检查每一个都降落在它预定的确切样本上. 这需要 [剧作家](https://playwright.dev/),故意不依赖此套件:

```bash
npm i --no-save playwright
npx playwright install chromium
npm run measure
```

使用CLI测试 `test/cli` 并运行脚本 `scripts/` 检查磁盘上留下了什么 它们涵盖了每个输出模式 `faust2wasm.js` (默认模板, `-no-template`, (中文(简体) ), `-standalone`, (中文(简体) ), `-pwa`,每个有和没有 `-poly`页:1 `.dsp` 文件输入 `test/` - 每一个编译,然后从生成的装入 `dsp-module.wasm` 财务报告和审定财务报表 `dsp-meta.json` 和边缘案件: `-I` 包括处理、论证、失败模式和同时援引. `faust2svg`, (中文(简体) ), `faust2cmajor` 财务报告和审定财务报表 `faust2sndfile` 后者也包括在内,通过阅读 `-sr`, (中文(简体) ), `-bd` 财务报告和审定财务报表 `-c` 返回到生成的 WAV 页眉。 他们不需要浏览器 :

```bash
npm run test-cli
```

`npm run test-all` 进行单位测试和CLI测试。 都写在 `test/out`,当套房通过时,该套房被取出并被取出;故障运行时,该套房被取出,以便检查产出。 CLI测试需要几秒钟.

`test/web` 包含在浏览器中手动检查的交互式测试页面:单声道和多声道仪器、FFT处理器、音效文件以及 `createFaustNode` API (英语). 构建软件包,为 repo 根服务(所以) `dist/` 财务报告和审定财务报表 `libfaust-wasm/` ),然后打开诸如 [http://localhost:8000/test/web/mono.html 页面存档备份,存于互联网档案馆](http://localhost:8000/test/web/mono.html)数字 :

```bash
npm run build
python3 -m http.server 8000
```

### 项目实例

几个例子可以通过在 faustwasm 根级别启动本地网络服务器进行测试,然后进入 `test/faustlive-wasm` 财务报告和审定财务报表 `libfaust-in-worklet` 文件夹.

该软件包用于以下项目:

-   [faust-web-组件](https://github.com/grame-cncm/faust-web-component),一个包提供了两个网络组件,用于将交互式浮士德片段嵌入到网页中.
-   [浮游游戏场](https://github.com/grame-cncm/faustplayground),一个网络平台,旨在使儿童能够以简单而生动的方式学习基本的音频编程.
-   [浮士德编辑器](https://github.com/grame-cncm/fausteditor)在WebAssembly支持下,一个简单的在线编辑器用于编辑、编译和运行任何最近Web浏览器的Faust代码.
-   [浮起网络 IDE](https://github.com/grame-cncm/faustide)在WebAssembly支持下,用于编辑、编译和运行任何最近Web浏览器的Faust代码.
-   [测试嵌入式动态 Faust 编译器](https://fausteditor.grame.fr/faustlive-wasm.html) 页面允许测试编译器, 与此相关 [HTML 源代码](https://github.com/grame-cncm/fausteditor/blob/master/faustlive-wasm.html) 使用 [此 Java 脚本代码](https://github.com/grame-cncm/fausteditor/blob/master/src/faustlive-wasm.js)。 。 。 .

## 文档

-   [API 组织](https://npmcn.com/package/%40grame/faustwasm/#readme-org)
    
-   [Faust 编译器 Web Assembly 模块](https://npmcn.com/package/%40grame/faustwasm/#readme-module)
    
-   [Faust 编译器 Javascript 接口](https://npmcn.com/package/%40grame/faustwasm/#readme-compiler)
    
-   [浮士德·瓦斯姆实例](https://npmcn.com/package/%40grame/faustwasm/#readme-wasm)
    
-   [Faust 音频节点实例和离线处理器](https://npmcn.com/package/%40grame/faustwasm/#readme-audio)
    
-   [高级API](https://npmcn.com/package/%40grame/faustwasm/#readme-high)
    
-   [如何使用打字符](https://npmcn.com/package/%40grame/faustwasm/#readme-tsuse)
    
-   [动态和静态实例](https://npmcn.com/package/%40grame/faustwasm/#readme-ds)
    
-   [杂项服务](https://npmcn.com/package/%40grame/faustwasm/#readme-misc)
    
-   [重要说明](https://npmcn.com/package/%40grame/faustwasm/#readme-note)
    

### API 组织

如下图所示,API的组织水平从低到高.

![](https://npmcn.com/package/%40grame/faustwasm/rsrc/overview.png)

#### Faust 编译器 Web Assembly 模块

第一个关卡是 Faust 编译器, 编译为 asum 库, 命名为 `libfaust-wasm`。 。 。 . 它包括三个不同的文件:

-   `libfaust-wasm.wasm` : 作为WebAssembly模块提供的浮士德编译器
-   `libfaust-wasm.js` : Web Assembly 模块的 Javascript 载入器
-   `libfaust-wasm.data` :包含"浮士德"图书馆的虚拟文件系统.

C++ 代码由 [标记](https://emscripten.org/) 和接口 `LibFaust.ts` 财务报告和审定财务报表 `types.ts`文档。 装入器将负责提供浮士德WebAssembly模块以及相关虚拟文件系统(libfaust-wasm.data)的实例.

### Faust 编译器 Javascript 接口

Faust 编译器 Javascript 界面描述于 `FaustCompiler.ts`。 。 。 .  
它规定 _经典_ Faust编译服务,其输出是一个原始的WebAssembly模块,并附带了该模块的JSON描述.

### 浮士德·瓦斯姆实例

这个关卡需要由Faust编译器制作的WebAssemsem模块或从文件中装入的预编译模块,并用适当的Wasm内存布局构建一个模块实例,准备运行. 其说明见: `FaustDspGenerator.ts`, (中文(简体) ), `FaustWasmInstantiator.ts`, (中文(简体) ), `FaustWebAudioDsp.ts` 财务报告和审定财务报表 `FaustDspInstance.ts` 文档.

#### Faust 音频节点实例和离线处理器

这个关卡需要一个浮士德·瓦斯姆实例来构建一个音频节点. [音频工作](https://developer.mozilla.org/fr/docs/Web/API/AudioWorklet) 财务报告和审定财务报表 [脚本处理器](https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode) 节点被支持. 其说明见: `FaustAudioWorkletNode.ts` 财务报告和审定财务报表 `FaustAudioWorkletProcessor.ts` 文档.

**3⁄4 ̄ ̧漯B**: AudioWorklet是一种最新技术,可能不会得到所有浏览器的支持. 检查 [兼容性](https://developer.mozilla.org/fr/docs/Web/API/AudioWorklet) 图表.

基础音频节点 API 文档记录在 [IFAustBase 微信公众号](https://github.com/search?q=repo%3Agrame-cncm%2Ffaustwasm%20IFaustBaseWebAudioDsp&type=code) 接口。 这个 [互联网档案馆的存檔,存档日期2013-12-04](https://github.com/search?q=repo%3Agrame-cncm%2Ffaustwasm%20IFaustPolyWebAudioDsp&type=code) 接口文档多声扩展名.

注意脚本处理器标记为 [已贬值](https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode) 但它是唯一在更古老的Safari版本中可用的音频架构. 单声道(发音,效果. )或多声道(仪器)节点都可以被创建. 其说明见: `FaustScriptProcessorNode.ts` 文档.

创建的音频节点有一个 `start` 财务报告和审定财务报表 `stop` 方法。 。 。 启动时(默认情况下完成),它们正在处理音频缓冲. 您可能必须明确阻止它们来保存 CPU( 并在需要时再次启动) , 例如, 在实际使用前的inition时间创建了多个节点 .

一个在非实时上下文中渲染出DSP并获得计算框架的离线处理器可供使用. 其说明见: `FaustOfflineProcessor.ts`。它将自动使用 `start` 财务报告和审定财务报表 `stop` 在内部激活其实际渲染的方法 `plot` 方法.

#### 高级API

高级API提供了方便的功能来编译一个Faust DSP程序并创建出相应的音频节点,无论是单音节还是多音节.

-   使用适当的 `FaustMonoDspGenerator` 或者说 `FaustPolyDspGenerator` 班级, `createNode` 明确建立单声道或多声道节点.
-   `createFaustNode` 通过检查 : `[nvoices:N]` dSP 元数据中的字段.

对于离线渲染, `createOfflineProcessor` 具有并支持单声道和多声道处理。 FFT 处理节点可以使用 `createFFTNode`。 。 。 .

此API由FaustDspGenerator.ts执行.

#### 如何使用打字符

简单地包括以下内容以获取类型和功能:

```
///<reference types="@grame/faustwasm"/>
```

### 动态和静态实例

Faust Wasm 和 Audio Node 级别使得从 Faust dsp 代码以及预编译的 Web Assembly 模块生成实例成为可能. 在后一种情况下,没有必要包括: `libfaust-wasm.js` 图书馆, `index.js` 足以提供所需的服务. 这可以生成更轻快的HTML页面.

## 杂项服务

-   `FaustSvgDiagrams.ts`: 提供浏览浮士德生成的 SVG 图表的设施
-   `FaustFFTAudioWorkletProcessor`: 提供 FFT 处理

### 重要说明

Html 页面嵌入了 Faust 编译器,必须使用 https 服务,除非使用 http://localhost .

* * *

[![](https://faust.grame.fr/community/logos/img/LOGO_FAUST_COMPLET_ORANGE.png)](http://faust.grame.fr/)

## 常见问题

### @grame/faustwasm 是什么？

浮士德编译器的 WebAssembly 版本

### 如何安装 @grame/faustwasm？

在项目目录运行 npm install @grame/faustwasm，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 faust2svg-ts、faust2wasm-ts、faust2sndfile-ts，可以用 npx faust2svg-ts 直接运行。

### @grame/faustwasm 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @grame/faustwasm 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @grame/faustwasm 可以商用吗？

@grame/faustwasm 使用 LGPL-2\.1 许可。弱 Copyleft：作为库被调用时通常不要求开源你自己的代码，但修改库本身需以 LGPL 开源；前端打包合并后的适用边界存在不同理解。以上为概括，不构成法律意见，请以许可原文为准。

### @grame/faustwasm 的下载量有多少？

根据 npm 官方下载统计，@grame/faustwasm 在 2026/10/17 – 2026/11/15 这 30 天内被下载 45,786 次，日均约 1,526 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @grame/faustwasm 还在维护吗？

最新版本 0\.21\.1 发布于 2026/11/16（1 天前）；至今共发布 151 个版本，其中过去 12 个月发布了 47 个；首次发布于 2023/06/28。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

