@audio/synth-chirp 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.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @audio/synth-chirp [![npm](https://img.shields.io/npm/v/@audio/synth-chirp)](https://www.npmjs.com/package/@audio/synth-chirp) [![MIT](https://img.shields.io/badge/MIT-%E0%A5%90-white)](https://github.com/krishnized/license)
2
+
3
+ Frequency sweep — exp/linear
4
+
5
+ ```
6
+ npm install @audio/synth-chirp
7
+ ```
8
+
9
+ ```js
10
+ import chirp from '@audio/synth-chirp'
11
+ ```
12
+
13
+ Frequency sweep generator. Exponential (log) sweep is the ESS measurement signal (Farina 2000, used by [`@audio/measure-ir`](https://github.com/audiojs/measure-ir)); linear sweep is for response plots. Instantaneous frequency: linear `f(t) = f0 + (f1-f0)·t/T`, exponential `f(t) = f0·(f1/f0)^(t/T)`. Unpitched — single opts argument, edges fade to avoid clicks.
14
+
15
+ ```js
16
+ chirp({ f0: 20, f1: 20000, duration: 1, method: 'exp' }) // → Float32Array
17
+ ```
18
+
19
+ | Param | Default | |
20
+ |---|---|---|
21
+ | `f0` | `20` | Start frequency, Hz |
22
+ | `f1` | `fs/2 · 0.95` | End frequency, Hz |
23
+ | `duration` | `1` | Seconds |
24
+ | `method` | `'exp'` | `'exp'` or `'lin'` |
25
+ | `amp` | `0.9` | Peak amplitude |
26
+ | `fade` | `0.005` | Edge fade, seconds (anti-click) |
27
+ | `fs` | `44100` | Sample rate |
28
+
29
+ **Use when:** measuring an impulse response (ESS deconvolution) or sweeping a filter/effect for a Bode-style plot.
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/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.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ /** Frequency sweep generator — exponential (ESS) or linear. */
2
+ export interface ChirpOptions {
3
+ /** start frequency, Hz, default 20 */
4
+ f0?: number
5
+ /** end frequency, Hz, default fs/2 * 0.95 */
6
+ f1?: number
7
+ /** seconds, default 1 */
8
+ duration?: number
9
+ /** sample rate, default 44100 */
10
+ fs?: number
11
+ /** sweep shape, default 'exp' */
12
+ method?: 'exp' | 'lin'
13
+ /** peak amplitude, default 0.9 */
14
+ amp?: number
15
+ /** edge fade, seconds, default 0.005 */
16
+ fade?: number
17
+ }
18
+
19
+ export default function chirp(options?: ChirpOptions): Float32Array
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,19 +1,25 @@
1
1
  {
2
2
  "name": "@audio/synth-chirp",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
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
+ "chirp.d.ts",
19
+ "audio.js",
20
+ "audio.d.ts"
16
21
  ],
22
+ "types": "chirp.d.ts",
17
23
  "keywords": [
18
24
  "audio",
19
25
  "dsp",
@@ -30,5 +36,11 @@
30
36
  "publishConfig": {
31
37
  "access": "public"
32
38
  },
33
- "audio": "./audio.js"
39
+ "audio": "./audio.js",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/audiojs/synth.git",
43
+ "directory": "packages/synth-chirp"
44
+ },
45
+ "funding": "https://github.com/sponsors/audiojs"
34
46
  }