Table of Contents

Class CaptureMixerInput

Namespace
NAudio.Extras
Assembly
NAudio.Extras.dll

Adapts a single capture source (a microphone, WASAPI loopback, etc.) into an ISampleProvider in a common target format, ready to feed a MixingSampleProvider. It buffers the incoming bytes, converts them to 32-bit IEEE float, and matches the channel count and sample rate of the target format.

public class CaptureMixerInput
Inheritance
CaptureMixerInput
Inherited Members

Remarks

The source is device-agnostic: feed captured bytes in via AddSamples(ReadOnlySpan<byte>) from any capture callback — a WasapiRecorder's zero-copy DataAvailable (input.AddSamples(data)) or a legacy IWaveIn (input.AddSamples(a.Buffer.AsSpan(0, a.BytesRecorded))). Packets are appended in arrival order; keeping independently-clocked sources in sync is handled downstream by RealtimeCaptureMixer, which paces its output to the wall clock.

Constructors

CaptureMixerInput(WaveFormat, WaveFormat, TimeSpan?)

Creates a new capture input.

public CaptureMixerInput(WaveFormat sourceFormat, WaveFormat targetFormat, TimeSpan? bufferDuration = null)

Parameters

sourceFormat WaveFormat

The native format the source delivers.

targetFormat WaveFormat

The common mixer format. Must be 32-bit IEEE float. The input is resampled and channel-converted to this format.

bufferDuration TimeSpan?

How much audio the internal buffer holds (default 2s).

Properties

BufferedFrames

Source frames currently buffered and waiting to be mixed. Diagnostics.

public int BufferedFrames { get; }

Property Value

int

HasReceivedData

Whether any audio has been received yet. RealtimeCaptureMixer uses this to anchor its output clock to the first captured sample.

public bool HasReceivedData { get; }

Property Value

bool

SampleProvider

The adapted provider, already in the target format, to add to a mixer.

public ISampleProvider SampleProvider { get; }

Property Value

ISampleProvider

SourceFormat

The native (capture) format of the source.

public WaveFormat SourceFormat { get; }

Property Value

WaveFormat

Methods

AddSamples(ReadOnlySpan<byte>)

Adds captured bytes, appended in arrival order. Safe to call from the capture thread.

public void AddSamples(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>