NET OwnaudioNET API Reference
High-level audio API with professional features including multi-track mixing, effects processing, synchronization, and real-time audio manipulation.
Overview
OwnaudioNET extends Ownaudio.Core with high-level features:
- Multi-track mixing - Unlimited simultaneous audio sources
- 15+ professional effects - Reverb, compressor, EQ, and more
- Master Clock synchronization - Sample-accurate timeline-based sync with drift correction
- DAW-style features - Realtime/offline rendering modes, start offsets
- Tempo and pitch control - Independent time-stretch and pitch-shift via SoundTouch
- Recording - Mix-down to WAV format
- Real-time metering - Peak and RMS level monitoring
- Thread-safe architecture - Lock-free buffers for glitch-free audio
Initialization
OwnaudioNet Class
Central initialization and configuration for OwnaudioNET.
await InitializeAsync()- Prevents 50-5000ms UI freezeawait StopAsync()- Prevents up to 2000ms UI freezeawait ShutdownAsync()- Non-blocking shutdownawait GetOutputDevicesAsync()- Non-blocking device enumeration
// Default initialization (48kHz, stereo, 512 frames)
OwnaudioNet.Initialize();
// Custom configuration
var config = new AudioConfig
{
SampleRate = 44100,
Channels = 2,
BufferSize = 256
};
OwnaudioNet.Initialize(config);
// Shutdown
OwnaudioNet.Shutdown();
// Default async initialization
await OwnaudioNet.InitializeAsync();
// Custom async configuration
var config = new AudioConfig
{
SampleRate = 44100,
Channels = 2,
BufferSize = 256
};
await OwnaudioNet.InitializeAsync(config);
// 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 |
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) |
Shutdown() |
Shutdown and release resources (⚠️ BLOCKS up to 2000ms) | Console apps |
ShutdownAsync() |
✅ Async shutdown (NON-BLOCKING) | UI apps (WPF, MAUI, Avalonia) |
Audio Sources
FileSource
File-based audio source with decoding, SoundTouch support, and Master Clock synchronization.
// 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.8-1.2)
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.8-1.2, 1.0 = normal) |
PitchShift |
float | Pitch shift in semitones (-12..+12) |
StartOffset |
double | Timeline start position (for Master Clock sync) |
SampleSource
Play audio from memory samples with optional dynamic updates.
// 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
);
// Update samples dynamically
float[] newSamples = GenerateNewSamples();
dynamicSource.SubmitSamples(newSamples);
// Playback control
source.Play();
source.Loop = true;
InputSource
Real-time audio input from microphone or line-in.
// Initialize OwnaudioNET (engine must be running)
OwnaudioNet.Initialize();
// Create input source
var input = new InputSource(
engine: OwnaudioNet.Engine,
bufferSizeInFrames: 8192 // Optional, default is 8192
);
// Add to mixer and start
mixer.AddSource(input);
input.Play();
SourceWithEffects
Wrapper for applying effects chains to any audio source.
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
reverb.Enabled = false; // Bypass effect
sourceWithFx.RemoveEffect(compressor);
sourceWithFx.ClearEffects();
AudioMixer
Central mixing engine for multi-track audio playback with Master Clock synchronization.
// 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 |
MasterClock |
MasterClock | Master clock for timeline synchronization |
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 |
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 with preset support.
Quick Start - Adding Effects
// Create source and wrap with effects capability
var fileSource = new FileSource("audio.mp3");
var source = new SourceWithEffects(fileSource);
// Add effects
var compressor = new CompressorEffect(CompressorPreset.VocalGentle);
var reverb = new ReverbEffect(ReverbPreset.VocalBooth);
var limiter = new LimiterEffect(48000f, LimiterPreset.Mastering);
source.AddEffect(compressor);
source.AddEffect(reverb);
source.AddEffect(limiter);
// Control effects
reverb.Enabled = false; // Bypass
compressor.Threshold = 0.6f; // Adjust parameter
// Add to mixer
mixer.AddSource(source);
mixer.Start();
Available Effects
| Category | Effects |
|---|---|
| Dynamics | Compressor, Limiter, AutoGain, DynamicAmp |
| Frequency | Equalizer (10-band), Equalizer30Band, Enhancer |
| Modulation | Chorus, Flanger, Phaser, Rotary |
| Spatial | Reverb, Delay |
| Distortion | Distortion, Overdrive |
See Also: Full Effects Documentation for detailed parameters, all presets, technical details, and advanced usage examples.
Synchronization
Master Clock Architecture
OwnaudioNET uses a professional DAW-style Master Clock for sample-accurate synchronization with timeline positioning and automatic drift correction.
// 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);
// Attach sources to Master Clock
drums.AttachToClock(mixer.MasterClock);
bass.AttachToClock(mixer.MasterClock);
guitar.AttachToClock(mixer.MasterClock);
// Optional: Set start offsets (timeline positioning)
drums.StartOffset = 0.0; // Starts at 0 seconds
bass.StartOffset = 0.0; // Starts at 0 seconds
guitar.StartOffset = 2.0; // Starts at 2 seconds (delayed)
// Start mixer
mixer.Start();
// Start all sources for playback (IMPORTANT!)
drums.Play();
bass.Play();
guitar.Play();
// All attached sources now play in perfect sync with Master Clock
// Timeline control
mixer.MasterClock.SeekTo(10.0); // Seek all tracks to 10 seconds
// Get current timeline position
double currentTime = mixer.MasterClock.CurrentTimestamp;
long samplePosition = mixer.MasterClock.CurrentSamplePosition;
// Rendering modes
mixer.MasterClock.Mode = ClockMode.Realtime; // Default: dropout → silence + event
mixer.MasterClock.Mode = ClockMode.Offline; // Offline: blocking, deterministic
Automatic Drift Correction
The Master Clock automatically maintains perfect synchronization with sub-10ms drift tolerance.
// Drift correction is automatic with Master Clock
// Tolerance: 10ms (~480 samples @ 48kHz)
// When drift exceeds tolerance, sources automatically resync
// Monitor dropout events (occurs when sources can't keep up)
mixer.TrackDropout += (sender, e) =>
{
Console.WriteLine($"Track dropout: {e.TrackName}");
Console.WriteLine($" At time: {e.MasterTimestamp:F3}s");
Console.WriteLine($" Missed frames: {e.MissedFrames}");
Console.WriteLine($" Reason: {e.Reason}");
};
Timeline Features
// DAW-style timeline positioning
var intro = new FileSource("intro.wav");
var verse = new FileSource("verse.wav");
var chorus = new FileSource("chorus.wav");
intro.AttachToClock(mixer.MasterClock);
verse.AttachToClock(mixer.MasterClock);
chorus.AttachToClock(mixer.MasterClock);
// Position tracks on timeline
intro.StartOffset = 0.0; // 0:00
verse.StartOffset = 8.5; // 0:08.5
chorus.StartOffset = 24.3; // 0:24.3
mixer.AddSource(intro);
mixer.AddSource(verse);
mixer.AddSource(chorus);
mixer.Start();
// Start all sources
intro.Play();
verse.Play();
chorus.Play();
// Tracks play at their scheduled times based on StartOffset
// Timeline navigation
mixer.MasterClock.SeekTo(20.0); // Jump to 20 seconds - all tracks sync