@audio/synth-sfx 1.1.1 → 1.1.3

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.
Files changed (4) hide show
  1. package/README.md +40 -3
  2. package/audio.d.ts +27 -0
  3. package/package.json +16 -4
  4. package/sfx.d.ts +40 -0
package/README.md CHANGED
@@ -1,5 +1,42 @@
1
- # @audio/synth-sfx
1
+ # @audio/synth-sfx [![npm](https://img.shields.io/npm/v/@audio/synth-sfx)](https://www.npmjs.com/package/@audio/synth-sfx) [![MIT](https://img.shields.io/badge/MIT-%E0%A5%90-white)](https://github.com/krishnized/license)
2
2
 
3
- > Game/UI sound effects generator — ZZFX / ChipTone class parameterized synthesis
3
+ ZZFX-class parameterized SFX, 8 deterministic presets
4
4
 
5
- Planned — not implemented yet. See the umbrella README for status and sources.
5
+ ```
6
+ npm install @audio/synth-sfx
7
+ ```
8
+
9
+ ```js
10
+ import sfx, { PRESETS } from '@audio/synth-sfx'
11
+ ```
12
+
13
+ Game/UI sound-effect generator (ZZFX/sfxr class): one parameterized pipeline — shaped oscillator → frequency slide/vibrato/arpeggio → ADSR-ish envelope → optional lowpass/bitcrush — behind 8 named presets covering the sfxr archetypes (`pickup`, `laser`, `explosion`, `powerup`, `hit`, `jump`, `blip`, `coin`). Every field is overridable; noise is seeded, so renders are reproducible.
14
+
15
+ ```js
16
+ sfx('laser') // named preset
17
+ sfx('coin', { seed: 42 }) // preset + override
18
+ sfx({ freq: 500, shape: 'square' }) // full custom parameter object
19
+ ```
20
+
21
+ | Param | Default | |
22
+ |---|---|---|
23
+ | `preset` | `'blip'` | Preset name or full parameter object (positional) |
24
+ | `freq` | preset | Base frequency, Hz |
25
+ | `shape` | preset | `'sine'` \| `'square'` \| `'saw'` \| `'triangle'` \| `'noise'` |
26
+ | `slide` | `0` | Octaves/second exponential pitch slide |
27
+ | `vibrato` / `vibratoDepth` | `0` / `0.1` | Hz / depth |
28
+ | `arp` / `arpAt` | `0` / `0.05` | Frequency multiplier stepped at `arpAt` seconds |
29
+ | `attack` / `sustain` / `release` | `0.005` / `0.08` / `0.12` | Seconds |
30
+ | `lowpass` | `0` | One-pole lowpass cutoff, Hz (0 = off) |
31
+ | `crush` | `0` | 0..1 bitcrush amount |
32
+ | `amp` | `0.8` | Peak amplitude |
33
+ | `seed` | — | Noise PRNG seed |
34
+ | `fs` | `44100` | Sample rate |
35
+
36
+ **Use when:** deterministic game/UI SFX without shipping audio assets.
37
+
38
+ ---
39
+
40
+ Part of [@audio/synth](https://github.com/audiojs/synth) — the synth family umbrella.
41
+
42
+ MIT © [audiojs](https://github.com/audiojs)
package/audio.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ // Generated from the audio.js manifest (params metadata is the source of truth).
2
+ // Regenerate: node tools/dts.js in @audio/compile. Do not edit by hand.
3
+
4
+ /** Automatable number — scalar, `t => value` fn, or breakpoint curve {t, v} */
5
+ type Auto = number | ((t: number) => number) | { t: number[], v: number[] }
6
+ /** Per-block param values as delivered by hosts (numbers arrive as 1-length Float32Array) */
7
+ type Live = Record<string, Float32Array | string | boolean>
8
+ type Ctx = { sampleRate: number, maxBlockSize: number, maxChannels: number, currentTime: number, duration?: number, events?: readonly any[], emit?: (name: string, ...args: any[]) => void, [k: string]: unknown }
9
+ type Process = (inputs: Float32Array[][], outputs: Float32Array[][], params: Live) => void
10
+
11
+ /** Chainable-host options for 'sfx' */
12
+ export interface SfxOptions {
13
+ /** default "blip" */
14
+ "preset"?: "pickup" | "laser" | "explosion" | "powerup" | "hit" | "jump" | "blip" | "coin"
15
+ at?: number | string
16
+ duration?: number | string
17
+ }
18
+
19
+ export declare const sfx: {
20
+ (ctx: Ctx): Process
21
+ channels: {"inputs":[],"outputs":"any"}
22
+ streaming: false
23
+ params: {
24
+ /** default "blip" */
25
+ "preset": { type: "enum", values: ["pickup","laser","explosion","powerup","hit","jump","blip","coin"], default: "blip" }
26
+ }
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@audio/synth-sfx",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Game/UI sound effects generator — ZZFX / ChipTone class parameterized synthesis",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -19,15 +19,27 @@
19
19
  "main": "sfx.js",
20
20
  "exports": {
21
21
  ".": "./sfx.js",
22
- "./audio": "./audio.js",
22
+ "./audio": {
23
+ "types": "./audio.d.ts",
24
+ "default": "./audio.js"
25
+ },
23
26
  "./package.json": "./package.json"
24
27
  },
25
28
  "files": [
26
29
  "sfx.js",
27
- "audio.js"
30
+ "sfx.d.ts",
31
+ "audio.js",
32
+ "audio.d.ts"
28
33
  ],
34
+ "types": "sfx.d.ts",
29
35
  "publishConfig": {
30
36
  "access": "public"
31
37
  },
32
- "audio": "./audio.js"
38
+ "audio": "./audio.js",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/audiojs/synth.git",
42
+ "directory": "packages/synth-sfx"
43
+ },
44
+ "funding": "https://github.com/sponsors/audiojs"
33
45
  }
package/sfx.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ /** ZZFX/sfxr-class parameterized SFX generator — shaped osc → slide/vibrato/arp → envelope → lowpass/bitcrush. */
2
+ export type SfxPreset = 'pickup' | 'laser' | 'explosion' | 'powerup' | 'hit' | 'jump' | 'blip' | 'coin'
3
+
4
+ export interface SfxOptions {
5
+ /** base frequency, Hz */
6
+ freq?: number
7
+ /** waveform */
8
+ shape?: 'sine' | 'square' | 'saw' | 'triangle' | 'noise'
9
+ /** octaves/second exponential pitch slide, default 0 */
10
+ slide?: number
11
+ /** Hz, default 0 */
12
+ vibrato?: number
13
+ /** depth, default 0.1 */
14
+ vibratoDepth?: number
15
+ /** frequency multiplier stepped at arpAt, default 0 */
16
+ arp?: number
17
+ /** seconds, default 0.05 */
18
+ arpAt?: number
19
+ /** seconds, default 0.005 */
20
+ attack?: number
21
+ /** seconds, default 0.08 */
22
+ sustain?: number
23
+ /** seconds, default 0.12 */
24
+ release?: number
25
+ /** one-pole lowpass cutoff Hz, 0 = off, default 0 */
26
+ lowpass?: number
27
+ /** 0..1 bitcrush amount, default 0 */
28
+ crush?: number
29
+ /** sample rate, default 44100 */
30
+ fs?: number
31
+ /** peak amplitude, default 0.8 */
32
+ amp?: number
33
+ /** noise PRNG seed */
34
+ seed?: number
35
+ }
36
+
37
+ export const PRESETS: Record<SfxPreset, SfxOptions>
38
+
39
+ /** preset: named preset ('blip' default) or a full parameter object */
40
+ export default function sfx(preset?: SfxPreset | SfxOptions, options?: SfxOptions): Float32Array