# Membrane Audio Mixer Plugin


Please use <>.

[![API Docs](](

Plugin providing an element mixing raw audio frames.

It is a part of [Membrane Multimedia Framework](

## Installation

Add the following line to your `deps` in `mix.exs`. Run `mix deps.get`.

{:membrane_audio_mixer_plugin, "~> 0.1.0"}

## Description

Provided element add samples from all pads and clip the result to the maximum value for given 
format to avoid overflow.

The Mixer mixes only raw audio (PCM), so some parser may be needed to precede it in pipeline.

Audio format can be set as an element option or received through caps from input pads. All
caps received from input pads have to be identical and match ones in element option (if that 
option is different from `nil`).

Input pads can have offset - it tells how much silence should be added before first sample
from that pad. Offset has to be positive.

All inputs into the mixer have to be added before starting pipeline and should not be changed
during mixer's work.

Mixing is tested only for integer audio formats.

## Sample usage

defmodule Mixing.Pipeline do
  use Membrane.Pipeline

  @impl true
  def handle_init(_) do
    children = [
      file_src_1: %Membrane.File.Source{location: "/tmp/input_1.raw"},
      file_src_2: %Membrane.File.Source{location: "/tmp/input_2.raw"},
      mixer: %Membrane.AudioMixer{
        caps: %Membrane.Caps.Audio.Raw{
          channels: 1,
          sample_rate: 16_000,
          format: :s16le
      converter: %Membrane.FFmpeg.SWResample.Converter{
        input_caps: %Membrane.Caps.Audio.Raw{channels: 1, sample_rate: 16_000, format: :s16le},
        output_caps: %Membrane.Caps.Audio.Raw{channels: 2, sample_rate: 48_000, format: :s16le}
      player: Membrane.PortAudio.Sink

    links = [
      |> to(:mixer)
      |> to(:converter)
      |> to(:player),
      |> via_in(:input, options: [offset: Membrane.Time.milliseconds(5000)])
      |> to(:mixer)

    {{:ok, spec: %ParentSpec{children: children, links: links}}, %{}}

## Copyright and License

Copyright 2021, [Software Mansion](

[![Software Mansion](](

Licensed under the [Apache License, Version 2.0](LICENSE)