---
title: "Apply an audio low-pass filter in C#"
url: https://recursiveai.org/oneaudio/cookbook/apply-audio-low-pass-filter/
description: "A low-pass filter reduces high frequencies while retaining low frequencies. Apply it to a mixer bus and render the result offline."
version: "1.7.2"
---

# Apply an audio low-pass filter 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/apply-audio-low-pass-filter/apply-audio-low-pass-filter.zip)

A low-pass filter reduces high frequencies while retaining low frequencies. Apply it to a mixer bus and render the result offline.

```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 { SampleRate = 48000, Channels = 1 });
if (!mixer.SetBusFilter(AudioMixer.MasterBus,
    FilterType.LowPass, 1000, rampFrames: 0))
    throw new InvalidOperationException("Queue full.");
mixer.Play(new PlayParams(
    Audio.Load("two-tone.wav")));
var output = new float[48000];
mixer.Render(output);
using (var wav = new WavEncoder(File.Create("filtered.wav"),
    new AudioFormat(48000, 1), leaveOpen: false))
    wav.Write(output);
Console.WriteLine("Saved filtered.wav");
```

`two-tone.wav` in the zip is a generated mono signal containing 200 Hz and 8000 Hz tones. The snippet saves one second of filtered mono audio to `filtered.wav`.

```text
Saved filtered.wav
```

Unzip [the example](https://recursiveai.org/oneaudio/cookbook/apply-audio-low-pass-filter/apply-audio-low-pass-filter.zip), then `dotnet run`.

## The full program

The full program generates the two tones directly, renders one second, and saves `filtered.wav`. It measures each tone in the last half-second to avoid the startup transient. A full command queue makes `SetBusFilter` return `false`; the example throws instead of silently rendering unfiltered audio.

```csharp
using OneAudio;

const int rate = 48000;
var samples = new float[rate];
for (int i = 0; i < samples.Length; i++)
    samples[i] = (float)(0.2 * Math.Sin(2 * Math.PI * 200 * i / rate)
        + 0.2 * Math.Sin(2 * Math.PI * 8000 * i / rate));
var mixer = new AudioMixer(new MixerOptions { SampleRate = rate, Channels = 1 });
if (!mixer.SetBusFilter(AudioMixer.MasterBus, FilterType.LowPass, 1000, rampFrames: 0))
    throw new InvalidOperationException("Command queue full.");
mixer.Play(new PlayParams(new AudioClip(new AudioFormat(rate, 1), samples)));
var output = new float[rate];
mixer.Render(output);
using (var wav = new WavEncoder(File.Create("filtered.wav"), new AudioFormat(rate, 1), leaveOpen: false))
    wav.Write(output);
Console.WriteLine("filtered.wav: 48000 frames, mono");
foreach (int frequency in new[] { 200, 8000 })
{
    double real = 0, imaginary = 0;
    for (int i = rate / 2; i < rate; i++)
    {
        double angle = 2 * Math.PI * frequency * i / rate;
        real += output[i] * Math.Cos(angle);
        imaginary += output[i] * Math.Sin(angle);
    }
    double amplitude = 4 * Math.Sqrt(real * real + imaginary * imaginary) / rate;
    Console.WriteLine($"{frequency} Hz amplitude: {amplitude:F4}");
}
```

```text
filtered.wav: 48000 frames, mono
200 Hz amplitude: 0.1998
8000 Hz amplitude: 0.0026
```

## Variations

For a lower cutoff, replace the `SetBusFilter` call’s cutoff argument `1000` with `500` in the full program. Keep the same signal and measurement loop.

```csharp
if (!mixer.SetBusFilter(AudioMixer.MasterBus, FilterType.LowPass, 500, rampFrames: 0))
    throw new InvalidOperationException("Command queue full.");
```

```text
filtered.wav: 48000 frames, mono
200 Hz amplitude: 0.1975
8000 Hz amplitude: 0.0006
```

## Related recipes

- [Apply reverb](https://recursiveai.org/oneaudio/cookbook/apply-audio-reverb/)
- [Mix audio](https://recursiveai.org/oneaudio/cookbook/mix-audio/)

## The short answer

Call `SetBusFilter(bus, FilterType.LowPass, cutoffHz)` before rendering. Use `AudioMixer.MasterBus` (the value `-1`) to filter the whole mix, or a numbered bus to filter only the voices routed through it. Queue the source with `Play`, call `Render` to obtain interleaved float PCM, then write that PCM with `WavEncoder` if you need a file. No audio device is required for this offline path.

The [mixer effects reference](https://recursiveai.org/oneaudio/docs/api/) documents a second-order low-pass filter, not an arbitrary equalizer or a frequency-domain noise-removal operation. This recipe uses a known two-tone input so that the effect is audible and its frequency-specific behavior is visible in the output. The short snippet reads the included WAV; the full program generates float PCM directly and writes the processed result.

## What is a low-pass filter in audio?

It passes lower frequencies and attenuates higher ones. The cutoff marks the transition region, not a hard boundary where every higher frequency vanishes. Oneaudio documents a second-order response with a 12 dB-per-octave slope. Its Q setting controls resonance, with a default of `0.707` and an accepted range from `0.1` to `24`.

In this run, each source tone starts at amplitude `0.2`. After the 1000 Hz filter settles, the 200 Hz component measures `0.1998`, while the 8000 Hz component measures `0.0026`. These are measurements of this synthetic signal at this sample rate and cutoff, not promises about every recording. The high-frequency component is reduced, not removed entirely.

The measurement loop accumulates sine and cosine projections at each known tone frequency. It uses only the latter half of the rendered second, so initialization has less influence on the result. This is not a loudness measurement; the numbers describe the individual test tones, not LUFS or perceived volume.

## What should I set my lowpass filter to?

Choose a cutoff based on which content you want to retain. In the example, 1000 Hz lies between the two tones. The 500 Hz variation lowers that transition and reduces the 8000 Hz component further, while also changing the low-frequency response. There is no universal vocal or music setting in this API.

Keep Q at its default while establishing the cutoff, then change resonance only if it is part of the desired sound. A resonant response can emphasize the transition region. Filtering is not peak limiting or loudness normalization: if your later processing requires a ceiling or loudness target, that is a separate operation.

For startup processing the example sets `rampFrames: 0` so the requested response is active from the beginning. During live parameter changes, use a ramp rather than abruptly switching the cutoff. The docs describe logarithmic cutoff gliding over the ramp.

## How to create a low-pass filter in C#?

Construct the mixer with the output rate and channel count you need. `Render` fills the supplied buffer at that format, processing it in internal passes up to `MaxBlockFrames`. Commands take effect at pass boundaries; merely queuing the filter does not produce output until rendering begins.

Check the Boolean command result. Otherwise a full queue can leave you hearing the previous settings. Keep the mixer instance between successive render blocks so its filter state continues across block boundaries. Recreating it for every block would repeatedly restart the response rather than process one continuous stream.
