@audio/synth-chirp 1.1.1 → 1.1.2

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 +39 -0
  2. package/chirp.js +7 -2
  3. package/package.json +7 -3
package/audio.d.ts ADDED
@@ -0,0 +1,39 @@
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 'chirp' */
12
+ export interface ChirpOptions {
13
+ /** 1..20000 Hz (default 20) */
14
+ "f0"?: Auto
15
+ /** 1..22050 Hz (default 20000) */
16
+ "f1"?: Auto
17
+ /** default "exp" */
18
+ "method"?: "exp" | "linear"
19
+ /** 0..1 (default 0.9) */
20
+ "amp"?: Auto
21
+ at?: number | string
22
+ duration?: number | string
23
+ }
24
+
25
+ export declare const chirp: {
26
+ (ctx: Ctx): Process
27
+ channels: {"inputs":[],"outputs":"any"}
28
+ streaming: false
29
+ params: {
30
+ /** 1..20000 Hz (default 20) */
31
+ "f0": { type: "number", default: 20 }
32
+ /** 1..22050 Hz (default 20000) */
33
+ "f1": { type: "number", default: 20000 }
34
+ /** default "exp" */
35
+ "method": { type: "enum", values: ["exp","linear"], default: "exp" }
36
+ /** 0..1 (default 0.9) */
37
+ "amp": { type: "number", default: 0.9 }
38
+ }
39
+ }
package/chirp.js CHANGED
@@ -11,12 +11,17 @@ export default function chirp ({ f0 = 20, f1, duration = 1, fs = 44100, method =
11
11
  f1 ||= fs / 2 * 0.95
12
12
  let n = Math.round(duration * fs)
13
13
  let d = new Float32Array(n)
14
- if (method === 'exp') {
15
- let L = duration / Math.log(f1 / f0)
14
+ let R = Math.log(f1 / f0)
15
+ if (method === 'exp' && Math.abs(R) > 1e-9) {
16
+ let L = duration / R
16
17
  for (let i = 0; i < n; i++) {
17
18
  let t = i / fs
18
19
  d[i] = amp * Math.sin(2 * Math.PI * f0 * L * (Math.exp(t / L) - 1))
19
20
  }
21
+ } else if (method === 'exp') {
22
+ // degenerate sweep (f1 === f0): the analytic limit is a constant tone —
23
+ // L = duration/log(1) would be ∞ → NaN
24
+ for (let i = 0; i < n; i++) d[i] = amp * Math.sin(2 * Math.PI * f0 * i / fs)
20
25
  } else {
21
26
  let k = (f1 - f0) / duration
22
27
  for (let i = 0; i < n; i++) {
package/package.json CHANGED
@@ -1,18 +1,22 @@
1
1
  {
2
2
  "name": "@audio/synth-chirp",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Chirp — linear/exponential frequency sweep (ESS measurement signal, Farina 2000)",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "chirp.js",
8
8
  "exports": {
9
9
  ".": "./chirp.js",
10
- "./audio": "./audio.js",
10
+ "./audio": {
11
+ "types": "./audio.d.ts",
12
+ "default": "./audio.js"
13
+ },
11
14
  "./package.json": "./package.json"
12
15
  },
13
16
  "files": [
14
17
  "chirp.js",
15
- "audio.js"
18
+ "audio.js",
19
+ "audio.d.ts"
16
20
  ],
17
21
  "keywords": [
18
22
  "audio",