@solidrt/flux-types 0.0.42 → 0.0.44

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/gui/audio.d.ts CHANGED
@@ -1,50 +1,85 @@
1
1
  // Sound playback (gui-enabled runtime only). The imperative primitive; `play`
2
- // decodes and starts a clip in one call, while `load` decodes once so a clip can
3
- // be replayed cheaply. Handles carry a `stop()` bound to just that voice, so the
4
- // raw track id never leaves the runtime.
2
+ // decodes and starts a clip in one call, while `load`/`loadPcm`/`stream` yield
3
+ // a Clip that starts cheap overlapping Playbacks. Handles carry controls bound
4
+ // to just that clip or playback, so raw ids never leave the runtime.
5
5
 
6
6
  declare module "flux:audio" {
7
- /** Options for {@link play} and {@link LoadedSound.play}. */
7
+ /** Options for {@link play} and {@link Clip.play}. */
8
8
  type PlayOptions = {
9
9
  /** Repeat the clip until stopped. Defaults to false. */
10
10
  loop?: boolean
11
11
  /** Volume scale, 1.0 leaves the clip unchanged. Defaults to 1.0. */
12
12
  gain?: number
13
+ /**
14
+ * Stereo position in [-1, 1] (clamped), -1 = left, 0 = center, 1 = right,
15
+ * equal-power law. Omitted means unspatialized: no stereo processing at
16
+ * all, which for a mono clip is about 3 dB louder than `pan: 0`.
17
+ */
18
+ pan?: number
13
19
  }
14
20
 
15
- /** A playing voice with controls bound to it. */
16
- type SoundHandle = {
17
- /** Stop this voice. A no-op if it already finished. */
21
+ /** One playing instance of a clip, with live controls bound to it. */
22
+ type Playback = {
23
+ /** Stop this playback. A no-op if it already finished. */
18
24
  stop(): void
25
+ /**
26
+ * Change the volume while playing. A finite number >= 0; 1.0 is the clip's
27
+ * own level. A no-op after the playback finished.
28
+ */
29
+ setGain(gain: number): void
30
+ /**
31
+ * Move the stereo position while playing (see {@link PlayOptions.pan}).
32
+ * A no-op after the playback finished.
33
+ */
34
+ setPan(pan: number): void
35
+ /** Whether playback finished, naturally or via {@link stop}. */
36
+ ended(): boolean
19
37
  }
20
38
 
21
- /** A decoded clip that can be replayed without re-decoding. */
22
- type LoadedSound = {
23
- /** Start a fresh overlapping voice for this clip. */
24
- play(options?: PlayOptions): SoundHandle
25
- /** Release the decoded clip. Voices already playing keep going. */
39
+ /** A loaded clip that can be played without re-decoding. */
40
+ type Clip = {
41
+ /** Start a fresh overlapping playback of this clip. */
42
+ play(options?: PlayOptions): Playback
43
+ /** Release the clip. Playbacks already running keep going. */
26
44
  unload(): void
27
45
  }
28
46
 
47
+ /** Options for {@link loadPcm}. */
48
+ type PcmOptions = {
49
+ /** Channel count, interleaved samples when 2. Defaults to 1 (mono). */
50
+ channels?: 1 | 2
51
+ }
52
+
29
53
  /**
30
54
  * Decode and start an encoded audio clip (Ogg/Vorbis or WAV). Returns
31
55
  * immediately; the sound plays on the mixer's own thread. Use {@link load} to
32
56
  * replay a clip repeatedly without decoding it each time.
33
57
  */
34
- export function play(bytes: Uint8Array, options?: PlayOptions): SoundHandle
58
+ export function play(bytes: Uint8Array, options?: PlayOptions): Playback
35
59
  /**
36
60
  * Decode an encoded clip (Ogg/Vorbis or WAV) once and keep it in memory so it
37
61
  * can be replayed cheaply. Call `unload()` on the result when done.
38
62
  */
39
- export function load(bytes: Uint8Array): LoadedSound
63
+ export function load(bytes: Uint8Array): Clip
64
+ /**
65
+ * Load raw PCM samples as a clip; no decoding, no container. The typed array
66
+ * is the sample format: Uint8Array = unsigned 8-bit, Int16Array = signed
67
+ * 16-bit, Float32Array = 32-bit float, all as laid out in memory. Samples are
68
+ * interleaved when `channels` is 2. Call `unload()` on the result when done.
69
+ */
70
+ export function loadPcm(
71
+ data: Uint8Array | Int16Array | Float32Array,
72
+ sampleRate: number,
73
+ options?: PcmOptions,
74
+ ): Clip
40
75
  /**
41
76
  * Open a clip for streaming: it is decoded on demand instead of loaded fully
42
77
  * into memory, so a large track needs little RAM. Takes a `file()` from
43
78
  * `flux:fs` (not a path), so the source rides the `file()` proxy override - a
44
79
  * dev-server-proxied file streams from the server. Play the result as a single
45
- * voice; do not overlap a stream with itself. Call `unload()` when done.
80
+ * playback; do not overlap a stream with itself. Call `unload()` when done.
46
81
  */
47
- export function stream(source: ReturnType<typeof import("flux:fs").file>): LoadedSound
82
+ export function stream(source: ReturnType<typeof import("flux:fs").file>): Clip
48
83
  /** Stop every playing sound. */
49
84
  export function stop(): void
50
85
  }
package/gui/gpu.d.ts CHANGED
@@ -116,6 +116,20 @@ declare module "flux:gpu" {
116
116
  * {@link setShaderSize}).
117
117
  */
118
118
  export type LabelOption = { label?: string }
119
+ /**
120
+ * Pixel format of an uploaded texture, declared at creation and fixed for
121
+ * the id's lifetime (like the sampler state). "rgba8" (default) is 4 bytes
122
+ * per pixel. "r8" is the single-channel format - 1 byte per pixel - for
123
+ * palette-indexed or grayscale content: upload raw indices and look the
124
+ * color up in the shader, so palette effects are a palette-texture write
125
+ * instead of touching every pixel. Any width works (no 4-byte row padding;
126
+ * the engine uploads r8 at unpack alignment 1). A shader samples an r8
127
+ * texture as `(v, 0, 0, 1)` - read `.r`; displaying one via `<texture src>`
128
+ * shows that same red-channel reading. Shader/pipeline targets and
129
+ * readbacks stay RGBA8.
130
+ */
131
+ export type TextureFormat = "rgba8" | "r8"
132
+ export type TextureFormatOption = { format?: TextureFormat }
119
133
  /**
120
134
  * This device's hard ceilings, queried once at startup: process constants.
121
135
  * Every create and bind validates against them at the call site, so an
@@ -138,19 +152,22 @@ declare module "flux:gpu" {
138
152
  maxVertexAttribs: number
139
153
  }
140
154
  /**
141
- * Create an immutable texture from an RGBA8 pixel buffer (exactly
142
- * width*height*4 bytes). Returns the texture id.
155
+ * Create an immutable texture from a pixel buffer (exactly
156
+ * width*height*bytesPerPixel bytes: *4 for the default "rgba8" format, *1
157
+ * for "r8"). Returns the texture id.
143
158
  */
144
- export function createTexture(data: Uint8Array, width: number, height: number, opts?: SamplerOptions & LabelOption): TextureId
159
+ export function createTexture(data: Uint8Array, width: number, height: number, opts?: SamplerOptions & TextureFormatOption & LabelOption): TextureId
145
160
  /**
146
161
  * Create a texture intended to be updated later via {@link uploadTexture}. The
147
- * seed buffer must hold at least one frame (width*height*4 bytes) and may hold
148
- * more (uploadTexture selects a frame by offset).
162
+ * seed buffer must hold at least one frame (width*height bytes at the
163
+ * declared format's pixel size) and may hold more (uploadTexture selects a
164
+ * frame by offset).
149
165
  */
150
- export function createMutableTexture(data: Uint8Array, width: number, height: number, opts?: SamplerOptions & LabelOption): TextureId
166
+ export function createMutableTexture(data: Uint8Array, width: number, height: number, opts?: SamplerOptions & TextureFormatOption & LabelOption): TextureId
151
167
  /**
152
- * Replace a mutable texture's pixels. `data` may hold several frames; `offset`
153
- * (default 0) selects which frame to upload.
168
+ * Replace a mutable texture's pixels; the frame size follows the format the
169
+ * id was created with. `data` may hold several frames; `offset` (default 0)
170
+ * selects which frame to upload.
154
171
  */
155
172
  export function uploadTexture(id: TextureId, data: Uint8Array, offset?: number): void
156
173
  /**
@@ -158,8 +175,9 @@ declare module "flux:gpu" {
158
175
  * resize): `<texture src>` references and shader sampler bindings keep
159
176
  * working, and shaders sampling the texture re-render. `data` seeds the new
160
177
  * contents and, like {@link createMutableTexture}, must hold at least one
161
- * width*height*4 frame. Shader/pipeline target ids are rejected - resize
162
- * those with {@link setShaderSize}.
178
+ * frame at the id's format (which survives the resize, like the sampler
179
+ * state). Shader/pipeline target ids are rejected - resize those with
180
+ * {@link setShaderSize}.
163
181
  */
164
182
  export function resizeTexture(id: TextureId, data: Uint8Array, width: number, height: number): void
165
183
  /**
@@ -202,8 +220,10 @@ declare module "flux:gpu" {
202
220
  * to the raw layer. The built-in vertex stage still supplies `vUV` to a
203
221
  * complete source; declare `in vec2 vUV;` yourself to read it. Same rule on
204
222
  * {@link createPipelineTexture}. A complete source may also declare
205
- * `iResolution` as vec3 (the Shadertoy shape); it is then filled as
206
- * `(w, h, 1.0)`.
223
+ * `iResolution` as vec3 (a common convention in ported shaders); it is
224
+ * then filled as `(w, h, 1.0)`. One naming trap: GLSL ES reserves `packed` as a keyword,
225
+ * so `vec4 packed = texture(...)` fails with a syntax error that does not
226
+ * name the identifier - pick another name.
207
227
  */
208
228
  export function createShaderTexture(
209
229
  fragmentSrc: string,
package/modules/wasm.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ // There is no `WebAssembly` global in flux; this module is the entire wasm
2
+ // surface. Imports must be scalar-signature functions only (no imported
3
+ // memory, globals or tables), which constrains the toolchain on the other
4
+ // side: default emscripten output imports its memory and is rejected, while
5
+ // `emcc -sSTANDALONE_WASM=1 --no-entry` produces a module that fits.
1
6
  declare module "flux:wasm" {
2
7
  /**
3
8
  * A scalar wasm value. i32/f32/f64 marshal as number; i64 marshals as BigInt
@@ -39,7 +44,8 @@ declare module "flux:wasm" {
39
44
  /**
40
45
  * Parse and validate a wasm binary (wat text bytes are also accepted).
41
46
  * Throws on invalid input or on an unsupported import (non-function, or
42
- * non-scalar signature).
47
+ * non-scalar signature) - see the module note above for the emscripten
48
+ * flags that produce a compatible binary.
43
49
  */
44
50
  constructor(bytes: Uint8Array | ArrayBuffer)
45
51
  /**
@@ -75,13 +81,27 @@ declare module "flux:wasm" {
75
81
  */
76
82
  callIndirect(index: number, ...args: WasmValue[]): WasmValue | WasmValue[] | undefined
77
83
  /**
78
- * The exported memory's current size in bytes, or `undefined` if the
79
- * module exports no memory.
84
+ * The exported linear memory as an `ArrayBuffer` aliasing the instance's
85
+ * live bytes, or `undefined` if the module exports no memory. Reads and
86
+ * writes go straight to guest memory - no copy; a `Uint8Array` over it
87
+ * (`new Uint8Array(instance.memory, ptr, len)`) is the zero-copy way to
88
+ * hand guest bytes to e.g. `uploadTexture`. Follows the web's
89
+ * `WebAssembly.Memory.buffer` contract: the buffer stays valid until the
90
+ * guest grows its memory, which detaches it; read `memory` again for a
91
+ * fresh buffer over the moved storage.
92
+ */
93
+ readonly memory: ArrayBuffer | undefined
94
+ /**
95
+ * Copy `len` bytes out of the exported memory at `ptr`, as a fresh
96
+ * `Uint8Array`. One-shot convenience; for repeated or large reads use
97
+ * {@link memory} directly.
80
98
  */
81
- readonly memorySize: number | undefined
82
- /** Copy `len` bytes out of the exported memory at `ptr`. */
83
99
  readMemory(ptr: number, len: number): Uint8Array
84
- /** Copy `bytes` into the exported memory at `ptr`. */
100
+ /**
101
+ * Copy `bytes` into the exported memory at `ptr`. The source may itself
102
+ * be a view over this instance's memory; overlapping ranges copy
103
+ * correctly.
104
+ */
85
105
  writeMemory(ptr: number, bytes: Uint8Array | ArrayBuffer): void
86
106
  }
87
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/flux-types",
3
- "version": "0.0.42",
3
+ "version": "0.0.44",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "types": "index.d.ts",