OwnaudioNet

The static entry point for all audio operations. Namespace: OwnaudioNET

Properties

PropertyTypeDescription
IsInitializedboolWhether the audio system has been initialized.
IsRunningboolWhether the audio engine is actively processing.
EngineAudioEngineWrapper?The active engine wrapper. null before initialization. Access UnderlyingEngine for the IAudioEngine.
VersionVersionLibrary version (3.1.7).

Initialization & Lifecycle

âš ī¸

On Linux, Initialize() can block up to 5 seconds waiting for PulseAudio. Always use InitializeAsync() in UI applications.

C# — Synchronous (console apps / services)
// Default config: 48kHz, stereo, 512 frames
OwnaudioNet.Initialize();

// Custom config
OwnaudioNet.Initialize(config);

// Unit testing — no hardware required
OwnaudioNet.Initialize(config, useMockEngine: true);

// Heavy DSP load: 8+ sources or 2+ VST master effects (~170 ms headroom)
OwnaudioNet.Initialize(config, bufferMultiplier: 16);

// Start and stop
OwnaudioNet.Start();
OwnaudioNet.Stop();

// Full release of all resources
OwnaudioNet.Shutdown();
C# — Asynchronous (recommended for UI apps)
// Default config
await OwnaudioNet.InitializeAsync();
await OwnaudioNet.InitializeAsync(cancellationToken);

// Custom config
await OwnaudioNet.InitializeAsync(config);
await OwnaudioNet.InitializeAsync(config, useMockEngine: false, cancellationToken: cancellationToken);

// Heavy DSP load: 8+ sources or 2+ VST master effects
await OwnaudioNet.InitializeAsync(config, bufferMultiplier: 16, cancellationToken: cancellationToken);

// Pre-created engine (custom platform implementations)
await OwnaudioNet.InitializeAsync(engine, config, bufferMultiplier: 16, cancellationToken: cancellationToken);

// Stop / Shutdown
await OwnaudioNet.StopAsync(cancellationToken);
await OwnaudioNet.ShutdownAsync(cancellationToken);
â„šī¸

bufferMultiplier controls the size of the internal CircularBuffer between the mix thread and the audio hardware. Default 8 provides ~85 ms headroom at 48 kHz / 512 frames. Use 16 when running 8 or more simultaneous sources or 2 or more VST master effects, so the mix thread has time to complete heavy DSP without causing audio dropouts. Pair with AudioMixer.Create() to route output through this buffer.

Configuration Factories

C#
// 48kHz ¡ stereo ¡ 512 frames (~10.6ms)
AudioConfig config = OwnaudioNet.CreateDefaultConfig();

// 48kHz ¡ stereo ¡ 128 frames (~2.7ms)
AudioConfig config = OwnaudioNet.CreateLowLatencyConfig();

// 48kHz ¡ stereo ¡ 2048 frames (~42.7ms)
AudioConfig config = OwnaudioNet.CreateHighLatencyConfig();

Device Management

C#
// Enumerate devices
List<AudioDeviceInfo> outputs = OwnaudioNet.GetOutputDevices();
List<AudioDeviceInfo> inputs  = OwnaudioNet.GetInputDevices();

// Async variants
List<AudioDeviceInfo> outputs = await OwnaudioNet.GetOutputDevicesAsync();
List<AudioDeviceInfo> inputs  = await OwnaudioNet.GetInputDevicesAsync();

// Use a specific device
var device = outputs.First(d => d.Name.Contains("Focusrite"));
config.OutputDeviceId = device.DeviceId;

// Hot-plug monitoring — pause when opening VST editors
OwnaudioNet.PauseDeviceMonitoring();
// ... open editor ...
OwnaudioNet.ResumeDeviceMonitoring();

AudioDeviceInfo Properties

PropertyTypeDescription
DeviceIdstringUnique identifier — pass to AudioConfig.OutputDeviceId.
NamestringHuman-readable device name.
EngineNamestringBackend: Wasapi, CoreAudio, PulseAudio, etc.
IsInput / IsOutputboolDevice direction.
IsDefaultboolSystem default device for its type.
MaxInputChannels / MaxOutputChannelsintHardware channel limits.
DefaultSampleRatedoubleNative sample rate reported by the platform at enumeration time. 0 = not available. Check > 0 before using. Available on PortAudio and MiniAudio backends. Added in v3.1.7.
StateAudioDeviceStateActive, Disabled, NotPresent, Unplugged.
C# — Device selection with native sample rate
// Find a device and use its native rate to open without resampling
var outputs = OwnaudioNet.GetOutputDevices();
var device  = outputs.First(d => d.Name.Contains("Focusrite"));

var config = new AudioConfig
{
    OutputDeviceId = device.DeviceId,
    SampleRate     = device.DefaultSampleRate > 0 ? (int)device.DefaultSampleRate : 48000
};
â„šī¸

v3.1.7: AudioConfig.OutputDeviceId is now honoured at initialization time on both MiniAudio and PortAudio backends. Previously the device was applied only after a post-init SetOutputDevice call; initialization always opened the system default first. If the requested device fails, the engine automatically falls back to the default device and clears the stored ID.

Direct Audio I/O

These methods bypass the mixer. Prefer AudioMixer + sources for most use cases.

C#
// Send interleaved samples to output
OwnaudioNet.Send(ReadOnlySpan<float> samples);

// Receive from input — ALWAYS return the buffer!
float[]? buffer = OwnaudioNet.Receive(out int sampleCount);
if (buffer != null)
{
    // process buffer[0..sampleCount-1]
    OwnaudioNet.ReturnInputBuffer(buffer); // returns buffer to pool (zero-allocation)
}
đŸšĢ

Never discard a buffer returned by Receive() without calling ReturnInputBuffer(). The buffer comes from a pool and leaking it causes memory growth.

AudioMixer Registry

The last created AudioMixer is automatically registered for NetworkSync. You can override this:

C#
// Set the primary mixer explicitly (e.g. if you have multiple mixers)
OwnaudioNet.SetPrimaryAudioMixer(mixer);

// Get the currently registered mixer
AudioMixer? active = OwnaudioNet.GetRegisteredAudioMixer();

AudioConfig

Configuration object describing the audio stream format and hardware selection. Namespace: Ownaudio.Core

PropertyTypeDefaultDescription
SampleRateint48000Sample rate in Hz. Common values: 44100, 48000, 96000.
Channelsint21 = mono, 2 = stereo.
BufferSizeint512Desired frames per buffer. Actual size negotiated with driver.
EnableOutputbooltrueEnable audio output (playback).
EnableInputboolfalseEnable audio input (recording / microphone).
OutputDeviceIdstring?nullOutput device ID from AudioDeviceInfo.DeviceId. null = system default.
InputDeviceIdstring?nullInput device ID. null = system default.
HostTypeEngineHostTypeNoneAudio backend: WASAPI, ASIO, CoreAudio, ALSA, Miniaudio, Portaudio.
OutputChannelSelectorsint[]?nullPhysical output channels to use. null = sequential from 0.
InputChannelSelectorsint[]?nullPhysical input channels to use.
FallbackToDefaultOnDisconnectbooltrueWhen the configured device disconnects, automatically switch to the system default device and continue playback. Switches back when the original device reconnects. Set false to wait for the original device instead.
C# — Common configurations
// Standard stereo output
var config = new AudioConfig { SampleRate = 48000, Channels = 2, BufferSize = 512 };

// Windows WASAPI, specific device, input disabled
var config = new AudioConfig
{
    SampleRate     = 48000,
    Channels       = 2,
    BufferSize     = 512,
    HostType       = EngineHostType.WASAPI,
    OutputDeviceId = myDevice.DeviceId,
    EnableInput    = false
};

// 8-channel multi-output device
var config = new AudioConfig
{
    Channels               = 8,
    OutputChannelSelectors = new[] { 0, 1, 2, 3, 4, 5, 6, 7 }
};