← f_ notebook · docs/f-reference/f_dynamics.md

f_dynamics ​

Audio-style dynamics for textures: every pixel gets its own envelope follower, gate or compressor, with attack, hold and release measured in milliseconds across draws. It is a temporal module (it remembers the last frame), so it changes the time behavior of any chain it sits in.

Written 2026-11-25 (Claude, offline) from src/f_dynamics/definition.py, src/f_dynamics/codebox_state.gen, .specify/stable/f_dynamics/{spec,plan,tasks}.md and the bench logs named under "Status". Not yet looked at in Max beyond the checks listed there.


Inputs and outputs ​

PortTypeWhat it is
Inlet 1texture + controlthe source. Required: with nothing connected the module sees black
Inlet 2texture (optional)the sidechain. When something is connected it becomes the detector (below)
Outlet 1texture, float32processed. Slew, Peak hold: the follower per channel, unclamped. Gate: the gated source. Compressor: the compressed source, clamped 0 to 1. Bypass: the source
Outlet 2texture, float32level: Rec.709 luma replicated to RGB, A = 1. Slew, Peak hold: of the follower. Gate, Compressor: of the detector. Bypass: the source
Outlet 3texture, float32gate: the flag, 0 or 1 replicated to RGB, A = 1. Gate mode only; 0 in the other modes. Bypass: the source

The output is always the render size, whatever the input size (decided 2026-11-25, T060: a 1x1 input gives a flat render-size texture; a 128x1 input is stretched, with independent state per output pixel).

Detector and source ​

The detector is what the module measures. It is inlet 2 when a sidechain is connected, otherwise inlet 1, in every mode. Gate and Compressor measure the detector's luma but scale the source (inlet 1). Slew and Peak hold follow the detector per channel.

Connecting or disconnecting the sidechain re-seeds the state, so there is no jump from stale values.

Parameters ​

Vocabulary reference for the library (G10, NF-004): attack and release are time constants in milliseconds, hold is a duration in milliseconds, threshold is a linear luma level (Rec.709, 0 to 1), not dB.

ParamRangeDefaultUsed byMeaning
modemenu: Slew, Gate, Peak hold, CompressorSlewallselects the algorithm
attack0 to 2000 ms10allrise time constant: 63% of a step in this time. 0 = at once
release0 to 5000 ms250allfall time constant. 0 = at once
hold0 to 2000 ms100Gate, Peak holdGate: how long it stays open after the level last reached the open threshold. Peak hold: how long the peak stays put before release starts
threshold0 to 10.5Gate, CompressorGate: the level where it opens (hysteresis is centered on it). Compressor: the level above which gain falls
hysteresis0 to 0.50.1Gatetotal band width: opens at threshold + half, closes below threshold - half
ratio1 to 1004Gate, CompressorCompressor: input change per output change above threshold (4 = a quarter). Gate: how steeply a closed gate pulls a quiet pixel down, gain = (level / threshold) ^ (ratio - 1); 100 acts as a hard gate
knee0 to 0.50.1Compressorsoft-knee width around threshold, linear level. 0 = hard corner
makeup0 to 41Compressorgain multiplier after compression; result clamped 0 to 1
floor_gain0 to 10Gatelowest gain a closed gate applies. 0 = black, 1 = no gating. (floor is a GenExpr operator, hence the name)
resetbuttonallre-seeds the state from the current input
bypasspilloffallsource passes through on all three outlets

Modes ​

Slew. Per channel: the follower moves toward the input with attack when the input is higher and release when lower. The smoothest way to remove flicker or turn a flash into a glow. Uses attack and release only.

Gate / Expander. Linked luma of the detector against threshold with hysteresis and hold. The gate flag moves the gain with attack (opening) and release (closing). While closed, the source is scaled by max(floor_gain, (level / threshold) ^ (ratio - 1)), so a low ratio gives an expander and a high ratio a hard gate. Outlet 3 carries the flag.

Peak hold. Per channel: rises with attack, holds the peak for hold, then falls with release. One hold counter is shared by the three channels and restarts on any rise.

Compressor / Limiter. Linked luma of the detector goes through a soft-knee static curve (threshold, knee, ratio). The resulting gain is smoothed (attack while the gain is falling, release while it recovers) and multiplied onto the source, then makeup, then clamped 0 to 1. A high ratio acts as a limiter. With a sidechain this is ducking: the sidechain's brightness turns the source down.

Time ​

Frame-rate independent. Each draw measures elapsed milliseconds with a timer (clamped to 250 ms, so a stall does not jump) and uses k = 1 - exp(-dt / tau); tau 0 gives k = 1. The time constants therefore hold at any draw rate.

Seeding, reset and containment ​

  • The state is seeded from the input after load (200 ms delay) and on reset, and the seed is held for three draws.
  • Bypass writes the state as the source, so when bypass ends the follower restarts from the input.
  • A non-finite or >= 1e30 input texel reads as 0. A non-finite fed-back state texel re-seeds from the source (bench 23/23, tests/logs/20261125-154028-bench.log: NaN and Inf input contained in all modes).
  • Bypass selects, it never mixes (mix(effect, src, 0) is 0 * NaN = NaN).
  • No clamp in the state path (float32 follower is unclamped); only the Compressor's output is clamped.
  • A change of mode does not re-seed, so the first draw in a new mode reads the old mode's state layout. A one-draw glitch is possible; not observed in Max.

Temporal-chain note ​

The module remembers the last frame. Putting it in a chain adds smoothing and memory to everything downstream of it, and a feedback loop that includes it pays one frame by construction (docs/max-reference/temporal_synthesis_architecture.md). A forward chain adds no frame of latency. Do not insert it into a chain that is expected to be stateless.

Sidechain lag (G7) ​

vs_inState reports connection with about 180 ms of lag at load and on disconnect (per vsynth-bpatcher; not observed in this module). A real black sidechain and vs_black cannot be told apart by value, so the module decides on the connection flag, not on content. While the flag lags, the detector may briefly still be the old input.

Typical use ​

  • Remove camera flicker: Slew, attack 30 to 100 ms, release 100 to 300 ms.
  • Duck a camera feed with a flashing shape: camera in inlet 1, shape in inlet 2, Compressor, low threshold, high ratio, short attack, release a few hundred ms. Checked live by Matt, 2026-11-25 (the duck was visible and felt right, reset made no jump).
  • Gate noise out of a feed: Gate, threshold just above the noise level, hysteresis 0.05 to 0.1, floor 0.
  • Peak-meter trail on a flash: Peak hold, hold 200 ms, release 500 ms.

Status ​

  • Offline: mirror tests tests/modules/dynamics/test_dynamics.py; GPU bench bench_dynamics.py 23/23 (tests/logs/20261125-154028-bench.log, Claude drove it with Matt's go, 2026-11-25); drift ok.
  • Live (Matt, 2026-11-25): the compressor duck (T053), reset without a jump, the earlier 190 x 196 all-dials panel. The 2026-11-25 role layout (now 190 x 162) was looked at live by Matt and accepted.
  • Live (Matt, 2026-11-25): f_lfo into it and a vs_vca passed (T063; no details reported).
  • Not yet looked at live: the sidechain lag; a render-size change at runtime (G3).
  • The contract bench tests/contracts/bench_modules.py fails 0/2 on f_a_decorrelate and f_a_purr, not on this module (reproduced untouched; the cause is inferred, not verified).

References ​

Designed in development; no outside source and no code taken from another implementation.

  • Envelope follower: a one-pole per draw, k = 1 - exp(-dt / tau), with dt measured in milliseconds (textbook audio dynamics, applied per pixel).
  • Gate: hysteresis band centered on the threshold, plus hold. Compressor: soft-knee static curve (quadratic knee). Both standard audio-dynamics forms; the formulas are in .specify/stable/f_dynamics/tasks.md and checked by tests/modules/dynamics/test_dynamics.py.
  • Detector: Rec.709 luma.