@maruaudio/dsp/mixing/key-velocity-response interpolates a gain and a velocity exponent across the keyboard from prepared register anchors, and applies them to one strike:
gain = 10^(gainDb(note)/20) × (clamp(velocity, 0, 1) / anchorVelocity)^max(0, exponent(note))keyInterpolatedValue(note, keys, values, count) interpolates linearly between the two anchors around note and extrapolates the end segments, so the register slope continues past the first and last anchor. keyTrackedVelocityGain combines the two interpolations. The …Eight variants are fixed eight-anchor forms used by the piano voice.
Parameters
There are no setters or state. The caller passes Float32Array tables of ordered, distinct key anchors with equal-length gain (dB) and exponent tables, the anchor count and the anchor velocity on every call.
Lifecycle
Pure functions, evaluated once per strike. The tables are prepared by the caller beforehand. No allocation, state change or sample or layer selection happens here.
When to use it
Calibrating an instrument's loudness and velocity sensitivity by register, so low and high notes respond to touch differently, with a handful of anchors instead of a table per key.
Limits
- Loudness only; physical excitation stays with the caller.
- Zero dB and a zero exponent are exactly neutral, including at velocity 0.
- With
count ≤ 1the first value is returned unchanged. - Repeated anchor keys divide by zero; the anchors must be distinct.
- Tables are f32; interpolation runs in doubles and the final gain is rounded to f32.