@audio/synth-voice 1.2.0 → 1.3.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/audio.d.ts +11 -9
  2. package/audio.js +3 -2
  3. package/package.json +4 -1
package/audio.d.ts CHANGED
@@ -1,11 +1,13 @@
1
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.
2
+ // Regenerate: node tools/dts.js in @audio/plugin. Do not edit by hand.
3
3
 
4
4
  /** Automatable number — scalar, `t => value` fn, or breakpoint curve {t, v} */
5
5
  type Auto = number | ((t: number) => number) | { t: number[], v: number[] }
6
6
  /** Per-block param values as delivered by hosts (numbers arrive as 1-length Float32Array) */
7
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 }
8
+ type Transport = Readonly<{ playing: boolean, bpm: number, beat: number, barStart: number, timeSig: [number, number] }>
9
+ /** What a host hands a processor it builds: the contract's Context (CONTRACT.d.ts, 1.0) */
10
+ type Ctx = { readonly sampleRate: number, readonly maxBlockSize: number, readonly maxChannels: number, readonly layouts?: { readonly inputs: readonly (string | undefined)[], readonly outputs: readonly (string | undefined)[] }, readonly params: Live, readonly buffers: Readonly<Record<string, Float32Array[] | undefined>>, readonly events?: readonly { time: number, kind: 'on' | 'off', midi: number, velocity: number, id: number }[], emit(name: string, value: number): void, readonly transport: Transport }
9
11
  type Process = (inputs: Float32Array[][], outputs: Float32Array[][], params: Live) => void
10
12
 
11
13
  /** Chainable-host options for 'voice' */
@@ -40,18 +42,18 @@ export declare const voice: {
40
42
  /** default "sawtooth" */
41
43
  "type": { type: "enum", values: ["sine","square","sawtooth","triangle"], default: "sawtooth" }
42
44
  /** 0.001..2 s (default 0.01) */
43
- "attack": { type: "number", default: 0.01 }
45
+ "attack": { type: "number", min: 0.001, max: 2, default: 0.01, unit: "s", curve: "log" }
44
46
  /** 0.001..2 s (default 0.15) */
45
- "decay": { type: "number", default: 0.15 }
47
+ "decay": { type: "number", min: 0.001, max: 2, default: 0.15, unit: "s", curve: "log" }
46
48
  /** 0..1 (default 0.6) */
47
- "sustain": { type: "number", default: 0.6 }
49
+ "sustain": { type: "number", min: 0, max: 1, default: 0.6 }
48
50
  /** 0.001..4 s (default 0.25) */
49
- "release": { type: "number", default: 0.25 }
51
+ "release": { type: "number", min: 0.001, max: 4, default: 0.25, unit: "s", curve: "log" }
50
52
  /** 100..16000 Hz (default 3000) */
51
- "fc": { type: "number", default: 3000, alias: "cutoff" }
53
+ "fc": { type: "number", min: 100, max: 16000, default: 3000, unit: "Hz", curve: "log", alias: "cutoff" }
52
54
  /** 0..1 (default 0.6) */
53
- "envAmount": { type: "number", default: 0.6 }
55
+ "envAmount": { type: "number", min: 0, max: 1, default: 0.6 }
54
56
  /** 0..1 (default 0.7) */
55
- "amp": { type: "number", default: 0.7 }
57
+ "amp": { type: "number", min: 0, max: 1, default: 0.7 }
56
58
  }
57
59
  }
package/audio.js CHANGED
@@ -19,7 +19,7 @@ export const voice = (ctx) => {
19
19
  const evs = ctx.events || []
20
20
  const on = new Map()
21
21
  const render = (slot, endSample) => {
22
- const freq = midiToHz(slot.pitch)
22
+ const freq = midiToHz(slot.midi)
23
23
  const dur = Math.max(0.01, (endSample - slot.time) / sr)
24
24
  const d = voiceFn(freq, {
25
25
  fs: sr, duration: dur,
@@ -33,7 +33,8 @@ export const voice = (ctx) => {
33
33
  }
34
34
  for (let i = 0; i < evs.length; i++) {
35
35
  const e = evs[i]
36
- if (e.kind === 'on') on.set(e.id, { time: e.time, pitch: e.pitch, velocity: e.velocity })
36
+ // a host older than contract 1.0 names the note number `pitch`
37
+ if (e.kind === 'on') on.set(e.id, { time: e.time, midi: e.midi ?? e.pitch, velocity: e.velocity })
37
38
  else if (e.kind === 'off' && on.has(e.id)) { render(on.get(e.id), e.time); on.delete(e.id) }
38
39
  }
39
40
  for (const slot of on.values()) render(slot, n) // unterminated notes ring to the end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@audio/synth-voice",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Synth voice — osc × ADSR through envelope-scaled lowpass (Tone.js Synth class)",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -13,6 +13,9 @@
13
13
  },
14
14
  "./package.json": "./package.json"
15
15
  },
16
+ "scripts": {
17
+ "prepublishOnly": "node ../../../compile/tools/tested.js"
18
+ },
16
19
  "files": [
17
20
  "voice.js",
18
21
  "voice.d.ts",