Skip to content
Oakfield Operator Calculus Function Reference Site

Coupling Operators

sim_add_mixer_operator(ctx, lhs, rhs, out, opts)

Combine two inputs in-place or into a destination. Shared options:

  • lhs_gain, rhs_gain, bias (defaults 0), mix (0..1 for crossfade).
  • accumulate (bool): add instead of overwrite.
  • scale_by_dt (bool): scale writes by substep dt when accumulating.

Modes:

  • linear: out = lhs * lhs_gain + rhs * rhs_gain + bias.
  • multiply: element-wise product of scaled inputs.
  • crossfade: blend between scaled inputs using mix (0 = lhs, 1 = rhs).
  • sum: simple sum of scaled inputs.
  • power: out = lhs ^ rhs (complex uses cpow).
  • am: amplitude modulation (1 + rhs*rhs_gain) * (lhs*lhs_gain) + bias.
  • fm: frequency modulation lhs * exp(i * rhs * rhs_gain).
  • pm: phase modulation preserving magnitude.
  • ring_mod: ring modulation removing DC bias.
  • max / min: element-wise extrema after scaling.
  • average: mean of scaled inputs.
  • difference / abs_diff: signed or absolute difference.
  • feedback: leaky integrator using feedback_decay, feedback_strength, feedback_bias.

Example mix patterns:

-- FM synthesis
sim.sim_add_mixer_operator(ctx, carrier, mod, out, {
mode = "fm",
lhs_gain = 1.0,
rhs_gain = 0.2
})
-- Crossfade
sim.sim_add_mixer_operator(ctx, a, b, out, {
mode = "crossfade",
lhs_gain = 1.0,
rhs_gain = 1.0,
mix = 0.35
})
-- Feedback blend
sim.sim_add_mixer_operator(ctx, a, b, out, {
mode = "feedback",
feedback_decay = 0.1,
feedback_strength = 0.9,
bias = 0.0
})

Examples:

sim.sim_add_mixer_operator(ctx, a, b, out, {
mode = "fm",
rhs_gain = 0.2,
lhs_gain = 1.0
})
sim.sim_add_mixer_operator(ctx, a, b, out, {
mode = "feedback",
feedback_decay = 0.1,
feedback_strength = 0.9,
bias = 0.0
})