@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
| Call | Accepts | Default |
|---|---|---|
createReferenceSmoothedGainState(initialGain) | Rounded to f32; a non-finite or f32-overflowing value becomes 1 | none |
setReferenceSmoothedGainTarget(state, gain, rampFrames) | Gain finite after f32 rounding; ramp an integer 0 to 4294967295 frames; 0 jumps at once | initial 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.
processreturnsfalseand 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.