Build with this node

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

Ask Studio

@maruaudio/dsp/processors/reference-smoothed-gain is a qualification fixture: a mono gain with a linear ramp to a target, stored and applied in 32-bit floats (Math.fround). It exists to prove that a stateful DSP node with the create, prepare, set, process and reset lifecycle survives packaging and compilation. It is not a product gain and not an alias for another gain implementation. REFERENCE_SMOOTHED_GAIN_ALGORITHM_REVISION is 1.

const state = createReferenceSmoothedGainState(0)
prepareReferenceSmoothedGain(state, { sampleRate: 48000, maximumBlockSize: 128, inputChannels: 1, outputChannels: 1 })
setReferenceSmoothedGainTarget(state, 1, 480) // gain 1 over 480 frames
processReferenceSmoothedGain(state, block)

Parameters

CallAcceptsDefault
createReferenceSmoothedGainState(initialGain)Rounded to f32; a non-finite or f32-overflowing value becomes 1none
setReferenceSmoothedGainTarget(state, gain, rampFrames)Gain finite after f32 rounding; ramp an integer 0 to 4294967295 frames; 0 jumps at onceinitial gain

An invalid target or ramp returns false and changes nothing.

Lifecycle

createReferenceSmoothedGainState allocates the state object → prepareReferenceSmoothedGain → setReferenceSmoothedGainTarget → processReferenceSmoothedGain → resetReferenceSmoothedGain. Prepare accepts only a finite positive rate, a maximum block of at least one frame and one input and one output channel; it fails without touching state otherwise, and resets on success. Reset restores the construction gain and clears the ramp. Processing reads caller-owned spans and allocates nothing.

When to use it

As a reference when writing or lowering a Processor: it shows instance-local state, bounded caller-owned planar blocks and a deterministic reset. Use a mixing or dynamics DSP node for gain in a product.

Limits

  • Mono in, mono out; prepare refuses any other channel count.
  • The ramp's first processed frame moves by one f32 increment and its last frame lands exactly on the target.
  • process returns false and writes nothing when the state is unprepared, the frame count exceeds the prepared maximum, or the offset and count run past the stride or either buffer.

Algorithm properties and proofs

No Lean 4 proof is mapped to this node.

Explore proofs alongside performance

Dependencies

None: this node imports no other node.

Dependents

No other node imports this one.

Used by

No plugin with a published composition uses this node yet.