Channel Separation

How to split multiple stereo channels or recombine mono audio signals

This example demonstrates how to split and rearrange audio channels using the ChannelSeparator and ChannelMerger nodes to divide a given stereo signal and recombine its channels. This technique is useful for independent channel processing.

// Configure the graph for rendering
let context = Assembler(rendering: .live).createAudioGraph()

// Configure an audio source (Renderer) from a local audio file
let url = URL(fileURLWithPath: "/path/to/source.mp3")
let source = MediaRenderer(contentsOf: url)

// Configure a stereo mixer and separator
let separator = ChannelSeparator(numberOfOutputs: 2)
let merger = ChannelMerger(numberOfInputs: 2)

// Configure node connections
try context.connect(source: source, to: separator)
try context.connect(source: separator, to: merger, with: .init(source: 0, destination: 1))
try context.connect(source: separator, to: merger, with: .init(source: 1, destination: 0))
try context.connect(source: merger, to: context.destination)
source.play(after: 0)

The following video shows the sample code in action and its real-time processing.

circle-info

For a complete description of each class, method, and property referenced in this section, refer to the official API documentationarrow-up-right, where you will find detailed references, available components, parameters, and additional usage code examples.

Last updated