# `Membrane.AudioMixer.NativeAdder`
[🔗](https://github.com/membraneframework/membrane_audio_mix_plugin/blob/v0.16.7/lib/membrane_audio_mixer/native_adder.ex#L1)

Module responsible for mixing audio tracks (all in the same format, with the same number of
channels and sample rate). The result is a single track in the format mixed tracks are encoded in.
If overflow happens during mixing, a wave will be scaled down to the max sample value. Uses NIFs
for mixing.

Description of the algorithm:
- Start with an empty queue
- Enqueue merged values while the sign of the values remains the same
- If the sign of values changes or adder is flushed:
  - If none of the values overflows limits of the format, convert the queued values
    to binary samples and return them
  - Otherwise, scale down the queued values, so the peak of the wave will become
    maximal (minimal) allowed value, then convert it to binary samples and return
    them.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
