@audio/effect-slew 1.1.5 → 1.1.7
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 +7 -4
- package/audio.js +18 -2
- package/package.json +4 -1
- package/slew-limiter.d.ts +1 -1
- package/slew-limiter.js +1 -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 'slew' */
|
|
@@ -21,10 +23,11 @@ export interface SlewOptions {
|
|
|
21
23
|
export declare const slew: {
|
|
22
24
|
(ctx: Ctx): Process
|
|
23
25
|
channels: "any"
|
|
26
|
+
tail: (at: { sampleRate: number, params: Live, buffers?: {}, transport: Transport }) => number
|
|
24
27
|
params: {
|
|
25
28
|
/** 10..20000 (default 1000) */
|
|
26
|
-
"rise": { type: "number", default: 1000 }
|
|
29
|
+
"rise": { type: "number", min: 10, max: 20000, default: 1000, curve: "log" }
|
|
27
30
|
/** 10..20000 (default 1000) */
|
|
28
|
-
"fall": { type: "number", default: 1000 }
|
|
31
|
+
"fall": { type: "number", min: 10, max: 20000, default: 1000, curve: "log" }
|
|
29
32
|
}
|
|
30
33
|
}
|
package/audio.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// atom manifest — wraps the slew-limiter atom; purely reactive rate-of-change
|
|
2
2
|
// clamp, no sizing params — every param stays live, per-channel state is just the
|
|
3
|
-
// running output sample.
|
|
3
|
+
// running output sample. The factory gives it as NaN, unseeded: a number from the start, so V8
|
|
4
|
+
// keeps it in place (added on the first block as 0, then made a double, it boxed once a second
|
|
5
|
+
// instance had run).
|
|
4
6
|
|
|
5
7
|
import slewLimiterFn from './slew-limiter.js'
|
|
6
8
|
|
|
7
9
|
export const slew = (ctx) => {
|
|
8
10
|
const chP = []
|
|
9
|
-
for (let c = 0, N = ctx.maxChannels ?? 8; c < N; c++) chP.push({ fs: ctx.sampleRate })
|
|
11
|
+
for (let c = 0, N = ctx.maxChannels ?? 8; c < N; c++) chP.push({ fs: ctx.sampleRate, y: NaN })
|
|
10
12
|
return (inputs, outputs, params) => {
|
|
11
13
|
const inp = inputs[0], out = outputs[0]
|
|
12
14
|
if (!inp || !inp.length) return
|
|
@@ -20,6 +22,20 @@ export const slew = (ctx) => {
|
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
slew.channels = 'any'
|
|
25
|
+
// once the input stops, the output falls to 0 at `fall` a second (or rises at `rise`, from below): a full-scale output,
|
|
26
|
+
// |y| ≤ 1, is there within 1 / min(rise, fall) seconds, and a held DC of ±1 against the slower of the two takes all of
|
|
27
|
+
// it. Louder signals take longer, in proportion. A ring of 128 frames or less needs no tail (CONTRACT 1.0).
|
|
28
|
+
// A planning snapshot's number that is not finite (automation whose values are not known yet) reserves the longer of
|
|
29
|
+
// the tails at the ends of its range, as effect-delay's tail reserves its maxima: through the formula it gave NaN, which
|
|
30
|
+
// a host takes as no tail, cutting the decay. Both ends are tried: the tail is longest at one or the other
|
|
31
|
+
const reserve = (f, tail) => function known (s) {
|
|
32
|
+
for (const k in f.params) if (f.params[k].type === 'number' && !Number.isFinite(s.params[k]?.[0])) {
|
|
33
|
+
const at = v => known({ ...s, params: { ...s.params, [k]: Float32Array.of(v) } })
|
|
34
|
+
return Math.max(at(f.params[k].min), at(f.params[k].max))
|
|
35
|
+
}
|
|
36
|
+
return tail(s)
|
|
37
|
+
}
|
|
38
|
+
slew.tail = reserve(slew, ({ sampleRate: fs, params }) => { let frames = Math.ceil(fs / Math.min(params.rise[0], params.fall[0])); return frames > 128 ? frames / fs : 0 })
|
|
23
39
|
slew.params = {
|
|
24
40
|
rise: { type: 'number', min: 10, max: 20000, default: 1000, curve: 'log' },
|
|
25
41
|
fall: { type: 'number', min: 10, max: 20000, default: 1000, curve: 'log' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audio/effect-slew",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Rate-of-change limiter",
|
|
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
|
"slew-limiter.js",
|
|
18
21
|
"audio.js",
|
package/slew-limiter.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export interface SlewLimiterOptions {
|
|
|
11
11
|
/**
|
|
12
12
|
* Mutates `data` in place and returns the same reference. Pass the same params
|
|
13
13
|
* object across calls — the running output sample persists on it (`y`, seeded
|
|
14
|
-
* from `data[0]` on the first call if absent).
|
|
14
|
+
* from `data[0]` on the first call if absent or NaN).
|
|
15
15
|
*/
|
|
16
16
|
export default function slewLimiter<T extends Float32Array | Float64Array>(data: T, params?: SlewLimiterOptions): T
|
package/slew-limiter.js
CHANGED
|
@@ -11,7 +11,7 @@ export default function slewLimiter (data, params = {}) {
|
|
|
11
11
|
let maxRise = rise / fs
|
|
12
12
|
let maxFall = fall / fs
|
|
13
13
|
|
|
14
|
-
let y = params.y
|
|
14
|
+
let y = params.y == null || params.y !== params.y ? data[0] : params.y // seeded from the first sample when absent or NaN
|
|
15
15
|
|
|
16
16
|
for (let i = 0, l = data.length; i < l; i++) {
|
|
17
17
|
let diff = data[i] - y
|