Fit the Compressor's tab to any size, make auto-gain a switch (#378)
Two things came up on the new tab. Floated and sized down, it spilled its knobs out of its window, and sized up it left the window empty. Auto-gain lifted far too much: it brought 0 dB back to 0 dB, which at -40 dB, 4:1 and knee 6 is +28.1 dB, so a sound at -24 dB came out at -6 dB. And as a knob from 0 to 1 it blended between makeup and auto-gain, so at 1 the makeup knob did nothing. Layout: - The knobs stay on the bottom line, centred, with the help line above them. - The levels fill the height left above. The curve is a square at their right, centred up and down. It grows with the tab from 180 to 360 px and takes no more than 40 % of its width (picturesLayout). - A floated window cannot be sized below what its pane needs. A pane says so in its minWidth and minHeight, and the Compressor's is every knob and the smallest pictures. Other panes keep 320 x 200. - A pane put into an open window that is too small grows the window. Auto-gain, as decided in #378: - A Compressor's auto-gain gives back what it takes from a sound at -18 dB, so that one comes out as loud as it went in. At the numbers above that is +14.6 dB. - Auto-gain is a switch on the Compressor, the Limiter and the Saturation alike, a setting and no longer an input. The makeup or output is added on top of it instead of being blended with it. - A project from before reads a number as on above 0. Nodes never set keep their defaults: off on the Compressor, on on the other two. - The tab shows the switch at the right of the knobs, with the dB it gives below it. With it on, the curve has a line at -18 dB from the curve up to the diagonal. - Every level reading keeps the gain of its time. Before, the whole picture was read by the current makeup, so after a change the tinting of the last seconds was wrong or missing. Findings: - My first e2e run of the layout clicked Dock where it was before the window was sized up, so the window stayed open and the next check went red. The check reads the button again. Tests: - Gate (melektaus-atx): 282 files, 4344 tests (6 new) - e2e 34 (melektaus-atx): ALL PASSED, 118 checks (2 new) - Offline in Chrome: a sine at -18 dB through -24 dB and 4:1 came out at -17.92 dB with auto-gain on and -22.42 dB with it off. - Counter-checks: the curve set at the top instead of the middle, and every reading read at a gain of 0, each fail exactly their test. - Looked at the window in screenshots: at its least every knob and the switch show. At 1280 x 797 the levels fill the height, the curve is centred at the right and the knobs are at the bottom. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1df38bd430
commit
2d4909d248
15 files changed
+424
-120
No files matched your search
@@ -41,21 +41,33 @@ export function compressorCurve(threshold: number, knee: number, ratio: number):
|
||||
x < kneeThreshold ? kneeCurve(x, k) : dbToLinear(kneeEndDb + slope * (linearToDb(x) - kneeThresholdDb));
|
||||
}
|
||||
|
||||
/** How much quieter a Compressor makes a sound at full scale, in dB: what full auto-gain gives back. */
|
||||
export function compressorAutoGain(threshold: number, knee: number, ratio: number): number {
|
||||
/** How much quieter a Compressor makes a sound at full scale, in dB; the node gives 0.6 of it back itself. */
|
||||
export function compressorFullScaleLoss(threshold: number, knee: number, ratio: number): number {
|
||||
return -linearToDb(compressorCurve(threshold, knee, ratio)(1));
|
||||
}
|
||||
|
||||
/** The level auto-gain keeps as loud as it came in: about where a mixed sound sits on average. */
|
||||
export const AUTO_GAIN_REFERENCE_DB = -18;
|
||||
|
||||
/**
|
||||
* The gain after a Compressor, as a factor: `makeup` dB and the auto-gain blended by `autoGain`
|
||||
* (0 none, 1 all of it), less the 0.6 of the auto-gain the node adds by itself.
|
||||
* What auto-gain gives back, in dB: as much as the Compressor takes from a sound at
|
||||
* `AUTO_GAIN_REFERENCE_DB`. At full scale that would be far too much once the threshold is low.
|
||||
*/
|
||||
export function compressorAutoGain(threshold: number, knee: number, ratio: number): number {
|
||||
const at = dbToLinear(AUTO_GAIN_REFERENCE_DB);
|
||||
return AUTO_GAIN_REFERENCE_DB - linearToDb(compressorCurve(threshold, knee, ratio)(at));
|
||||
}
|
||||
|
||||
/**
|
||||
* The gain after a Compressor, as a factor: `makeup` dB, the auto-gain on top where it is on, less
|
||||
* the 0.6 of its full-scale loss the node adds by itself.
|
||||
*/
|
||||
export function compressorMakeup(
|
||||
numbers: Record<'threshold' | 'knee' | 'ratio' | 'makeup' | 'autoGain', number>,
|
||||
numbers: Record<'threshold' | 'knee' | 'ratio' | 'makeup', number> & { autoGain: boolean },
|
||||
): number {
|
||||
const auto = compressorAutoGain(numbers.threshold, numbers.knee, numbers.ratio);
|
||||
const w = Math.max(0, Math.min(1, numbers.autoGain));
|
||||
return dbToLinear((1 - w) * numbers.makeup + w * auto - 0.6 * auto);
|
||||
const { threshold, knee, ratio } = numbers;
|
||||
const auto = numbers.autoGain ? compressorAutoGain(threshold, knee, ratio) : 0;
|
||||
return dbToLinear(numbers.makeup + auto - 0.6 * compressorFullScaleLoss(threshold, knee, ratio));
|
||||
}
|
||||
|
||||
/** How far a Limiter looks ahead: a peak is met by a gain that has come down over this long. */
|
||||
@@ -80,8 +92,8 @@ const at = (values: Float32Array, i: number) => (values.length > 1 ? values[i]!
|
||||
* A look-ahead limiter: the sound is held back `limiterDelay` samples, and the gain for every one
|
||||
* is the smallest any sample in the window ahead needs, averaged over that window – so it comes
|
||||
* down smoothly and is low enough by the time the peak is heard. Nothing ever goes above the lower
|
||||
* of threshold and ceiling. The gain then comes back up in `release` seconds, and auto-gain raises
|
||||
* the result towards the ceiling.
|
||||
* of threshold and ceiling. The gain then comes back up in `release` seconds, and auto-gain (1 on,
|
||||
* 0 off) raises the result to the ceiling.
|
||||
*/
|
||||
export class Limiter {
|
||||
private readonly delay: number;
|
||||
|
||||
+41
-28
@@ -1,7 +1,7 @@
|
||||
import type { DeclaredPort } from '../graph/Graph';
|
||||
import { SOUND_FX_INPUT, SOUND_FX_OUTPUT } from '../graph/nested';
|
||||
import type { NodeDef, PortDef } from '../graph/NodeRegistry';
|
||||
import { type PropertyBag, textOf } from '../model/Properties';
|
||||
import { booleanOf, type PropertyBag, textOf } from '../model/Properties';
|
||||
import { DEFAULT_TEMPO, heldTempo, secondsOfQuarters } from '../music/time';
|
||||
import type { FlatDef } from '../properties/PropertySchema';
|
||||
import type { ChipShape, ChipWave } from './chip';
|
||||
@@ -120,7 +120,7 @@ export interface FxCompress {
|
||||
gain: number;
|
||||
}
|
||||
|
||||
/** A Limiter (#326) on the worklet: dB, seconds and how much of the auto-gain it gives. */
|
||||
/** A Limiter (#326) on the worklet: dB, seconds, and its auto-gain as 1 on or 0 off. */
|
||||
export interface FxLimit {
|
||||
kind: 'limit';
|
||||
threshold: number;
|
||||
@@ -318,13 +318,13 @@ export type FxStagePlan =
|
||||
>)
|
||||
| ({ kind: 'flanger' } & Record<'offset' | 'sweep' | 'rate' | 'depth' | 'feedback' | 'mix', FxAmount>)
|
||||
| { kind: 'pan'; pan: FxAmount }
|
||||
| ({ kind: 'compress' } & Record<
|
||||
'threshold' | 'knee' | 'ratio' | 'attack' | 'release' | 'makeup' | 'autoGain',
|
||||
| ({ kind: 'compress'; autoGain: boolean } & Record<
|
||||
'threshold' | 'knee' | 'ratio' | 'attack' | 'release' | 'makeup',
|
||||
FxAmount
|
||||
>)
|
||||
| ({ kind: 'limit' } & Record<'threshold' | 'ceiling' | 'release' | 'autoGain', FxAmount>)
|
||||
| ({ kind: 'saturate'; curve: SaturationType } & Record<
|
||||
'drive' | 'tone' | 'output' | 'autoGain' | 'mix',
|
||||
| ({ kind: 'limit'; autoGain: boolean } & Record<'threshold' | 'ceiling' | 'release', FxAmount>)
|
||||
| ({ kind: 'saturate'; curve: SaturationType; autoGain: boolean } & Record<
|
||||
'drive' | 'tone' | 'output' | 'mix',
|
||||
FxAmount
|
||||
>)
|
||||
| { kind: 'tremolo'; shape: LfoShape; rate: FxAmount; depth: FxAmount }
|
||||
@@ -1004,7 +1004,23 @@ const COMPRESS_KNEE = { ...numberRow('knee', 'Knee (dB)', 0, 40, 0.5), default:
|
||||
const COMPRESS_ATTACK = { ...numberRow('attack', 'Attack (s)', 0, 1, 0.001), default: 0.003 };
|
||||
const COMPRESS_RELEASE = { ...numberRow('release', 'Release (s)', 0, 1, 0.001), default: 0.25 };
|
||||
const MAKEUP = numberRow('makeup', 'Makeup (dB)', -24, 24, 0.5);
|
||||
const AUTO_GAIN = numberRow('autoGain', 'Auto-gain', 0, 1, 0.01);
|
||||
/**
|
||||
* Auto-gain of a Compressor, Limiter and Saturation: a switch, with the node's own gain on top of
|
||||
* it. Until #378 it was a number from 0 to 1 blending the two, so a number read is on above 0.
|
||||
*/
|
||||
export const COMPRESS_AUTO_GAIN = {
|
||||
key: 'autoGain',
|
||||
label: 'Auto-gain',
|
||||
kind: 'boolean' as const,
|
||||
default: false,
|
||||
};
|
||||
|
||||
/** Whether a node's auto-gain is on: its switch, or its default where none was ever set. */
|
||||
export function autoGainOn(settings: PropertyBag, row: { key: string; default: boolean }): boolean {
|
||||
const value = settings[row.key];
|
||||
return value === undefined ? row.default : booleanOf(value);
|
||||
}
|
||||
|
||||
/** The numbers of a Compressor, in the order its tab shows them as knobs (#378). */
|
||||
export const COMPRESS_ROWS = {
|
||||
threshold: COMPRESS_THRESHOLD,
|
||||
@@ -1013,7 +1029,6 @@ export const COMPRESS_ROWS = {
|
||||
attack: COMPRESS_ATTACK,
|
||||
release: COMPRESS_RELEASE,
|
||||
makeup: MAKEUP,
|
||||
autoGain: AUTO_GAIN,
|
||||
};
|
||||
|
||||
export const SoundFxCompressor: SoundFxNodeDef = effect(
|
||||
@@ -1023,12 +1038,12 @@ export const SoundFxCompressor: SoundFxNodeDef = effect(
|
||||
category: 'sound',
|
||||
tapped: true,
|
||||
description:
|
||||
'Squeezes the loudness of the sound together: what goes above "threshold" (dB) comes out only 1/"ratio" as much louder, so 4 makes 8 dB over it 2 dB. "knee" (dB) eases into that from the threshold on instead of at once. "attack" is how fast it turns down once the sound is over the threshold, "release" how fast it lets go, both in seconds. "makeup" (dB) raises it again afterwards. "auto-gain" from 0 to 1 blends that with the gain that brings a sound at full scale back to full scale: 0 is the makeup alone, 1 the auto-gain alone. It is 6 ms late, which a voice, a Mix and a bus make up for. All of it can change while the sound plays. Double-click the node to open its editor: a knob for each number, its curve with threshold and ratio to drag, and the level coming in and going out over the last seconds.' +
|
||||
'Squeezes the loudness of the sound together: what goes above "threshold" (dB) comes out only 1/"ratio" as much louder, so 4 makes 8 dB over it 2 dB. "knee" (dB) eases into that from the threshold on instead of at once. "attack" is how fast it turns down once the sound is over the threshold, "release" how fast it lets go, both in seconds. "makeup" (dB) raises it again afterwards. "Auto-gain" on gives back what it takes from a sound at -18 dB, so that one comes out as loud as it went in; the makeup is added on top. It is 6 ms late, which a voice, a Mix and a bus make up for. All of it can change while the sound plays. Double-click the node to open its editor: a knob for each number, its curve with threshold and ratio to drag, and the level coming in and going out over the last seconds.' +
|
||||
BLENDS,
|
||||
inputs: [audioIn, ...Object.values(COMPRESS_ROWS).map(numberIn)],
|
||||
outputs: [audioOut],
|
||||
params: [],
|
||||
emit: (sounds, amounts) =>
|
||||
params: [COMPRESS_AUTO_GAIN],
|
||||
emit: (sounds, amounts, settings) =>
|
||||
withStages(arriving(sounds), [
|
||||
{
|
||||
kind: 'compress',
|
||||
@@ -1038,7 +1053,7 @@ export const SoundFxCompressor: SoundFxNodeDef = effect(
|
||||
attack: held(amounts.attack, COMPRESS_ATTACK),
|
||||
release: held(amounts.release, COMPRESS_RELEASE),
|
||||
makeup: held(amounts.makeup, MAKEUP),
|
||||
autoGain: held(amounts.autoGain, AUTO_GAIN),
|
||||
autoGain: autoGainOn(settings, COMPRESS_AUTO_GAIN),
|
||||
},
|
||||
]),
|
||||
},
|
||||
@@ -1048,12 +1063,11 @@ export const SoundFxCompressor: SoundFxNodeDef = effect(
|
||||
const LIMIT_THRESHOLD = { ...numberRow('threshold', 'Threshold (dB)', -60, 0, 0.5), default: -6 };
|
||||
const CEILING = { ...numberRow('ceiling', 'Ceiling (dB)', -30, 0, 0.1), default: -1 };
|
||||
const LIMIT_RELEASE = { ...numberRow('release', 'Release (s)', 0.001, 2, 0.001), default: 0.1 };
|
||||
const LIMIT_AUTO_GAIN = { ...AUTO_GAIN, default: 1 };
|
||||
const LIMIT_AUTO_GAIN = { ...COMPRESS_AUTO_GAIN, default: true };
|
||||
const LIMIT_ROWS = {
|
||||
threshold: LIMIT_THRESHOLD,
|
||||
ceiling: CEILING,
|
||||
release: LIMIT_RELEASE,
|
||||
autoGain: LIMIT_AUTO_GAIN,
|
||||
};
|
||||
|
||||
export const SoundFxLimiter: SoundFxNodeDef = effect(
|
||||
@@ -1062,19 +1076,19 @@ export const SoundFxLimiter: SoundFxNodeDef = effect(
|
||||
label: 'Limiter',
|
||||
category: 'sound',
|
||||
description:
|
||||
'Keeps every peak of the sound below "threshold" (dB), however loud it comes in: it looks 5 ms ahead and has the volume down by the time the peak is heard, then lets it come back up in "release" seconds. "auto-gain" from 0 to 1 raises the limited sound towards "ceiling" (dB): at 1 its peaks sit right at the ceiling, at 0 at the threshold. Nothing ever goes above the ceiling, and a threshold above the ceiling limits at the ceiling. It is 5 ms late, which a voice, a Mix and a bus make up for. All of it can change while the sound plays.' +
|
||||
'Keeps every peak of the sound below "threshold" (dB), however loud it comes in: it looks 5 ms ahead and has the volume down by the time the peak is heard, then lets it come back up in "release" seconds. "Auto-gain" on raises the limited sound to "ceiling" (dB), so its peaks sit right at the ceiling; off they sit at the threshold. Nothing ever goes above the ceiling, and a threshold above the ceiling limits at the ceiling. It is 5 ms late, which a voice, a Mix and a bus make up for. All of it can change while the sound plays.' +
|
||||
BLENDS,
|
||||
inputs: [audioIn, ...Object.values(LIMIT_ROWS).map(numberIn)],
|
||||
outputs: [audioOut],
|
||||
params: [],
|
||||
emit: (sounds, amounts) =>
|
||||
params: [LIMIT_AUTO_GAIN],
|
||||
emit: (sounds, amounts, settings) =>
|
||||
withStages(arriving(sounds), [
|
||||
{
|
||||
kind: 'limit',
|
||||
threshold: held(amounts.threshold, LIMIT_THRESHOLD),
|
||||
ceiling: held(amounts.ceiling, CEILING),
|
||||
release: held(amounts.release, LIMIT_RELEASE),
|
||||
autoGain: held(amounts.autoGain, LIMIT_AUTO_GAIN),
|
||||
autoGain: autoGainOn(settings, LIMIT_AUTO_GAIN),
|
||||
},
|
||||
]),
|
||||
},
|
||||
@@ -1084,13 +1098,12 @@ export const SoundFxLimiter: SoundFxNodeDef = effect(
|
||||
const DRIVE = { ...numberRow('drive', 'Drive (dB)', 0, 48, 0.5), default: 12 };
|
||||
const TONE = { ...numberRow('tone', 'Tone', 0, 1, 0.01), default: 1 };
|
||||
const OUTPUT = numberRow('output', 'Output (dB)', -24, 24, 0.5);
|
||||
const SATURATION_AUTO_GAIN = { ...AUTO_GAIN, default: 1 };
|
||||
const SATURATION_AUTO_GAIN = { ...COMPRESS_AUTO_GAIN, default: true };
|
||||
const SATURATION_MIX = { ...numberRow('mix', 'Wet', 0, 1, 0.01), default: 1 };
|
||||
const SATURATION_ROWS = {
|
||||
drive: DRIVE,
|
||||
tone: TONE,
|
||||
output: OUTPUT,
|
||||
autoGain: SATURATION_AUTO_GAIN,
|
||||
mix: SATURATION_MIX,
|
||||
};
|
||||
const SATURATION_TYPE = {
|
||||
@@ -1111,11 +1124,11 @@ export const SoundFxSaturation: SoundFxNodeDef = effect(
|
||||
label: 'Saturation',
|
||||
category: 'sound',
|
||||
description:
|
||||
'Bends the sound, from warmth to a hard distortion. "Type" is the shape it is bent by: Soft (tanh) and Cubic round the peaks off, Hard clip cuts them, Tube and Fuzz bend one half harder than the other, Foldback and Sine fold mirror what goes past full scale back in, Rectify turns the lower half up, an octave higher. "drive" (dB) is how hard the sound is pushed into it. "tone" from 0 to 1 is a low-pass after it, from 1 kHz up to wide open. "output" (dB) sets the level of the bent sound, "auto-gain" from 0 to 1 blends that with the gain that keeps a sound at -12 dBFS as loud as it came in. "wet" is how much of the bent sound is heard instead of the sound itself. It is 4 ms late (192 samples), which a voice, a Mix and a bus make up for. All numbers can change while the sound plays.' +
|
||||
'Bends the sound, from warmth to a hard distortion. "Type" is the shape it is bent by: Soft (tanh) and Cubic round the peaks off, Hard clip cuts them, Tube and Fuzz bend one half harder than the other, Foldback and Sine fold mirror what goes past full scale back in, Rectify turns the lower half up, an octave higher. "drive" (dB) is how hard the sound is pushed into it. "tone" from 0 to 1 is a low-pass after it, from 1 kHz up to wide open. "Auto-gain" on keeps a sound at -12 dBFS as loud as it came in, and "output" (dB) is added on top; off, "output" alone sets the level of the bent sound. "wet" is how much of the bent sound is heard instead of the sound itself. It is 4 ms late (192 samples), which a voice, a Mix and a bus make up for. All numbers can change while the sound plays.' +
|
||||
BYPASSES,
|
||||
inputs: [audioIn, ...Object.values(SATURATION_ROWS).map(numberIn)],
|
||||
outputs: [audioOut],
|
||||
params: [SATURATION_TYPE],
|
||||
params: [SATURATION_TYPE, SATURATION_AUTO_GAIN],
|
||||
emit: (sounds, amounts, settings) => {
|
||||
const mix = held(amounts.mix, SATURATION_MIX);
|
||||
if (isNone(mix)) return arriving(sounds);
|
||||
@@ -1126,7 +1139,7 @@ export const SoundFxSaturation: SoundFxNodeDef = effect(
|
||||
drive: held(amounts.drive, DRIVE),
|
||||
tone: held(amounts.tone, TONE),
|
||||
output: held(amounts.output, OUTPUT),
|
||||
autoGain: held(amounts.autoGain, SATURATION_AUTO_GAIN),
|
||||
autoGain: autoGainOn(settings, SATURATION_AUTO_GAIN),
|
||||
mix,
|
||||
},
|
||||
]);
|
||||
@@ -1423,7 +1436,7 @@ function stagesOf(plan: readonly FxStagePlan[], params: FxParams, tempo: number)
|
||||
gain: compressorMakeup({
|
||||
...numbers,
|
||||
makeup: amountOf(stage.makeup, params),
|
||||
autoGain: amountOf(stage.autoGain, params),
|
||||
autoGain: stage.autoGain,
|
||||
}),
|
||||
});
|
||||
continue;
|
||||
@@ -1434,14 +1447,14 @@ function stagesOf(plan: readonly FxStagePlan[], params: FxParams, tempo: number)
|
||||
threshold: amountOf(stage.threshold, params),
|
||||
ceiling: amountOf(stage.ceiling, params),
|
||||
release: amountOf(stage.release, params),
|
||||
autoGain: amountOf(stage.autoGain, params),
|
||||
autoGain: stage.autoGain ? 1 : 0,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (stage.kind === 'saturate') {
|
||||
const drive = amountOf(stage.drive, params);
|
||||
const w = amountOf(stage.autoGain, params);
|
||||
const levelDb = (1 - w) * amountOf(stage.output, params) + w * saturationAutoGain(stage.curve, drive);
|
||||
const auto = stage.autoGain ? saturationAutoGain(stage.curve, drive) : 0;
|
||||
const levelDb = amountOf(stage.output, params) + auto;
|
||||
stages.push({
|
||||
kind: 'saturate',
|
||||
curve: stage.curve,
|
||||
|
||||
Reference in new issue
Block a user