Build with this node

Start with a prompt in Studio, or copy it into your own coding agent.

Ask Studio

@maruaudio/dsp/mixing/gain multiplies one sample by a bounded linear gain: y = x × gain, a double multiply with no rounding of its own. Channel count belongs to the caller: a stereo caller runs the tick once per channel against one shared state.

const state = initGainNode(48000)
setGainNodeGain(state, 2)
const y = gainNodeTick(state, 0.3) // 0.6

Parameters

SetterRange the setter enforcesDefault
setGainNodeGain0 to 4 (linear)1

The sample rate passed to initGainNode is stored and not read.

Lifecycle

initGainNode → setGainNodeGain → gainNodeTick. There is no reset; the state holds only the parameter. Ticks allocate nothing and do no I/O.

When to use it

An output level, a fixed trim or a send amount set as a linear factor. For a level set in decibels with a mute, use @maru/mixing-gain-db; for a gain driven by a control signal, use @maru/mixing-control-gain.

Limits

  • Mono sample tick, not a block Processor.
  • No negative gain: polarity inversion is not available here.
  • Gain changes apply at once, with no smoothing.
  • The clamp is the kernel node's conditional clamp, not the math/range policy: a NaN passes through unchanged.

Algorithm properties and proofs

Lean 4 checks specific properties of this algorithm’s mathematical model. Each model result applies within its stated domain and assumptions.

2 Lean 4 results: 1 proof in exact arithmetic; 1 refused rewrite.

Proved in exact arithmetic.Two successive scalar gains can be combined algebraically in exact arithmetic.Exact rational input and gain coefficients
Limits and assumptions
  • Hand-written source-reviewed model, not formal refinement of TypeScript or compiled code. Named functions and whole-file source digests are checked; finite canonical JavaScript cases are compared with executable Lean definitions. Exact rational arithmetic only: IEEE rounding, overflow, NaN, infinities and signed-zero behavior are not proved. Sampler mappings cover the named shared stage only. No optimization is enabled or claimed faster.
Theorem
MaruLean.LeafContracts.gain_fusion_exact
Recorded axioms
propext, Classical.choice, Quot.sound
Manifest reviewed
Rewrite refused.Fusing two small gains can underflow their product to zero while sequential gains keep a nonzero output.One finite IEEE binary64 witness; input 2^600 and both gains 2^-600
Limits and assumptions
  • Hand-written source-reviewed model, not formal refinement of TypeScript or compiled code. Named functions and whole-file source digests are checked; finite canonical JavaScript cases are compared with executable Lean definitions. One concrete witness; it refutes the stated unrestricted claim, not every possible guarded implementation.
Theorem
MaruLean.LeafContracts.gain_fusion_refused_on_float
Recorded axioms
propext, Classical.choice, Quot.sound
Manifest reviewed
Explore proofs alongside performance

Parameters

ParameterTypeSetter
Gain gainfloatsetGainNodeGain

Ports

  • In ininput · audio · mono
  • Out outoutput · audio · mono

One sample per gainNodeTick call.

Dependencies

None: this node imports no other node.

Dependents

No other node imports this one.

Used by