Skip to content

Splitting and Merging Audio

Phil Schatzmann edited this page Jul 22, 2022 · 34 revisions

Splitting Audio - Sending Audio to Multiple Destinations

Instead of copying the audio to a single destination you can use the MultiOutput class and add multiple final output classes to it: e.g. a I2SStream and the VolumePrint class which measures the volume.

Here is an example with 2 outputs. Alternatively or if you have more then 2 outputs you need to define them by calling the add method.

Merging Audio

Mixing Multiple Inputs into One Output

You can use the InputMixer class to merge multiple inputs into one output. Just add the Sources that need to be mixed to the Mixer and use it as copy source. Note that this is however only working if the basic audio information is the same across all inputs and the data is in PCM format:

  • number of channels
  • bits per sample
  • sample rate

Here is a simple InputMixer example

Mixing Multiple Outputs into One Output

You can use the OutputMixer class to merge multiple outputs into one single output. You need to define the total number of outputs and then write the data for each output to the mixer. Note that this is however only working if the basic audio information is the same across all outputs and the data is in PCM format:

  • number of channels
  • bits per sample
  • sample rate

Please note that mixing on the output side is quite challenging and requires plenty of additional memory.

Here is a simple OutputMixer example

Clone this wiki locally