-
-
Notifications
You must be signed in to change notification settings - Fork 2
Home
- Overview
- Installation & Setup
- Quick Start
- Core Classes
- Audio Effects
- Advanced Usage
- Platform Support
- API Reference
OwnAudio is a cross-platform audio library for .NET that provides comprehensive audio playback, recording, and processing capabilities. Built on FFmpeg and PortAudio, it offers a unified interface for audio operations across Windows, macOS, and Linux.
Key Features:
- Multi-source audio mixing and playback
- Real-time audio input/output
- Built-in audio effects library
- Cross-platform compatibility
- High-quality audio processing
By default, OwnAudio includes Miniaudio which works out of the box. For extended functionality, you can optionally configure FFmpeg 6 and Portaudio 2.
// Extract FFmpeg 6 and Portaudio 2 DLL to a folder, then:
OwnAudio.Initialize(@"C:\path\to\libraries\");
sudo apt update
sudo apt install portaudio19-dev ffmpeg
// Auto-detection - no path needed
OwnAudio.Initialize();
brew install portaudio
brew install ffmpeg@6
// Auto-detection - no path needed
OwnAudio.Initialize();
// Simple initialization with default settings
bool success = OwnAudio.Initialize();
// With specific host API
bool success = OwnAudio.Initialize(OwnAudioEngine.EngineHostType.WASAPI);
// With custom library path
bool success = OwnAudio.Initialize(@"C:\libraries", OwnAudioEngine.EngineHostType.ASIO);
// Initialize library
if (!OwnAudio.Initialize()) return;
// Get SourceManager instance
var sourceManager = SourceManager.Instance;
// Configure output
SourceManager.OutputEngineOptions = new AudioEngineOutputOptions(
device: OwnAudio.DefaultOutputDevice,
channels: OwnAudioEngine.EngineChannels.Stereo,
sampleRate: 44100,
latency: OwnAudio.DefaultOutputDevice.DefaultHighOutputLatency
);
// Add and play audio file
await sourceManager.AddOutputSource("audio.mp3");
sourceManager.Play();
// Cleanup
sourceManager.Reset();
OwnAudio.Free();
var sourceManager = SourceManager.Instance;
// Add multiple sources
await sourceManager.AddOutputSource("music.mp3");
await sourceManager.AddOutputSource("vocals.wav");
// Control individual volumes
sourceManager.SetVolume(0, 0.8f); // Music at 80%
sourceManager.SetVolume(1, 1.0f); // Vocals at 100%
sourceManager.Play();
Main initialization and device management class.
Properties:
-
IsFFmpegInitialized: FFmpeg initialization status -
IsPortAudioInitialized: PortAudio initialization status -
DefaultOutputDevice: System default output device -
DefaultInputDevice: System default input device -
OutputDevices: Available output devices -
InputDevices: Available input devices
Methods:
-
Initialize(): Initialize with defaults -
Initialize(hostType): Initialize with specific host API -
Initialize(libraryPath, hostType): Initialize with custom paths -
Free(): Release resources
Central audio management system for mixing multiple sources.
Key Properties:
-
Instance: Singleton access -
Sources: List of output sources -
State: Current playback state -
Volume: Master volume -
Position: Current playback position -
Duration: Total duration -
OutputLevels: Real-time output levels -
InputLevels: Real-time input levels
Essential Methods:
-
AddOutputSource(url): Add audio file source -
AddRealTimeSource(volume, channels): Add real-time source -
AddInputSource(volume): Add input recording source -
Play(): Start playback -
Pause(): Pause playback -
Stop(): Stop playback -
Seek(position): Seek to position -
Reset(): Clear all sources
Individual audio file player with advanced controls.
Properties:
-
Duration: Audio file duration -
Position: Current position -
State: Playback state -
Volume: Source volume (0.0-1.0) -
Pitch: Pitch adjustment in semitones (-6.0 to +6.0) -
Tempo: Tempo adjustment as percentage (-20.0 to +20.0) -
CustomSampleProcessor: Custom audio processor
Methods:
-
LoadAsync(url): Load from file/URL -
LoadAsync(stream): Load from stream -
ChangeState(state): Change playback state -
Seek(position): Seek to position
Real-time audio streaming source for live audio data.
Usage:
// Create real-time source
SourceSound source = sourceManager.AddRealTimeSource(0.4f, 1); // 40% volume, mono
// Submit audio samples
float[] samples = GetAudioSamples();
source.SubmitSamples(samples);
OwnAudio includes a comprehensive effects library. All effects inherit from SampleProcessorBase.
| Effect | Description | Key Parameters |
|---|---|---|
| Compressor | Dynamic range control | Threshold, Ratio, Attack, Release |
| Reverb | Spatial reverb effect | Room Size, Damping, Wet/Dry |
| Delay | Echo effect | Time, Repeat, Mix |
| Distortion | Overdrive/distortion | Drive, Mix, Output Gain |
| Chorus | Modulated delay chorus | Rate, Depth, Voices |
| Flanger | Jet-like sweeping effect | Rate, Depth, Feedback |
| Phaser | Phase shift sweeping | Rate, Depth, Stages |
| Equalizer | 10-band parametric EQ | Frequency, Q, Gain |
| Enhancer | Harmonic exciter | Mix, Cut Frequency, Gain |
| Overdrive | Tube-style saturation | Gain, Tone, Mix |
| Rotary | Leslie speaker simulation | Horn/Rotor Speed, Intensity |
| DynamicAmp | Adaptive level control | Target Level, Attack, Release |
// Windows - Professional audio
OwnAudio.Initialize(OwnAudioEngine.EngineHostType.ASIO);
// macOS - Default
OwnAudio.Initialize(OwnAudioEngine.EngineHostType.CoreAudio);
// Linux - Low latency
OwnAudio.Initialize(OwnAudioEngine.EngineHostType.JACK);
// Auto-detect best available
OwnAudio.Initialize(OwnAudioEngine.EngineHostType.None);
-
Idle: Not playing -
Playing: Currently playing -
Paused: Playback paused -
Buffering: Loading audio data -
Recording: Recording audio
-
None: Auto-detect -
ASIO: Windows professional audio -
WASAPI: Windows Audio Session API -
WDMKS: Windows Driver Model -
CoreAudio: macOS audio -
ALSA: Linux audio -
JACK: Professional cross-platform
-
Mono: Single channel -
Stereo: Two channels
new AudioEngineOutputOptions(
device: AudioDevice,
channels: EngineChannels,
sampleRate: int,
latency: double
);
new AudioEngineInputOptions(
device: AudioDevice,
channels: EngineChannels,
sampleRate: int,
latency: double
);
Most operations throw OwnaudioException on failure. Always wrap in try-catch blocks:
try
{
await sourceManager.AddOutputSource("file.mp3");
sourceManager.Play();
}
catch (OwnaudioException ex)
{
Console.WriteLine($"Audio error: {ex.Message}");
}
-
Always initialize: Call
OwnAudio.Initialize()before any operations -
Resource cleanup: Call
Reset()between sessions andFree()when done - Thread safety: Modify playback state from main thread
- Error handling: Wrap operations in try-catch blocks
- Memory management: Dispose sources when no longer needed
-
Buffer sizing: Lower
EngineFramesPerBufferreduces latency but may cause glitches
- Use
EngineFramesPerBuffer = 512for balanced latency/stability - Lower buffer sizes (256) for real-time applications
- Higher buffer sizes (1024+) for file processing
- Monitor
OutputLevels/InputLevelsfor UI feedback - Reset SourceManager between different audio sessions