@mimium/mimium-webaudio 4.0.0-alpha.4 → 4.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md CHANGED
@@ -6,4 +6,74 @@ https://mimium.org
6
6
 
7
7
  The main entrypoint of compiler on web platform is [`mimium-web`](https://www.npmjs.com/package/mimium-web), which is directory exported from Rust code using wasm-pack.
8
8
 
9
- The reason to split package for audioworklet module is because wasm-pack is not fully compatible with WebAudio AudioWorklet and need to write some wrapper code to load wasm modules.
9
+ The reason to split package for audioworklet module is because wasm-pack is not fully compatible with WebAudio AudioWorklet and need to write some wrapper code to load wasm modules.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @mimium/mimium-webaudio
15
+ ```
16
+
17
+ ## Basic usage
18
+
19
+ ```ts
20
+ import {
21
+ preloadMimiumLibCache,
22
+ setupMimiumAudioWorklet,
23
+ } from "@mimium/mimium-webaudio";
24
+ import processorUrl from "@mimium/mimium-webaudio/dist/audioprocessor.mjs?url";
25
+
26
+ const ctx = new AudioContext();
27
+
28
+ const src = `
29
+ fn dsp(){
30
+ 0.0
31
+ }
32
+ `;
33
+
34
+ await preloadMimiumLibCache({
35
+ libBaseUrl: "https://raw.githubusercontent.com/mimium-org/mimium-rs/dev/lib/",
36
+ });
37
+
38
+ const node = await setupMimiumAudioWorklet(ctx, src, processorUrl);
39
+ node.connect(ctx.destination);
40
+ ```
41
+
42
+ `setupMimiumAudioWorklet` returns `MimiumProcessorNode` (`AudioWorkletNode`).
43
+
44
+ ## API
45
+
46
+ ```ts
47
+ preloadMimiumLibCache(options?: {
48
+ libBaseUrl?: string;
49
+ }): Promise<void>
50
+
51
+ setupMimiumAudioWorklet(
52
+ ctx: AudioContext,
53
+ src: string,
54
+ MimiumProcessorUrl: string,
55
+ options?: {
56
+ libBaseUrl?: string;
57
+ moduleBaseUrl?: string;
58
+ }
59
+ ): Promise<MimiumProcessorNode>
60
+ ```
61
+
62
+ - `libBaseUrl`: Base URL for standard mimium libraries (default: `https://raw.githubusercontent.com/mimium-org/mimium-rs/dev/lib/`).
63
+ - `moduleBaseUrl`: Base URL for user modules resolved by `mod` / `include` (default: current page base URL).
64
+
65
+ For code that uses standard library modules (`use osc::sinwave`, etc.), calling `preloadMimiumLibCache` before `setupMimiumAudioWorklet` is recommended.
66
+
67
+ ## Notes
68
+
69
+ - Compilation and library/module fetch are done on the main thread.
70
+ - AudioWorklet uses preloaded virtual file cache and does not fetch files directly.
71
+
72
+ ## Testing (Playwright)
73
+
74
+ ```bash
75
+ npx playwright install chromium
76
+ npx playwright test tests/compile.spec.ts
77
+ ```
78
+
79
+ This test opens a browser page, creates `AudioContext` + `AudioWorklet`, compiles a mimium source, and verifies compile completion.
@@ -1,10 +1,14 @@
1
1
  import { Context } from 'mimium-web';
2
2
  export declare class MimiumProcessor extends AudioWorkletProcessor {
3
3
  context: Context | null;
4
+ isCompiled: boolean;
4
5
  interleaved_input: Float32Array;
5
6
  interleaved_output: Float32Array;
6
7
  constructor();
7
8
  onmessage(event: MessageEvent<any>): void;
8
- compile(samplerate: number, buffersize: number, src: string): void;
9
+ compile(samplerate: number, buffersize: number, src: string, moduleBaseUrl?: string, libBaseUrl?: string, virtualFiles?: Array<{
10
+ path: string;
11
+ content: string;
12
+ }>): Promise<void>;
9
13
  process(inputs: Float32Array[][], outputs: Float32Array[][], parameter: Record<string, Float32Array>): boolean;
10
14
  }