OwnAudioSharp is a professional cross-platform audio framework featuring a native C++ audio engine for glitch-free, real-time audio processing. After extensive development with pure managed code, we discovered that the .NET Garbage Collector is insurmountable for professional real-time audio - the native engine is now the default, with managed C# implementations available for development and testing.
Native Engine (Default): GC-free C++ audio core eliminates glitches and provides deterministic real-time performance Managed Engines (Optional): Pure C# implementations available for development, testing, and debugging Professional Audio Features: AI-driven vocal separation, audio mastering, advanced chord detection Commercial Quality, Free: Professional tools without licensing costs Truly Cross-Platform: Windows, macOS, Linux, Android, iOS
During the development of OwnAudioSharp 2.0, we invested significant effort into creating a pure managed C# audio engine with zero external dependencies. We implemented:
- β Zero-allocation design - no allocations in real-time audio paths
- β Lock-free ring buffers - wait-free cross-thread communication
- β SIMD optimization - vectorized audio processing
- β Object pooling - reusing buffers to minimize GC pressure
- β Span usage - stack-allocated audio data
Despite these optimizations, the .NET Garbage Collector proved to be insurmountable for professional real-time audio:
β GC pauses are inevitable - Even brief GC pauses (1-10ms) cause audible glitches and dropouts β GC is inherent to managed code - There's no way to completely avoid it in C# β Unpredictable timing - GC can trigger at any moment, breaking real-time guarantees
We introduced a high-performance native C++ audio engine that operates completely outside the GC's control:
β Zero GC interference - Native code runs independently of .NET's GC β Deterministic timing - Guaranteed real-time performance without glitches β Professional quality - Audio processing meets industry standards β Default engine - Automatically used unless you specify otherwise
The native engine automatically selects the best available audio backend:
1. PortAudio (Preferred) - If installed on the system 2. miniaudio (Fallback) - Bundled as embedded resource 3. Managed Engines (Development) - Pure C# implementations (may experience GC glitches)
PortAudio provides the best cross-platform audio performance. Here's how to install it:
# Using Chocolatey
choco install portaudio
# Or download binaries from:
# http://www.portaudio.com/download.html
# Place portaudio.dll in your application directory# Ubuntu/Debian
sudo apt-get install portaudio19-dev
# Fedora/RHEL
sudo dnf install portaudio-devel
# Arch Linux
sudo pacman -S portaudio# Using Homebrew
brew install portaudio
# Using MacPorts
sudo port install portaudioNote: If PortAudio is not found, OwnAudioSharp automatically falls back to the embedded miniaudio library - no installation required for basic functionality.
The pure C# managed engines remain in the API for:
- π§ Development and debugging - easier to step through C# code
- π§ͺ Testing scenarios - when GC pauses are acceptable
- π Educational purposes - learning audio engine architecture
To use managed engines explicitly:
// Use managed engine (may experience GC glitches)
using var engine = AudioEngineFactory.CreateManaged();
// Or platform-specific:
#if WINDOWS
using var engine = new WasapiEngine();
#elif LINUX
using var engine = new PulseAudioEngine();
#elif MACOS
using var engine = new CoreAudioEngine();
#endifVersion 2.1.0+ (Current) - Native engine with PortAudio/miniaudio backends
Version 2.0.0 - Attempted pure managed code (GC issues discovered)
Pre-2.0.0 - Native libraries (miniaudio, portaudio, ffmpeg)
Features you typically only find in commercial software:
-
AI Vocal Separation: State-of-the-art vocal and instrumental track separation using ONNX neural networks
- Multiple quality models:
default,best,karaoke - Professional-grade stem isolation
- Multiple quality models:
-
Audio Mastering: AI-driven matchering - master your tracks to match reference audio
- Automatic EQ matching and spectral analysis
- Professional mastering without expensive plugins
-
Advanced Chord Detection: Musical chord recognition from simple to professional
- Real-time and offline analysis
- Major, minor, diminished, augmented, extended chords (7th, 9th, 11th, 13th)
- Chromagram-based recognition
-
Native C++ Audio Engine (Default):
- GC-free, deterministic real-time audio processing
- PortAudio backend (if installed) or embedded miniaudio fallback
- Professional-grade performance on all platforms
- Zero audio glitches or dropouts
-
Managed C# Engines (Optional):
- Windows (WASAPI), macOS (Core Audio), Linux (PulseAudio), Android (AAudio)
- Pure C# implementation for development and debugging
- Available but may experience GC-related glitches
-
Dual API Layers:
- Low-level Core API for direct engine control
- High-level NET API for professional features
-
Audio Processing:
- Multi-format support (MP3, WAV, FLAC) with built-in decoders
- Real-time effects: reverb, compressor, equalizer, pitch shifting, tempo control
- Multi-source audio mixing with synchronized playback
-
High Performance:
- Native engine: Zero GC interference
- Lock-free ring buffers for thread safety
- SIMD-optimized audio processing
Install-Package OwnAudioSharpdotnet add package OwnAudioSharp- .NET 8.0 or later
- Optional: PortAudio library for best performance (automatically falls back to embedded miniaudio if not available)
The native engine includes:
- PortAudio (preferred) - Install separately for best performance
- miniaudio (fallback) - Embedded as resource, always available
- No installation required - works out of the box with miniaudio
Complete API documentation with examples is available on the official website:
The website includes:
- Complete API reference for all classes and methods
- Step-by-step tutorials and usage examples
- Architecture and design documentation
- Best practices and performance tips
- Professional feature guides (vocal removal, mastering, chord detection)
OwnAudioSharp's audio engine is built on a modular architecture with platform-specific implementations. Detailed documentation is available for each component:
- Ownaudio.Core - Cross-platform interfaces, audio decoders (MP3/WAV/FLAC), lock-free buffers, and zero-allocation primitives
- Ownaudio.Windows - WASAPI implementation for Windows (10+)
- Ownaudio.Linux - PulseAudio implementation for Linux
- Ownaudio.macOS - Core Audio implementation for macOS
- Ownaudio.Android - AAudio implementation for Android (API 26+)
Each platform implementation includes:
- Architecture overview and native API details
- Performance characteristics and latency information
- Platform-specific requirements and dependencies
- Usage examples and best practices
- Troubleshooting guides
For low-level engine development or platform-specific optimization, check out the individual platform documentation.
using Ownaudio.Core;
// Create NATIVE audio engine (DEFAULT - GC-free!)
// Automatically uses PortAudio if available, otherwise miniaudio
using var engine = AudioEngineFactory.CreateDefault();
// Configure and start the engine
var config = new AudioConfig
{
SampleRate = 48000,
Channels = 2,
BufferSize = 512
};
engine.Initialize(config);
engine.Start();
// Create decoder and play audio
using var decoder = AudioDecoderFactory.Create("music.mp3",
targetSampleRate: 48000,
targetChannels: 2);
while (true)
{
var result = decoder.DecodeNextFrame();
if (result.IsEOF) break;
// Native engine - no GC glitches!
engine.Send(result.Frame.Samples);
}
engine.Stop();// Initialize OwnaudioNET (uses native engine by default)
await OwnaudioNet.InitializeAsync();
// Create file source
var source = new FileSource("music.mp3");
// Create mixer and add source
var mixer = new AudioMixer(OwnaudioNet.Engine);
mixer.AddSource(source);
mixer.Start();
// Play the source
source.Play();
// Apply professional effects
var reverb = new ReverbEffect { Mix = 0.3f, RoomSize = 0.7f };
var compressor = new CompressorEffect(threshold: 0.5f, ratio: 4.0f, sampleRate: 48000f);
var sourceWithEffects = new SourceWithEffects(source, reverb, compressor);
// Control playback
source.Volume = 0.8f;
source.Seek(30.0); // seconds// Create MANAGED audio engine (pure C#)
// Note: May experience GC-related audio glitches
using var engine = AudioEngineFactory.CreateManaged();
// Or platform-specific:
#if WINDOWS
using var engine = new WasapiEngine();
#elif LINUX
using var engine = new PulseAudioEngine();
#elif MACOS
using var engine = new CoreAudioEngine();
#endif
engine.Initialize(AudioConfig.Default);
engine.Start();
// ... rest of your codeOwnAudioSharp is completely free and open-source, providing professional-grade audio features without licensing costs. If you find this library useful, especially for commercial purposes, consider supporting its continued development:
Why support?
- Enables continued development and new features
- Ensures timely bug fixes and updates
- Improves documentation and examples
- Saves you thousands in commercial audio library licensing costs
Your support helps keep professional audio technology accessible to everyone!
See the LICENSE file for details.
Special thanks to the creators of:
- DryWetMidi - .NET library to work with MIDI data and MIDI devices
- soundtouch.net - .NET wrapper for SoundTouch
- Avalonia - Cross-platform .NET UI framework
