@audio/effect-exciter 1.2.1 → 1.2.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/audio.d.ts +8 -5
- package/audio.js +42 -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/
|
|
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
|
|
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 'exciter' */
|
|
@@ -25,12 +27,13 @@ export interface ExciterOptions {
|
|
|
25
27
|
export declare const exciter: {
|
|
26
28
|
(ctx: Ctx): Process
|
|
27
29
|
channels: "any"
|
|
30
|
+
tail: (at: { sampleRate: number, params: Live, buffers?: {}, transport: Transport }) => number
|
|
28
31
|
params: {
|
|
29
32
|
/** 500..8000 Hz (default 3000) */
|
|
30
|
-
"fc": { type: "number", default: 3000, alias: "freq" }
|
|
33
|
+
"fc": { type: "number", min: 500, max: 8000, default: 3000, unit: "Hz", curve: "log", smoothing: 0.02, alias: "freq" }
|
|
31
34
|
/** 0..1 (default 0.5) */
|
|
32
|
-
"drive": { type: "number", default: 0.5 }
|
|
35
|
+
"drive": { type: "number", min: 0, max: 1, default: 0.5 }
|
|
33
36
|
/** 0..1 (default 0.5) */
|
|
34
|
-
"amount": { type: "number", default: 0.5 }
|
|
37
|
+
"amount": { type: "number", min: 0, max: 1, default: 0.5 }
|
|
35
38
|
}
|
|
36
39
|
}
|
package/audio.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// atom manifest — wraps the exciter atom; SVF filter state, no sizing params —
|
|
2
|
-
// every param stays live, per-channel state is just the running filter integrators
|
|
2
|
+
// every param stays live, per-channel state is just the running filter integrators,
|
|
3
|
+
// made here so the first block sets nothing up. fc retunes the highpass each call, smoothed so
|
|
4
|
+
// that a host ramps it.
|
|
3
5
|
|
|
4
6
|
import exciterFn from './exciter.js'
|
|
5
7
|
|
|
6
8
|
export const exciter = (ctx) => {
|
|
7
9
|
const chP = []
|
|
8
|
-
for (let c = 0, N = ctx.maxChannels ?? 8; c < N; c++) chP.push({ fs: ctx.sampleRate })
|
|
10
|
+
for (let c = 0, N = ctx.maxChannels ?? 8; c < N; c++) chP.push({ fs: ctx.sampleRate, _lp: 0, _bp: 0 })
|
|
9
11
|
return (inputs, outputs, params) => {
|
|
10
12
|
const inp = inputs[0], out = outputs[0]
|
|
11
13
|
if (!inp || !inp.length) return
|
|
@@ -20,8 +22,45 @@ export const exciter = (ctx) => {
|
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
exciter.channels = 'any'
|
|
25
|
+
// The tail (CONTRACT 1.0: until the output stays 60 dB under the input's level) by the rule for a fixed linear filter:
|
|
26
|
+
// the frames after an input stops until the rest of Σ|h| is under eps, h the impulse response. A peak-1 input then
|
|
27
|
+
// leaves at most eps, and a held tone at a resonance, or DC into a loop, comes within a few percent of it, so the gain
|
|
28
|
+
// the ring starts at is in the count. `make` returns [tick, energy]: tick(x) runs a frame, energy() sums the squares of
|
|
29
|
+
// the state. h runs until that energy has fallen 200 dB from its largest, past which what is left is negligible, then
|
|
30
|
+
// again from the impulse, the rest being the sum less what has passed; Infinity where it has not fallen so far in 2^22
|
|
31
|
+
// frames
|
|
32
|
+
const rest = (make, eps) => {
|
|
33
|
+
let [tick, energy] = make(), sum = 0, top = 0, n = 0
|
|
34
|
+
for (; n < 2 ** 22; n++) { sum += Math.abs(tick(n ? 0 : 1)); let e = energy(); if (e > top) top = e; else if (n > 64 && e <= 1e-20 * top) break }
|
|
35
|
+
if (n === 2 ** 22) return Infinity
|
|
36
|
+
tick = make()[0]
|
|
37
|
+
for (let j = 0; j < n; j++) if ((sum -= Math.abs(tick(j ? 0 : 1))) <= eps) return j
|
|
38
|
+
return n
|
|
39
|
+
}
|
|
40
|
+
// the highpass frozen at f, as exciter.js runs it: the trapezoidal SVF at g = tan(π f / fs), damping k
|
|
41
|
+
const highpass = (f, k, fs) => () => {
|
|
42
|
+
let g = Math.tan(Math.PI * Math.min(f, 0.49 * fs) / fs), a = 1 / (1 + g * (g + k)), lp = 0, bp = 0
|
|
43
|
+
return [x => { let v1 = a * (bp + g * (x - lp)), v2 = lp + g * v1; bp = 2 * v1 - bp; lp = 2 * v2 - lp; return x - k * v1 - v2 }, () => lp * lp + bp * bp]
|
|
44
|
+
}
|
|
45
|
+
// A planning snapshot's number that is not finite (automation whose values are not known yet) reserves the longer of
|
|
46
|
+
// the tails at the ends of its range, as effect-delay's tail reserves its maxima: through the formula it gave NaN, which
|
|
47
|
+
// a host takes as no tail, cutting the decay. Both ends are tried: the ring is longest at one or the other
|
|
48
|
+
const reserve = (f, tail) => function known (s) {
|
|
49
|
+
for (const k in f.params) if (f.params[k].type === 'number' && !Number.isFinite(s.params[k]?.[0])) {
|
|
50
|
+
const at = v => known({ ...s, params: { ...s.params, [k]: Float32Array.of(v) } })
|
|
51
|
+
return Math.max(at(f.params[k].min), at(f.params[k].max))
|
|
52
|
+
}
|
|
53
|
+
return tail(s)
|
|
54
|
+
}
|
|
55
|
+
// What the input leaves is 0.5 · amount · tanh(g · hp), g = 1 + 9 · drive (exciter.js): at most 0.5 · amount · g · |hp|,
|
|
56
|
+
// the saturator's slope at 0, which a quiet input meets; so the highpass's rest is held under 1e-3 over that gain. A ring
|
|
57
|
+
// of 128 frames or less needs no tail (CONTRACT 1.0)
|
|
58
|
+
exciter.tail = reserve(exciter, ({ sampleRate: fs, params }) => {
|
|
59
|
+
let gain = 0.5 * params.amount[0] * (1 + 9 * params.drive[0]), n = gain > 1e-3 ? rest(highpass(params.fc[0], 0.5, fs), 1e-3 / gain) : 0
|
|
60
|
+
return n > 128 ? n / fs : 0
|
|
61
|
+
})
|
|
23
62
|
exciter.params = {
|
|
24
|
-
fc: { type: 'number', min: 500, max: 8000, default: 3000, unit: 'Hz', curve: 'log', alias: 'freq' },
|
|
63
|
+
fc: { type: 'number', min: 500, max: 8000, default: 3000, unit: 'Hz', curve: 'log', alias: 'freq', smoothing: 0.02 },
|
|
25
64
|
drive: { type: 'number', min: 0, max: 1, default: 0.5 },
|
|
26
65
|
amount: { type: 'number', min: 0, max: 1, default: 0.5 },
|
|
27
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/effect-exciter",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Exciter — psychoacoustic harmonic synthesis for presence/air",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"default": "./audio.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prepublishOnly": "node ../../../compile/tools/tested.js"
|
|
18
|
+
},
|
|
16
19
|
"files": [
|
|
17
20
|
"exciter.js",
|
|
18
21
|
"audio.js",
|