Skip to content

Commit d6429c4

Browse files
committed
feat: one knob for the five effects that cannot honestly have one
The last unbuilt piece of the rack design. A compressor has seven controls and an author wants one — but unlike a filter or a delay, no single one of them can be its face: threshold means nothing without ratio, ratio means nothing without make-up gain. So the knob is derived, exactly as `carveProfile` already turns one number into six for the carve. `EFFECT_COPY[id].primary === "strength"` was already the copy layer saying "this module wants this treatment", and a test now asserts the profile set matches that list exactly — a missing profile leaves a module opening on all seven controls, and an extra one is a knob nobody asked for. **Continuous, not the three-point tables the design proposed.** A table makes gentle/middle/strong three settings to pick between, and the thing being modelled is one axis — which the carve's knob has already proved reads. The proposal's figures survive as anchors where they held up. ## Three of the five figures were wrong, and rendering is what showed it Full numbers and method in `~/audio-fx-profiles-ab/README.md`. - **Compressor make-up was too small and not linear.** 1/3/7 dB left the track 2.5 dB QUIETER at full evenness — an evenness knob that turns the track down as it goes up. Gain reduction accelerates as threshold and ratio move together, so linear was wrong too; solved as s² × 9.5. Spread now falls 19.1 → 8.8 dB with the level unmoved. - **Saturation's trim went the wrong way.** A soft clipper at −18 dB IS a limiter at −18 dB: the proposed −3 dB trim took the peak from 0.496 to 0.089 and nearly halved RMS, so "Warmth" mostly meant "much quieter". Reversed to s² × 2.8 up; RMS now holds within 0.4% while the peak comes down, which is the signature of saturation rather than attenuation. - **The gate did essentially nothing.** The design derived threshold and range only; left at the effect's 100 ms default release it moved the gaps 0.1 dB against a range asking for 30. Swept, release dominates everything else — 0.2 dB at 140 ms, 13.4 dB at 10 ms — so it joins the profile. Gaps now fall 29.6 dB with speech unmoved to a tenth of a dB. Reverb and bitcrush measured correctly as proposed and are unchanged. The first measurement reported the gate as working when it was doing nothing at all: a speaking-window measure excludes exactly the windows a gate acts on. Gaps are measured separately for that reason. ## In the panel The derived knob renders through the ordinary `FxParamRow`, not through `FxNodeParams` — it has no AudioParam behind it and nothing to automate. What automation there is belongs to the parameters it sets, under Details, where they can be aimed at individually. It writes mechanism, never the knob: the chain stores what renders, and `audioFxProfileStrength` reads the knob back by inverting the curve — the same contract `normalizeCarveSettings` has. A profile merges over what is there, so a compressor's knee and a saturation's curve type survive the knob moving. Falsified: a derived parameter that turns around mid-sweep, one that runs past its range, a profile that replaces rather than merges, and a panel that writes the knob instead of the mechanism each fail a test. core 1762 (113 files) · studio 3695 + 18 todo.
1 parent a7e8e7f commit d6429c4

6 files changed

Lines changed: 460 additions & 17 deletions

File tree

packages/core/package-subpaths.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@
9898
"types": "./dist/audioFxCopy.d.ts",
9999
"environments": ["browser", "bun", "node"]
100100
},
101+
"./audio-fx-profiles": {
102+
"source": "./src/audioFxProfiles.ts",
103+
"runtime": "./dist/audioFxProfiles.js",
104+
"types": "./dist/audioFxProfiles.d.ts",
105+
"environments": ["browser", "bun", "node"]
106+
},
101107
"./audio-fx-jobs": {
102108
"source": "./src/audioFxJobs.ts",
103109
"runtime": "./dist/audioFxJobs.js",

packages/core/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@
112112
"import": "./src/audioFxCopy.ts",
113113
"types": "./src/audioFxCopy.ts"
114114
},
115+
"./audio-fx-profiles": {
116+
"bun": "./src/audioFxProfiles.ts",
117+
"node": "./dist/audioFxProfiles.js",
118+
"import": "./src/audioFxProfiles.ts",
119+
"types": "./src/audioFxProfiles.ts"
120+
},
115121
"./audio-fx-jobs": {
116122
"bun": "./src/audioFxJobs.ts",
117123
"node": "./dist/audioFxJobs.js",
@@ -426,6 +432,10 @@
426432
"import": "./dist/audioFxCopy.js",
427433
"types": "./dist/audioFxCopy.d.ts"
428434
},
435+
"./audio-fx-profiles": {
436+
"import": "./dist/audioFxProfiles.js",
437+
"types": "./dist/audioFxProfiles.d.ts"
438+
},
429439
"./audio-fx-jobs": {
430440
"import": "./dist/audioFxJobs.js",
431441
"types": "./dist/audioFxJobs.d.ts"
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import { describe, expect, it } from "vitest";
2+
import { defaultAudioFxParams, getAudioFxDef } from "./audioFx.js";
3+
import { EFFECT_COPY } from "./audioFxCopy.js";
4+
import {
5+
applyAudioFxProfile,
6+
audioFxProfileStrength,
7+
getAudioFxProfile,
8+
HF_AUDIO_FX_PROFILES,
9+
} from "./audioFxProfiles.js";
10+
11+
describe("derived one-knob profiles", () => {
12+
it("covers exactly the effects whose copy asks for one", () => {
13+
// `primary: "strength"` is the copy layer saying "this module has no real
14+
// parameter that can honestly be its face". A profile missing for one of
15+
// those leaves the module opening on all seven of its controls; a profile
16+
// for anything else is a knob nobody asked for.
17+
const asked = Object.entries(EFFECT_COPY)
18+
.filter(([, copy]) => copy.primary === "strength")
19+
.map(([id]) => id)
20+
.sort();
21+
expect(Object.keys(HF_AUDIO_FX_PROFILES).sort()).toEqual(asked);
22+
});
23+
24+
it("derives only parameters the effect actually has", () => {
25+
for (const [id, profile] of Object.entries(HF_AUDIO_FX_PROFILES)) {
26+
const keys = getAudioFxDef(id)?.params.map((p) => p.key) ?? [];
27+
for (const key of profile.derives) {
28+
expect(keys, `${id} derives "${key}", which it does not have`).toContain(key);
29+
}
30+
// And the curve sets everything it claims to.
31+
for (const key of profile.derives) {
32+
expect(profile.at(0.5)[key], `${id}.${key} is not set at 0.5`).toBeDefined();
33+
}
34+
}
35+
});
36+
37+
it("stays inside every parameter's declared range across the whole knob", () => {
38+
// A profile that runs past a range is not clipped by the panel — it is
39+
// clamped on the way into the chain, so the knob would silently stop
40+
// meaning anything past that point.
41+
for (const [id, profile] of Object.entries(HF_AUDIO_FX_PROFILES)) {
42+
const def = getAudioFxDef(id);
43+
for (let s = 0; s <= 1.0001; s += 0.05) {
44+
const derived = profile.at(s);
45+
for (const param of def?.params ?? []) {
46+
const value = derived[param.key];
47+
if (value === undefined || param.kind !== "number") continue;
48+
expect(value, `${id}.${param.key} at ${s.toFixed(2)}`).toBeGreaterThanOrEqual(param.min);
49+
expect(value, `${id}.${param.key} at ${s.toFixed(2)}`).toBeLessThanOrEqual(param.max);
50+
}
51+
}
52+
}
53+
});
54+
55+
it("moves every derived parameter monotonically", () => {
56+
// The whole promise of one knob: everything under it moves together and in
57+
// one direction. A parameter that turns around mid-sweep means the knob
58+
// makes the effect stronger and then weaker, which is unusable and is the
59+
// failure a hand-tuned table invites.
60+
for (const [id, profile] of Object.entries(HF_AUDIO_FX_PROFILES)) {
61+
for (const key of profile.derives) {
62+
const series: number[] = [];
63+
for (let s = 0; s <= 1.0001; s += 0.05) {
64+
const value = profile.at(s)[key];
65+
if (typeof value === "number") series.push(value);
66+
}
67+
const up = series.every((v, i) => i === 0 || v >= (series[i - 1] ?? v));
68+
const down = series.every((v, i) => i === 0 || v <= (series[i - 1] ?? v));
69+
expect(up || down, `${id}.${key} turns around mid-sweep`).toBe(true);
70+
}
71+
}
72+
});
73+
74+
it("keeps what the author set under Details", () => {
75+
// A profile names only the parameters it derives. A compressor's knee and a
76+
// saturation's curve type are the author's, and the knob must not reach in
77+
// and reset them on the way past.
78+
const params = { ...defaultAudioFxParams("compressor"), knee: 6, mix: 0.5 };
79+
const next = applyAudioFxProfile("compressor", 0.8, params);
80+
expect(next.knee).toBe(6);
81+
expect(next.mix).toBe(0.5);
82+
expect(next.ratio).not.toBe(params.ratio);
83+
});
84+
85+
it("reads a strength back out of the values a chain stores", () => {
86+
// A chain stores mechanism, not the knob — the mechanism is what renders,
87+
// so it has to be authoritative. Reopening a project has to put the knob
88+
// back where it was.
89+
for (const [id, profile] of Object.entries(HF_AUDIO_FX_PROFILES)) {
90+
for (const s of [0, 0.25, 0.5, 0.75, 1]) {
91+
const params = applyAudioFxProfile(id, s, defaultAudioFxParams(id));
92+
expect(audioFxProfileStrength(id, params), `${id} at ${s}`).toBeCloseTo(s, 1);
93+
}
94+
void profile;
95+
}
96+
});
97+
98+
it("passes through the figures the design proposed", () => {
99+
// The curves replaced a three-point table, and these are the points it
100+
// named. Continuous beats three settings, but not at the price of landing
101+
// somewhere else than the design said.
102+
expect(getAudioFxProfile("compressor")?.at(0).threshold).toBe(-12);
103+
expect(getAudioFxProfile("compressor")?.at(0.5).ratio).toBe(4);
104+
expect(getAudioFxProfile("compressor")?.at(1).release).toBe(90);
105+
expect(getAudioFxProfile("gate")?.at(0).threshold).toBe(-55);
106+
expect(getAudioFxProfile("saturate")?.at(1).threshold).toBe(-18);
107+
expect(getAudioFxProfile("reverb")?.at(0).size).toBe(0.25);
108+
expect(getAudioFxProfile("reverb")?.at(0.5).size).toBe(0.55);
109+
expect(getAudioFxProfile("reverb")?.at(1).size).toBe(0.9);
110+
expect(getAudioFxProfile("bitcrush")?.at(1).bits).toBe(6);
111+
});
112+
113+
it("takes a value that is not a number as the middle", () => {
114+
// The knob has to land somewhere, and silence is the one answer that is
115+
// never right.
116+
expect(getAudioFxProfile("reverb")?.at(Number.NaN).size).toBe(
117+
getAudioFxProfile("reverb")?.at(0.5).size,
118+
);
119+
expect(audioFxProfileStrength("reverb", {})).toBe(0.5);
120+
expect(audioFxProfileStrength("not-an-effect", {})).toBe(0.5);
121+
});
122+
});
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/**
2+
* One knob over several, for the five effects that cannot honestly have one
3+
* real parameter nominated as the control that matters.
4+
*
5+
* A compressor has seven controls and an author wants one. The rest of the rack
6+
* opens on a single real parameter — a filter's frequency, a delay's mix — but
7+
* these five have no such parameter: threshold means nothing without ratio,
8+
* ratio means nothing without make-up gain, and picking any one of them as the
9+
* face of the module would be a knob that lies about what it sets.
10+
*
11+
* So they get a derived one, exactly as the carve already does: `carveProfile`
12+
* turns a single 0..1 into six numbers, and these do the same for the rest of
13+
* the rack. `EFFECT_COPY[id].primary` is `"strength"` for precisely these five,
14+
* which is what says a module wants this treatment.
15+
*
16+
* Continuous rather than the three-point tables the design proposed. A table
17+
* makes gentle/middle/strong three settings an author picks between, and the
18+
* thing being modelled is not three settings — it is one axis, and the carve's
19+
* knob has proved that reads. The proposal's figures survive as the anchors:
20+
* each curve passes through them at 0, 0.5 and 1.
21+
*
22+
* Every number below is expressed in the parameter's own registry unit and then
23+
* clamped by `normalizeAudioFxParams` on the way into the chain, so a profile
24+
* cannot ship a value the effect would refuse.
25+
*/
26+
27+
import { normalizeAudioFxParams, type HfAudioFxParamValues } from "./audioFx.js";
28+
29+
/** 0..1, whatever arrives. NaN reads as the middle rather than as silence. */
30+
function clamp01(strength: number): number {
31+
return Number.isFinite(strength) ? Math.min(1, Math.max(0, strength)) : 0.5;
32+
}
33+
34+
/** Two decimal places, so a derived value reads as a setting and not as float noise. */
35+
function to2(value: number): number {
36+
return Number(value.toFixed(2));
37+
}
38+
39+
export interface HfAudioFxProfile {
40+
/** What the one knob is called. Never the DSP name of anything it drives. */
41+
label: string;
42+
/** What the two ends sound like — the question an author actually has. */
43+
ends: { low: string; high: string };
44+
/** The parameters it sets. Everything else keeps the effect's own default. */
45+
derives: readonly string[];
46+
/** The mechanism values at a given strength. */
47+
at(strength: number): HfAudioFxParamValues;
48+
}
49+
50+
export const HF_AUDIO_FX_PROFILES: Record<string, HfAudioFxProfile> = {
51+
compressor: {
52+
label: "Evenness",
53+
ends: { low: "Barely touched", high: "Very even, quite squashed" },
54+
derives: ["threshold", "ratio", "attack", "release", "makeup"],
55+
at(strength) {
56+
const s = clamp01(strength);
57+
return {
58+
// Lower threshold and higher ratio together: more of the signal is
59+
// caught, and what is caught is held harder. Moving one without the
60+
// other is the pair of knobs this exists to stop an author meeting.
61+
threshold: to2(-12 - s * 18),
62+
ratio: to2(2 + s * 4),
63+
// Faster as it gets firmer, because a firm compressor that lets peaks
64+
// through is doing the audible half of its job and not the useful half.
65+
attack: to2(25 - s * 20),
66+
release: to2(300 - s * 210),
67+
// Compression makes things quieter; this is the level put back, and it
68+
// has to rise with the amount taken off or the knob reads as a volume
69+
// control that goes the wrong way.
70+
//
71+
// Solved from measurement rather than proposed, and it is not linear:
72+
// gain reduction accelerates as the threshold drops and the ratio rises
73+
// together, so a straight line is too loud in the middle and too quiet
74+
// at the top. The design's 1/3/7 dB left the track +0.9 dB at rest,
75+
// +1.3 dB at the middle and −2.5 dB at full. Numbers in
76+
// `~/audio-fx-profiles-ab/README.md`.
77+
makeup: to2(s * s * 9.5),
78+
};
79+
},
80+
},
81+
82+
gate: {
83+
label: "Tightness",
84+
ends: { low: "Only true silence", high: "Cuts quiet words too" },
85+
derives: ["threshold", "range", "release"],
86+
at(strength) {
87+
const s = clamp01(strength);
88+
return {
89+
threshold: to2(-55 + s * 23),
90+
// How far the gaps are ducked, never to silence: a room that stops dead
91+
// between sentences sounds broken rather than clean.
92+
range: to2(-10 - s * 20),
93+
// Release has to come along, which the design did not have — and it
94+
// dominates: swept against a fixed threshold and range, the gaps move
95+
// 0.2 dB at 140 ms and 13.4 dB at 10 ms. Left at the effect's 100 ms
96+
// default the gate was very nearly inaudible whatever else it was told.
97+
//
98+
// Measured on narration, speech level is unmoved (−24.0 dB) at every
99+
// release down to 10 ms, so the usual reason to stay slow — clipping
100+
// word endings — does not bite on this material at these thresholds.
101+
release: to2(120 - s * 105),
102+
};
103+
},
104+
},
105+
106+
saturate: {
107+
label: "Warmth",
108+
ends: { low: "Just a sheen", high: "Openly distorted" },
109+
derives: ["threshold", "output"],
110+
at(strength) {
111+
const s = clamp01(strength);
112+
return {
113+
// Drive: the lower the threshold, the more of the signal meets the
114+
// curve.
115+
threshold: to2(-3 - s * 15),
116+
// Up, not down — which reverses the design's figure, on the measurement
117+
// that motivated taking one. A soft clipper at -18 dB threshold IS a
118+
// limiter at -18 dB: peak fell to 0.089 from 0.496 and RMS almost
119+
// halved, so the proposed trim of −3 dB made "warmer" mean "much
120+
// quieter" and an author would have heard the level, not the warmth.
121+
// Accelerating for the same reason as the compressor's make-up.
122+
output: to2(s * s * 2.8),
123+
};
124+
},
125+
},
126+
127+
reverb: {
128+
label: "Space",
129+
ends: { low: "A small tight room", high: "A big open hall" },
130+
derives: ["size", "wet", "dry"],
131+
at(strength) {
132+
const s = clamp01(strength);
133+
return {
134+
// Anchored at the design's three figures — 0.25 / 0.55 / 0.90 — which a
135+
// single linear run cannot hit, because 0.55 is not their midpoint.
136+
size: to2(s <= 0.5 ? 0.25 + s * 0.6 : 0.55 + (s - 0.5) * 0.7),
137+
wet: to2(0.15 + s * 0.3),
138+
// Dry comes down as wet goes up, but not by the same amount: the two
139+
// legs sum, and matching them exactly makes a big room quieter than a
140+
// small one instead of further away.
141+
dry: to2(0.92 - s * 0.2),
142+
};
143+
},
144+
},
145+
146+
bitcrush: {
147+
label: "Crush",
148+
ends: { low: "Slightly gritty", high: "Destroyed" },
149+
derives: ["bits", "samples", "mix"],
150+
at(strength) {
151+
const s = clamp01(strength);
152+
return {
153+
// Fewer steps and longer holds. `bits` runs DOWN as the knob runs up,
154+
// which is why it cannot be the module's face on its own.
155+
bits: to2(14 - s * 8),
156+
samples: Math.max(1, Math.round(1 + s * 3)),
157+
mix: to2(0.25 + s * 0.75),
158+
};
159+
},
160+
},
161+
};
162+
163+
export function getAudioFxProfile(type: string): HfAudioFxProfile | undefined {
164+
return HF_AUDIO_FX_PROFILES[type];
165+
}
166+
167+
/**
168+
* The parameters a profile sets at this strength, merged over what is there.
169+
*
170+
* Merged rather than replacing: a profile names only the parameters it derives,
171+
* and the rest — a compressor's knee, a saturation's curve type — are the
172+
* author's to set under Details and must survive the knob moving.
173+
*/
174+
export function applyAudioFxProfile(
175+
type: string,
176+
strength: number,
177+
params: HfAudioFxParamValues,
178+
): HfAudioFxParamValues {
179+
const profile = getAudioFxProfile(type);
180+
if (!profile) return params;
181+
return normalizeAudioFxParams(type, { ...params, ...profile.at(strength) });
182+
}
183+
184+
/**
185+
* The strength a set of parameters reads as, by inverting the profile's own
186+
* curve on its most characteristic parameter.
187+
*
188+
* A chain stores mechanism values, not the knob — the same contract
189+
* `normalizeCarveSettings` has, and for the same reason: the mechanism is what
190+
* renders, so it is what must be authoritative. Reading the knob back means one
191+
* parameter has to be nominated as the one that says most about intent.
192+
*
193+
* A hand-edited chain therefore lands the knob at the nearest strength that
194+
* would have produced its most telling value, which is the honest answer — the
195+
* alternative is a knob parked at a default while the effect is set to
196+
* something else entirely.
197+
*/
198+
export function audioFxProfileStrength(type: string, params: HfAudioFxParamValues): number {
199+
const profile = getAudioFxProfile(type);
200+
if (!profile) return 0.5;
201+
const key = profile.derives[0];
202+
if (key === undefined) return 0.5;
203+
const value = params[key];
204+
if (typeof value !== "number") return 0.5;
205+
const low = profile.at(0)[key];
206+
const high = profile.at(1)[key];
207+
if (typeof low !== "number" || typeof high !== "number" || low === high) return 0.5;
208+
return to2(Math.min(1, Math.max(0, (value - low) / (high - low))));
209+
}

0 commit comments

Comments
 (0)