@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.
| Mode | Constant | Output |
|---|---|---|
| Sum | MIX_MODE_SUM (0) | a + b |
| Dry/wet | MIX_MODE_DRY_WET (1) | a × (1 − amount) + b × amount |
| Crossfade | MIX_MODE_CROSSFADE (2) | a × cos(amount·π/2) + b × sin(amount·π/2), gains rounded to f32 |
| Ring | MIX_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
| Setter | Range the setter enforces | Default |
|---|---|---|
setMixNodeMode | Rounded, then 0 to 3 | Sum |
setMixNodeAmount | 0 to 1; read by dry/wet, crossfade and ring | 0.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.