NET OwnaudioNET API Reference

High-level audio API with professional features. Built on Ownaudio.Core with multi-track mixing, effects, synchronization, and real-time processing.

Production-Ready Features OwnaudioNET provides 15+ professional effects, unlimited track mixing, perfect synchronization, tempo/pitch control, and recording capabilities.

Overview

OwnaudioNET extends Ownaudio.Core with:

Key Features

Feature Description
Multiple Formats WAV, MP3, FLAC support
Low Latency < 12ms @ 512 buffer size
Synchronization Sample-accurate multi-track sync with drift correction
Real-time Processing Live synthesis, streaming, effects chains
SoundTouch Independent tempo and pitch control

Initialization

OwnaudioNet Class

Central initialization and configuration for OwnaudioNET.

⚠️ UI APPLICATIONS: Use Async API For desktop/mobile UI applications, use async methods to prevent UI thread blocking:
  • await InitializeAsync() - Prevents 50-5000ms UI freeze
  • await StopAsync() - Prevents up to 2000ms UI freeze
  • await ShutdownAsync() - Non-blocking shutdown
  • await GetOutputDevicesAsync() - Non-blocking device enumeration
Synchronous Initialization (Console Apps)
// Default initialization (48kHz, stereo, 512 frames)
OwnaudioNet.Initialize();

// Custom configuration
var config = new AudioConfig
{
    SampleRate = 44100,
    Channels = 2,
    BufferSize = 256
};
OwnaudioNet.Initialize(config);

// Mock engine for testing (no hardware required)
OwnaudioNet.Initialize(config, useMockEngine: true);

// Shutdown
OwnaudioNet.Shutdown();
Async Initialization (UI Apps) ⭐ RECOMMENDED
// Default async initialization
await OwnaudioNet.InitializeAsync();

// Custom async configuration
var config = new AudioConfig
{
    SampleRate = 44100,
    Channels = 2,
    BufferSize = 256
};
await OwnaudioNet.InitializeAsync(config);

// With cancellation token
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
await OwnaudioNet.InitializeAsync(config, useMockEngine: false, cts.Token);

// Async device enumeration
var devices = await OwnaudioNet.GetOutputDevicesAsync();
foreach (var device in devices)
{
    Console.WriteLine($"Device: {device.Name}");
}

// Async shutdown
await OwnaudioNet.ShutdownAsync();
Method Description Recommended For
Initialize() Initialize with default settings (⚠️ BLOCKS 50-200ms) Console apps
Initialize(AudioConfig) Initialize with custom config (⚠️ BLOCKS 50-5000ms) Console apps
Initialize(AudioConfig, bool) Initialize with mock engine (⚠️ BLOCKS 50-5000ms) Console apps, testing
InitializeAsync() ✅ Async init with default settings (NON-BLOCKING) UI apps (WPF, MAUI, Avalonia)
InitializeAsync(AudioConfig) ✅ Async init with custom config (NON-BLOCKING) UI apps (WPF, MAUI, Avalonia)
InitializeAsync(AudioConfig, bool, CancellationToken) ✅ Async init with cancellation (NON-BLOCKING) UI apps with timeout control
Shutdown() Shutdown and release resources (⚠️ BLOCKS up to 2000ms) Console apps
ShutdownAsync() ✅ Async shutdown (NON-BLOCKING) UI apps (WPF, MAUI, Avalonia)
GetOutputDevicesAsync() ✅ Get output devices async (NON-BLOCKING) UI apps
GetInputDevicesAsync() ✅ Get input devices async (NON-BLOCKING) UI apps

Platform Initialization Times

Platform Typical Time Maximum Time
Windows WASAPI 50-100ms 200ms
Linux PulseAudio 100-500ms 5000ms ⚠️
macOS Core Audio 50-150ms 300ms

Audio Sources

FileSource

File-based audio source with decoding and SoundTouch support.

FileSource Usage
// Create from file
var source = new FileSource("music.mp3");

// Configure playback
source.Volume = 0.8f;          // Volume (0.0-1.0)
source.Loop = true;             // Enable looping
source.Tempo = 1.2f;            // 20% faster (0.5-2.0)
source.PitchShift = -2.0f;      // 2 semitones lower (-12..+12)

// Control playback
source.Play();
source.Pause();
source.Stop();
source.Seek(30.0);  // Seek to 30 seconds

// Get info
double position = source.Position;  // Current position (seconds)
double duration = source.Duration;  // Total duration (seconds)
AudioState state = source.State;    // Playing/Paused/Stopped

// Cleanup
source.Dispose();

Properties

Property Type Description
Id Guid Unique source identifier
State AudioState Current playback state
Volume float Volume level (0.0-1.0)
Loop bool Enable/disable looping
Position double Current position in seconds
Duration double Total duration in seconds
Tempo float Playback tempo (0.5-2.0, 1.0 = normal)
PitchShift float Pitch shift in semitones (-12..+12)
IsEndOfStream bool True if reached end of file

Supported Formats

SampleSource

Play audio from memory samples.

SampleSource Usage
// Generate or load samples
float[] samples = GenerateAudioSamples();

// Create source from existing samples
var config = new AudioConfig
{
    SampleRate = 48000,
    Channels = 2
};
var source = new SampleSource(samples, config);

// OR create empty source for dynamic updates
var dynamicSource = new SampleSource(
    bufferSizeInFrames: 48000,  // 1 second buffer
    config: config
);
// dynamicSource.AllowDynamicUpdate is automatically true

// Update samples dynamically (only works if AllowDynamicUpdate is enabled)
float[] newSamples = GenerateNewSamples();
dynamicSource.SubmitSamples(newSamples);

// Playback control
source.Play();
source.Loop = true;

InputSource

Real-time audio input from microphone or line-in.

InputSource Usage
// Initialize OwnaudioNET (engine must be running)
OwnaudioNet.Initialize();

// Create input source (requires AudioEngineWrapper)
var input = new InputSource(
    engine: OwnaudioNet.Engine,
    bufferSizeInFrames: 8192  // Optional, default is 8192
);

// Add to mixer and start
mixer.AddSource(input);
input.Play();

GhostTrackSource

Silent source for synchronization timing.

GhostTrackSource Usage
// Create ghost track with duration
var ghost = new GhostTrackSource(
    durationInSeconds: 180.0,  // 3 minutes
    sampleRate: 48000,         // Optional, default is 48000
    outputChannels: 2          // Optional, default is 2 (stereo)
);

// Use for sync timing
var syncGroup = mixer.CreateSyncGroup(track1, track2, ghost);

SourceWithEffects

Wrapper for applying effects to sources.

SourceWithEffects Usage
var source = new FileSource("guitar.wav");

// Create source with effects wrapper
var sourceWithFx = new SourceWithEffects(source);

// Add effects to the chain
var reverb = new ReverbEffect
{
    Mix = 0.3f,
    RoomSize = 0.7f,
    Damping = 0.5f
};
sourceWithFx.AddEffect(reverb);

var compressor = new CompressorEffect(
    threshold: 0.5f,
    ratio: 4.0f,
    attackTime: 10.0f,
    releaseTime: 100.0f,
    makeupGain: 1.0f,
    sampleRate: 48000f
);
sourceWithFx.AddEffect(compressor);

// Modify effects dynamically
sourceWithFx.AddEffect(new DelayEffect());
sourceWithFx.RemoveEffect(reverb);
sourceWithFx.SetEffectEnabled(0, false);  // Disable first effect
sourceWithFx.ClearEffects();

AudioMixer

Central mixing engine for multi-track audio playback.

AudioMixer Usage
// Create mixer
var mixer = new AudioMixer(OwnaudioNet.Engine);
mixer.Start();

// Add sources
var drums = new FileSource("drums.wav");
var bass = new FileSource("bass.wav");
var guitar = new FileSource("guitar.wav");

mixer.AddSource(drums);
mixer.AddSource(bass);
mixer.AddSource(guitar);

// Control individual sources
drums.Volume = 0.8f;
bass.Volume = 0.7f;
guitar.Volume = 0.6f;

// Play sources
drums.Play();
bass.Play();
guitar.Play();

// Master controls
mixer.MasterVolume = 0.9f;

// Real-time metering
float leftPeak = mixer.LeftPeak;
float rightPeak = mixer.RightPeak;

// Recording
mixer.StartRecording("output.wav");
// ... playback ...
mixer.StopRecording();

// Cleanup
mixer.Stop();
mixer.Dispose();

Properties

Property Type Description
MasterVolume float Master volume level (0.0-1.0)
IsRunning bool True if mixer is running
SourceCount int Number of active sources
LeftPeak float Left channel peak level
RightPeak float Right channel peak level
IsRecording bool True if currently recording
EnableAutoDriftCorrection bool Enable automatic drift correction

Methods

Method Description
Start() Start the mixer
Stop() Stop the mixer
AddSource(IAudioSource) Add audio source to mixer
RemoveSource(Guid) Remove source by ID
RemoveAllSources() Remove all sources
GetSource(Guid) Get source by ID
AddMasterEffect(IEffectProcessor) Add effect to master chain
RemoveMasterEffect(IEffectProcessor) Remove effect from master chain
StartRecording(string) Start recording to WAV file
StopRecording() Stop recording

Audio Effects

OwnaudioNET includes 15+ professional audio effects.

ReverbEffect

Room reverb with multiple presets.

ReverbEffect Usage
var reverb = new ReverbEffect
{
    RoomSize = 0.7f,       // Room size (0-1)
    Damping = 0.5f,        // High frequency damping (0-1)
    Width = 1.0f,          // Stereo width (0-1)
    WetLevel = 0.33f,      // Wet signal level (0-1)
    DryLevel = 0.7f,       // Dry signal level (0-1)
    Gain = 0.015f,         // Input gain
    Mix = 0.5f             // Wet/dry mix (0-1)
};

// Load preset
reverb.SetPreset(ReverbPreset.LargeHall);

CompressorEffect

Dynamic range compressor.

CompressorEffect Usage
// Create compressor with constructor parameters
var compressor = new CompressorEffect(
    threshold: 0.5f,      // Threshold level (0-1, where 1.0 = 0dB, 0.5 = -6dB)
    ratio: 4.0f,          // Compression ratio (1:1 - 100:1)
    attackTime: 100f,     // Attack time in ms (0.1-1000)
    releaseTime: 200f,    // Release time in ms (1-2000)
    makeupGain: 1.0f,     // Makeup gain as linear multiplier (0.1-10.0)
    sampleRate: 48000f
);

// Or use a preset
var compressor2 = new CompressorEffect(CompressorPreset.VocalGentle, sampleRate: 48000f);

Equalizer30BandEffect

30-band graphic equalizer.

Equalizer30BandEffect Usage
var eq = new Equalizer30BandEffect();

// Set individual bands (-12 to +12 dB)
eq[0] = 3.0f;              // Boost first band (20Hz) by 3dB
eq[10] = -2.0f;            // Cut band 10 (200Hz) by 2dB

// Or use SetBandGain method with frequency and Q
eq.SetBandGain(15, 1000f, 1.0f, 2.0f);  // band, frequency, Q, gain in dB

// Use a preset
eq.SetPreset(Equalizer30Preset.Rock);

// Get all current gains
float[] gains = eq.GetAllGains();

DelayEffect

Echo/delay with feedback.

DelayEffect Usage
var delay = new DelayEffect
{
    Time = 375,            // Delay time in ms (1-5000)
    Repeat = 0.35f,        // Feedback amount (0-1)
    Mix = 0.3f,            // Wet/dry mix (0-1)
    Damping = 0.25f        // High-frequency damping (0-1)
};

// Or use a preset
delay.SetPreset(DelayPreset.ClassicEcho);

ChorusEffect

Chorus with multiple voices.

ChorusEffect Usage
var chorus = new ChorusEffect
{
    Rate = 1.0f,           // LFO rate in Hz (0.1-10.0)
    Depth = 0.5f,          // Modulation depth (0-1)
    Mix = 0.5f,            // Wet/dry mix (0-1)
    Voices = 3             // Number of voices (2-6)
};

// Or use a preset
chorus.SetPreset(ChorusPreset.VocalLush);

DistortionEffect

Distortion effect with soft clipping.

DistortionEffect Usage
var distortion = new DistortionEffect
{
    Drive = 2.0f,          // Drive amount (1.0-10.0)
    Mix = 1.0f,            // Wet/dry mix (0-1)
    OutputGain = 0.5f      // Output gain compensation (0.1-1.0)
};

// Or use a preset
distortion.SetPreset(DistortionPreset.ClassicRock);

LimiterEffect

Peak limiter with lookahead.

LimiterEffect Usage
// Create limiter with constructor parameters
var limiter = new LimiterEffect(
    sampleRate: 48000f,
    threshold: -3.0f,     // Threshold in dB (-20 to 0)
    ceiling: -0.1f,       // Output ceiling in dB (-2 to 0)
    release: 50.0f,       // Release time in ms (1-1000)
    lookAheadMs: 5.0f     // Look-ahead time in ms (1-20)
);

// Or use a preset
var limiter2 = new LimiterEffect(sampleRate: 48000f, preset: LimiterPreset.Mastering);

// Check if limiting is active
bool isLimiting = limiter.IsLimiting;
float gainReduction = limiter.GetGainReductionDb();

FlangerEffect

Flanger effect with variable delay modulation.

FlangerEffect Usage
var flanger = new FlangerEffect
{
    Rate = 0.5f,           // LFO rate in Hz (0.1-5.0)
    Depth = 0.8f,          // Modulation depth (0-1)
    Feedback = 0.6f,       // Feedback amount (0-0.95)
    Mix = 0.5f             // Wet/dry mix (0-1)
};

// Or use a preset
flanger.SetPreset(FlangerPreset.Classic);

PhaserEffect

Phaser effect with all-pass filter stages.

PhaserEffect Usage
var phaser = new PhaserEffect
{
    Rate = 0.5f,           // LFO rate in Hz (0.1-10.0)
    Depth = 0.7f,          // Modulation depth (0-1)
    Feedback = 0.5f,       // Feedback amount (0-0.95)
    Mix = 0.5f,            // Wet/dry mix (0-1)
    Stages = 4             // Number of stages (2-8)
};

// Or use a preset
phaser.SetPreset(PhaserPreset.Vintage);

AutoGainEffect

Automatic gain control processor.

AutoGainEffect Usage
var autoGain = new AutoGainEffect
{
    TargetLevel = 0.25f,         // Target level (0.01-1.0)
    AttackCoefficient = 0.99f,   // Attack coefficient (0.9-0.999)
    ReleaseCoefficient = 0.999f, // Release coefficient (0.9-0.9999)
    GateThreshold = 0.001f,      // Gate threshold (0.0001-0.01)
    MaximumGain = 4.0f,          // Maximum gain (1.0-10.0)
    MinimumGain = 0.25f          // Minimum gain (0.1-1.0)
};

// Or use a preset
autoGain.SetPreset(AutoGainPreset.Voice);

EnhancerEffect

Harmonic enhancer for adding presence.

EnhancerEffect Usage
var enhancer = new EnhancerEffect
{
    Mix = 0.2f,                  // Mix amount (0-1)
    Gain = 2.5f,                 // Pre-saturation gain (0.1-10)
    CutoffFrequency = 4000f      // High-pass cutoff in Hz (100-20000)
};

// Or use a preset
enhancer.SetPreset(EnhancerPreset.VocalClarity);

OverdriveEffect

Tube-like overdrive effect.

OverdriveEffect Usage
var overdrive = new OverdriveEffect
{
    Gain = 2.0f,           // Input gain (1.0-5.0)
    Tone = 0.5f,           // Tone control (0=dark, 1=bright)
    Mix = 1.0f,            // Wet/dry mix (0-1)
    OutputLevel = 0.7f     // Output level (0.1-1.0)
};

// Or use a preset
overdrive.SetPreset(OverdrivePreset.Blues);

RotaryEffect

Leslie speaker simulator with horn and rotor.

RotaryEffect Usage
var rotary = new RotaryEffect
{
    HornSpeed = 6.0f,      // Horn rotation speed in Hz (2.0-15.0)
    RotorSpeed = 1.0f,     // Rotor rotation speed in Hz (0.5-5.0)
    Intensity = 0.7f,      // Effect intensity (0-1)
    Mix = 1.0f,            // Wet/dry mix (0-1)
    IsFast = false         // Fast/slow speed switch
};

// Or use a preset
rotary.SetPreset(RotaryPreset.Hammond);

DynamicAmpEffect

Adaptive volume control with dynamics preservation.

DynamicAmpEffect Usage
var dynamicAmp = new DynamicAmpEffect
{
    TargetLevel = -9.0f,         // Target RMS level in dB (-40 to 0)
    AttackTime = 0.2f,           // Attack time in seconds (min 0.001)
    ReleaseTime = 0.8f,          // Release time in seconds (min 0.001)
    NoiseGate = 0.005f,          // Noise threshold (0-1)
    MaxGain = 10.0f              // Maximum gain (> 0)
};

// Or use a preset
dynamicAmp.SetPreset(DynamicAmpPreset.Music);

Available Effects Summary

Effect Description
ReverbEffectRoom reverb with presets
CompressorEffectDynamic range compressor
DelayEffectEcho/delay with ping-pong
ChorusEffectChorus with multiple voices
DistortionEffectMultiple distortion modes
EqualizerEffectParametric EQ
Equalizer30BandEffect30-band graphic EQ
LimiterEffectPeak limiter
FlangerEffectFlanger effect
PhaserEffectPhaser effect
AutoGainEffectAutomatic gain control
EnhancerEffectHarmonic enhancer
OverdriveEffectTube overdrive
RotaryEffectLeslie speaker simulator
DynamicAmpEffectDynamic amplifier

Synchronization

Synchronized Playback

Perfect sample-accurate synchronization of multiple sources.

Tip for the best synchronization Tip for the best sync Use the same file types and avoid using mp3 files. MP3 files are difficult to sync accurately due to their structure, so inaccuracies may occur.
Sync Group Usage
// Create sources
var drums = new FileSource("drums.wav");
var bass = new FileSource("bass.wav");
var guitar = new FileSource("guitar.wav");

// Add to mixer
mixer.AddSource(drums);
mixer.AddSource(bass);
mixer.AddSource(guitar);

// Create sync group
var syncGroup = mixer.CreateSyncGroup(drums, bass, guitar);

// Start all sources in perfect sync
mixer.StartSyncGroup(syncGroup.Id);

// Stop sync group
mixer.StopSyncGroup(syncGroup.Id);

// Remove sync group
mixer.RemoveSyncGroup(syncGroup.Id);

Drift Correction

Drift Correction
// Enable automatic drift correction
mixer.EnableAutoDriftCorrection = true;

// Drift correction monitors timing differences between sources
// and automatically adjusts to maintain perfect synchronization

Interfaces

IAudioSource

Base interface for all audio sources.

IAudioSource Interface
public interface IAudioSource : IDisposable
{
    // Properties
    Guid Id { get; }
    AudioState State { get; }
    float Volume { get; set; }
    bool Loop { get; set; }
    double Position { get; }
    double Duration { get; }
    bool IsEndOfStream { get; }
    float Tempo { get; set; }
    float PitchShift { get; set; }
    
    // Methods
    void Play();
    void Pause();
    void Stop();
    bool Seek(double positionInSeconds);
    int ReadSamples(Span buffer, int frameCount);
    
    // Events
    event EventHandler StateChanged;
    event EventHandler BufferUnderrun;
    event EventHandler Error;
}

IEffectProcessor

Base interface for audio effects.

IEffectProcessor Interface
public interface IEffectProcessor
{
    bool IsEnabled { get; set; }
    void Process(Span buffer, int frameCount);
    void Reset();
}

ISynchronizable

Interface for synchronizable sources.

ISynchronizable Interface
public interface ISynchronizable
{
    void PrepareForSync();
    void StartSync();
    void ResyncTo(double targetPosition);
    double GetSyncPosition();
}

Performance

Latency

CPU Usage

Memory

Thread Safety

OwnaudioNET uses a multi-threaded architecture:

All public methods are thread-safe with lock-free buffer management.

Related Documentation