@audio/synth-poly 1.2.0 → 1.2.1

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 (3) hide show
  1. package/README.md +33 -3
  2. package/package.json +10 -2
  3. package/poly.d.ts +26 -0
package/README.md CHANGED
@@ -1,5 +1,35 @@
1
- # @audio/synth-poly
1
+ # @audio/synth-poly [![npm](https://img.shields.io/npm/v/@audio/synth-poly)](https://www.npmjs.com/package/@audio/synth-poly) [![MIT](https://img.shields.io/badge/MIT-%E0%A5%90-white)](https://github.com/krishnized/license)
2
2
 
3
- > Polyphonic voice allocator — wrap any voice with N-voice polyphony
3
+ N-voice allocator — oldest-note steal with 5 ms fade, {freq|midi} notes, any pitched generator as voice
4
4
 
5
- Planned — not implemented yet. See the umbrella README for status and sources.
5
+ ```
6
+ npm install @audio/synth-poly
7
+ ```
8
+
9
+ ```js
10
+ import poly from '@audio/synth-poly'
11
+ ```
12
+
13
+ Polyphonic voice allocator: renders a list of note events through any voice function with N-voice polyphony and oldest-note stealing (5 ms fade at the steal point, no click). The voice contract is the family's generator shape — `(freq, {fs, duration, velocity, ...voiceOpts}) => Float32Array` — every pitched `@audio/synth` generator satisfies it (`osc`, `pluck`, `fm`, `modal`, `drum`'s `membrane`/`metal`, `bell`, `epiano`, `risset`, `wavetable`…). Extra per-voice config (fm's `ratio`/`index`, modal's `model`, wavetable's `tables`) rides in via `voiceOpts`.
14
+
15
+ ```js
16
+ import osc from '@audio/synth-osc'
17
+ poly([{ time: 0, freq: 440, duration: 0.5 }, { time: 0.2, midi: 64 }], { voice: osc, voices: 8 })
18
+ ```
19
+
20
+ | Param | Default | |
21
+ |---|---|---|
22
+ | `notes` | — | `[{time, freq\|midi, duration=0.5, velocity=1}]` (positional) |
23
+ | `voice` | — | Required — `(freq, opts) => Float32Array` voice function |
24
+ | `voiceOpts` | `{}` | Extra options forwarded to every voice call |
25
+ | `voices` | `16` | Max simultaneous notes — oldest is stolen with a 5ms fade |
26
+ | `duration` | — | Total seconds; default: end of last note + 0.5 |
27
+ | `fs` | `44100` | Sample rate |
28
+
29
+ **Use when:** hosting any pitched generator polyphonically, or rendering MIDI: `poly(parse(smf).notes, { voice: pluck })` — see [`@audio/midi`](https://github.com/audiojs/midi).
30
+
31
+ ---
32
+
33
+ Part of [@audio/synth](https://github.com/audiojs/synth) — the synth family umbrella.
34
+
35
+ MIT © [audiojs](https://github.com/audiojs)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@audio/synth-poly",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Polyphonic voice allocator — wrap any voice with N-voice polyphony",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -25,9 +25,11 @@
25
25
  },
26
26
  "files": [
27
27
  "poly.js",
28
+ "poly.d.ts",
28
29
  "audio.js",
29
30
  "audio.d.ts"
30
31
  ],
32
+ "types": "poly.d.ts",
31
33
  "publishConfig": {
32
34
  "access": "public"
33
35
  },
@@ -35,5 +37,11 @@
35
37
  "dependencies": {
36
38
  "@audio/synth-voice": "^1.1.0",
37
39
  "@audio/note": "^1.0.0"
38
- }
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/audiojs/synth.git",
44
+ "directory": "packages/synth-poly"
45
+ },
46
+ "funding": "https://github.com/sponsors/audiojs"
39
47
  }
package/poly.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /** N-voice polyphonic allocator — oldest-note steal with 5ms fade, any pitched generator as voice. */
2
+ export interface PolyNote {
3
+ time?: number
4
+ freq?: number
5
+ midi?: number
6
+ duration?: number
7
+ velocity?: number
8
+ }
9
+
10
+ export type Voice = (freq: number, opts: { fs: number, duration: number, velocity: number, [key: string]: unknown }) => Float32Array
11
+
12
+ export interface PolyOptions {
13
+ /** required — voice function, family generator contract (freq, opts) => Float32Array */
14
+ voice: Voice
15
+ /** extra options forwarded to every voice call, default {} */
16
+ voiceOpts?: Record<string, unknown>
17
+ /** max simultaneous notes — oldest is stolen with a 5ms fade, default 16 */
18
+ voices?: number
19
+ /** total seconds; default: end of last note + 0.5 */
20
+ duration?: number
21
+ /** sample rate, default 44100 */
22
+ fs?: number
23
+ }
24
+
25
+ /** Returns the mono mix. */
26
+ export default function poly(notes: PolyNote[], options: PolyOptions): Float32Array