Skip to content

Splitting and Merging Audio

Phil Schatzmann edited this page Mar 15, 2024 · 26 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.

You can define the outputs in the constructor or you can define them by calling the add method.

Here are some examples:

Combining Audio

Mixing Multiple Inputs into One Output

You can use the InputMixer class to combine 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 input is in PCM format and is the same across all inputs:

  • 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 mix 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 output is in PCM format and the same across all outputs:

  • 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

Merging Multiple Inputs

You can use the InputMerge class to combine 2 mono input channels into a stereo signal. The first input stream is ending up on one channels and the second stream on the other.

Here is a simple Merging Example

Splitting Multiple Channels into Mono Signals

You can use the ChannelSplitOutput class to extract a mono channel from a stereo signal or to split the stereo signal into two separate mono signals. Just define for each relevant channel your selected output class.

Splitting Multiple Channels

The ChannelsSelectOutput class can be used do extract one or multiple channels to one or more outputs. Just select the channels: e.g. 2,3 creates a stereo signal consisting of channel 2 and channel 3.

Further Information