(module embabi1_1_ema_step

  ; Fixed-point exponential moving average, one sample per call.
  ; alpha = 1/4: new = old + (sample - old) / 4
  ; The host drives this in a loop, one chunk-sample at a time,
  ; carrying `state` across calls — the (State, Sample) -> State
  ; accumulator the embedding boundary exists for.
  (fn ema_step
    (export "ema_step")
    (type
      (fn-type
        (params (own (con Int)) (own (con Int)))
        (ret (own (con Int)))))
    (params state sample)
    (body
      (app + state
        (app / (app - sample state) 4)))))
