Build with this node

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

Ask Studio

@maruaudio/dsp/mixing/mix combines two input samples a and b in one of four modes. The amount is the dry/wet or crossfade position.

ModeConstantOutput
SumMIX_MODE_SUM (0)a + b
Dry/wetMIX_MODE_DRY_WET (1)a × (1 − amount) + b × amount
CrossfadeMIX_MODE_CROSSFADE (2)a × cos(amount·π/2) + b × sin(amount·π/2), gains rounded to f32
RingMIX_MODE_RING (3)a × (1 − amount) + (a × b) × amount

The crossfade gains come from @maru/mixing-levels (equalPowerGainA/B).

const state = initMixNode(48000)
setMixNodeMode(state, MIX_MODE_CROSSFADE)
setMixNodeAmount(state, 0.5)
const y = mixNodeTick(state, a, b)

Parameters

SetterRange the setter enforcesDefault
setMixNodeModeRounded, then 0 to 3Sum
setMixNodeAmount0 to 1; read by dry/wet, crossfade and ring0.5

Lifecycle

initMixNode → setters → mixNodeTick. There is no reset; the state holds only the two parameters. Ticks allocate nothing and do no I/O. The crossfade mode calls cos and sin on each tick.

When to use it

Blending a dry and a processed signal, crossfading between two sources at constant power, or ring-modulating a carrier a by b with a dry/wet amount.

Limits

  • Mono sample tick; channel count and buffers belong to the caller.
  • Sum mode does not scale: two full-scale inputs reach 2.
  • The equal-power crossfade sums two equal unit inputs to √2 at the centre.
  • Amount changes apply at once, with no smoothing.

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: 2 proofs in exact arithmetic.

Proved in exact arithmetic.The dry/wet sum and the subtract-then-scale interpolation form are algebraically equal.Exact rational samples and mix coefficient
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. This does not authorize changing the existing floating-point operation order.
Theorem
MaruLean.LeafContracts.drywet_is_lerp
Recorded axioms
propext, Classical.choice, Quot.sound
Manifest reviewed
Proved in exact arithmetic.A dry/wet mix stays inside the common input interval for a mix between zero and one.Exact rationals; ordered finite bounds and stated coefficient guards; mix in [0, 1]
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.drywet_bounded
Recorded axioms
propext, Classical.choice, Quot.sound
Manifest reviewed
Explore proofs alongside performance

Parameters

ParameterTypeSetter
Mode modefloatsetMixNodeMode
Amount amountfloatsetMixNodeAmount

Dependencies

Dependents

No other node imports this one.

Used by