---
title: "Route audio to a mixer bus in C#"
url: https://recursiveai.org/oneaudio/cookbook/route-audio-through-mixer-buses/
description: "Route voices to numbered mixer buses in C#, set a group’s volume, and send one bus into another with OneAudio. Run the example without an audio device."
version: "1.8.0"
---

# Route audio to a mixer bus in C#

**oneaudio** is a free, open-source audio library for .NET from Recursive AI. MIT or Apache-2.0, no bundled native binaries.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneAudio) · [GitHub](https://github.com/recursive-ai-oss/oneaudio-csharp) · [Docs](https://recursiveai.org/oneaudio/docs/) · [Download example (.zip)](https://recursiveai.org/oneaudio/cookbook/route-audio-through-mixer-buses/route-audio-through-mixer-buses.zip)

A voice is one playing sound: `mixer.Play` returns a handle to it. Set its `Bus` to group it with other sounds you want to turn up or down together.

```shell
dotnet add package RecursiveAI.OneAudio
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneAudio;

var mixer = new AudioMixer(new MixerOptions
{
    Channels = 1, MaxBuses = 2
});
var format = new AudioFormat(48000, 1);
var clip = new AudioClip(format, [0.5f]);
if (!mixer.SetBusGain(1, 0.5f, 0))
    throw new InvalidOperationException();
var dry = mixer.Play(
    new PlayParams(clip) { Bus = 0 });
var group = mixer.Play(
    new PlayParams(clip) { Bus = 1 });
if (!dry.IsValid || !group.IsValid)
    throw new InvalidOperationException();

var pcm = new float[1];
mixer.Render(pcm);
Console.WriteLine(FormattableString
    .Invariant($"Master sample: {pcm[0]}"));
```

The example renders one sample into an array and plays nothing through speakers, so it needs no audio device.

Two voices send `0.5` each to different buses. Bus 0 sends `0.5` to the master; bus 1 halves its contribution to `0.25`.

```text
Master sample: 0.75
```

Check for an invalid `Play` handle or a `false` bus command result: the command queue may be full.

Unzip [the example](https://recursiveai.org/oneaudio/cookbook/route-audio-through-mixer-buses/route-audio-through-mixer-buses.zip), then `dotnet run`.

## Variations

To put bus 0 under the same gain as bus 1, insert this before `var dry = mixer.Play(...)`:

```csharp
if (!mixer.SetBusOutput(0, 1))
    throw new InvalidOperationException();
```

```text
Master sample: 0.5
```

## Related recipes

- [Mix audio in C#](https://recursiveai.org/oneaudio/cookbook/mix-audio/)
- [Play an audio file in C#](https://recursiveai.org/oneaudio/cookbook/play-audio-file/)

## The short answer

Set `PlayParams.Bus` to the bus number when you start a voice. Reserve the number of buses you need with `MixerOptions.MaxBuses`; with two buses, the indexes are `0` and `1`. Both feed the master output by default. `SetBusGain(1, 0.5f, 0)` immediately halves bus 1’s contribution at the next render pass, without changing bus 0.

## What is a bus on a sound mixer?

It’s a shared path for several signals. A game could route its character voices and sound effects through separate buses and let the player turn the effects down without touching dialogue. Assign voices to groups as you start them; bus `0` is the default for voices with no explicit `Bus`. Each voice goes to one bus, not to both its bus and the master. `SetMasterGain` changes the final level rather than one group’s contribution.

Bus gain is linear: `1f` leaves the level unchanged, `0.5f` halves the sample amplitudes, and `0f` makes the bus silent. The example uses zero ramp frames so the change is visible in a single sample. In a live mix, omit the explicit ramp to use `MixerOptions.SmoothingMilliseconds` rather than stepping the gain abruptly. The [mixer reference](https://recursiveai.org/oneaudio/docs/api/) notes that render sums the streams without clipping them, so leave headroom when you combine louder signals.

## What does submix mean?

A submix combines some of the channels before they reach the final mix. The variation routes bus 0 into bus 1, so the two `0.5` signals sum before bus 1 halves the result to `0.5`. That is different from changing bus 1’s gain with both buses independently feeding the master, where the result was `0.75`.

Choose a parent bus when you want several groups to share one control, but keep their own group controls. `SetBusOutput` replaces the child’s destination rather than adding a second route. To send it directly to the output again, use `AudioMixer.MasterBus` as the destination. A route that makes a bus feed itself, even through other buses, throws `ArgumentException`.
