API Reference

Complete reference documentation for the OwnAudioSharp library. This guide covers all public classes, methods, and properties.

Note: All examples assume you have initialized OwnAudio with OwnAudio.Initialize() and properly disposed with OwnAudio.Free().

OwnAudio Class

Ownaudio

The main entry point for the OwnAudio library. Handles initialization and cleanup of the audio system.

Static Methods

Initialize()

public static void Initialize(string libraryPath = null)

Initializes the OwnAudio system with optional library path for FFmpeg and PortAudio.

Parameter Type Description
libraryPath string Optional path to FFmpeg and PortAudio libraries. If null, uses MiniAudio.
Example
try 
{
    OwnAudio.Initialize();
    // Your audio code here
}
finally 
{
    OwnAudio.Free(); // Always cleanup
}

SourceManager Class

Ownaudio.Sources

Manages multiple audio sources and provides playback control. Uses singleton pattern for global access.

Properties

Instance

public static SourceManager Instance { get; }

Gets the singleton instance of SourceManager.

IsPlaying

public bool IsPlaying { get; }

Gets whether any audio source is currently playing.

Duration

public TimeSpan Duration { get; }

Gets the total duration of the longest audio source.

Position

public TimeSpan Position { get; }

Gets the current playback position.

Sources

public IReadOnlyList<Source> Sources { get; }

Gets a read-only list of all audio sources.

Methods

AddOutputSource()

public async Task<Source> AddOutputSource(string filePath, string name = null)

Adds an audio file as an output source for playback.

Parameter Type Description
filePath string Path to the audio file to load
name string Optional name for the source. If null, uses filename.
Example
var sourceManager = SourceManager.Instance;

// Add with automatic name
var source1 = await sourceManager.AddOutputSource("music.mp3");

// Add with custom name
var source2 = await sourceManager.AddOutputSource("sfx.wav", "SoundEffect");

SourceInput Class

public async Task<SourceInput> AddInputSource(string name = null)

Adds an input source for audio recording from the default microphone.

AddRealTimeSource()

public SourceSound AddRealTimeSource(float volume, int channels, string name = null)

Creates a real-time audio source for live audio generation and streaming.

Parameter Type Description
volume float Initial volume (0.0 to 1.0)
channels int Number of audio channels (1 = mono, 2 = stereo)
name string Optional name for the source

Play()

public void Play() public void Play(string outputFile, int bitDepth)

Starts playback of all audio sources, or starts recording to a file.

Pause()

public void Pause()

Pauses playback of all audio sources.

Stop()

public void Stop()

Stops playback and resets position to the beginning.

Seek()

public void Seek(TimeSpan position)

Seeks to a specific position in the audio.

Indexer Access

public Source this[string name] { get; } public Source this[int index] { get; }

Accesses sources by name or index.

Example
// Access by name
sourceManager["BackgroundMusic"].Volume = 0.5f;

// Access by index
sourceManager[0].Volume = 0.8f;

Source Class

Ownaudio.Sources

Represents an individual audio source with playback controls and effects.

Properties

Volume

public float Volume { get; set; }

Gets or sets the volume level (0.0 to 1.0).

Tempo

public double Tempo { get; set; }

Gets or sets the tempo change in percentage (-20 to +20). Affects speed without changing pitch.

Pitch

public double Pitch { get; set; }

Gets or sets the pitch change in semitones (-6 to +6). Affects pitch without changing tempo.

Duration

public TimeSpan Duration { get; }

Gets the total duration of the audio source.

State

public SourceState State { get; }

Gets the current state (Idle, Playing, Paused, Stopped).

Methods

GetFloatAudioData()

public float[] GetFloatAudioData(TimeSpan startTime)

Extracts audio data as float array starting from specified time.

GetByteAudioData()

public byte[] GetByteAudioData(TimeSpan startTime)

Extracts audio data as byte array starting from specified time.

Example
var source = sourceManager[0];

// Adjust playback parameters
source.Volume = 0.7f;       // 70% volume
source.Tempo = 10.0;        // 10% faster
source.Pitch = 2.0;         // 2 semitones higher

// Extract audio data
float[] audioData = source.GetFloatAudioData(TimeSpan.Zero);

SourceSound Class

Ownaudio.Sources

Real-time audio source for live audio generation and streaming.

Methods

SubmitSamples()

public void SubmitSamples(float[] samples)

Submits audio samples for real-time playback.

Example
var realtimeSource = sourceManager.AddRealTimeSource(1.0f, 2);

// Generate sine wave
float[] buffer = new float[1024 * 2]; // Stereo
for (int i = 0; i < 1024; i++)
{
    float sample = (float)Math.Sin(2 * Math.PI * 440 * i / 44100);
    buffer[i * 2] = sample;     // Left
    buffer[i * 2 + 1] = sample; // Right
}

realtimeSource.SubmitSamples(buffer);
Example
// Example: Receive audio data from network and play in real-time
var networkSource = sourceManager.AddRealTimeSource(1.0f, 2);

// Network audio receiver (pseudo-code)
networkClient.OnAudioDataReceived += (audioData) =>
{
    // Convert received network data to float array
    float[] samples = ConvertBytesToFloats(audioData);

    // Submit to real-time source for immediate playback
    networkSource.SubmitSamples(samples);
};

sourceManager.Play();

Reverb Effect

Ownaudio.Processors

Professional quality reverb effect based on the Freeverb algorithm.

Constructor

public Reverb(float roomSize, float damping, float wetLevel, float dryLevel)
Parameter Type Description
roomSize float Size of the reverb space (0.0 to 1.0)
damping float High frequency damping (0.0 to 1.0)
wetLevel float Level of reverb effect (0.0 to 1.0)
dryLevel float Level of original signal (0.0 to 1.0)
Example
// Create hall reverb
var hallReverb = new Reverb(0.8f, 0.2f, 0.5f, 0.7f);
sourceManager.CustomSampleProcessor = hallReverb;

// Create room reverb
var roomReverb = new Reverb(0.4f, 0.6f, 0.3f, 0.8f);
sourceManager.CustomSampleProcessor = roomReverb;

Delay Effect

Ownaudio.Processors

Echo effect with configurable delay time and feedback.

Constructor

public Delay(int delayMs, float feedback, float wetLevel, int sampleRate)
Parameter Type Description
delayMs int Delay time in milliseconds
feedback float Amount of feedback (0.0 to 0.95)
wetLevel float Level of delay effect (0.0 to 1.0)
sampleRate int Audio sample rate (typically 44100)

Compressor Effect

Ownaudio.Processors

Dynamic range compressor for controlling audio dynamics.

Constructor

public Compressor(float threshold, float ratio, float attackMs, float releaseMs, float makeupGain, float sampleRate)

Equalizer Effect

Ownaudio.Processors

30-band parametric equalizer with dynamic Q-factor optimization.

Constructor

public Equalizer(int sampleRate)

Methods

SetBandGain()

public void SetBandGain(int band, float frequency, float gain, float q)
Example
var equalizer = new Equalizer(44100);

// Boost bass at 100Hz
equalizer.SetBandGain(0, 100f, 3.0f, 1.0f);

// Cut harsh frequencies at 3kHz
equalizer.SetBandGain(10, 3000f, -2.0f, 2.0f);

sourceManager.CustomSampleProcessor = equalizer;

AudioEngine Configuration

Ownaudio.Engines

Configure audio engine parameters for optimal performance.

Engine Options

Engine Configuration
// Configure output engine
SourceManager.OutputEngineOptions = new AudioEngineOutputOptions(
    OwnAudioEngine.EngineChannels.Stereo, 
    44100,    // Sample rate
    0.02      // Latency (20ms)
);

// Configure input engine
SourceManager.InputEngineOptions = new AudioEngineInputOptions(
    OwnAudioEngine.EngineChannels.Mono, 
    44100, 
    0.02
);

// Set buffer size
SourceManager.EngineFramesPerBuffer = 512;

Chord Detection

Ownaudio.Utilities.OwnChordDetect

Advanced chord detection and musical analysis capabilities.

DetectChords() Extension Method

public static (List<TimedChord> timedChords, string detectedKey, double tempo) DetectChords(this SourceManager sourceManager, string sourceName, float intervalSecond = 1.0f)
Example
// Detect chords from audio file
var (chords, key, tempo) = sourceManager.DetectChords("MusicTrack", 1.0f);

Console.WriteLine($"Key: {key}, Tempo: {tempo} BPM");
foreach (var chord in chords)
{
    Console.WriteLine($"{chord.StartTime:F1}s: {chord.ChordName} ({chord.Confidence:F2})");
}

Professional Matchering

Ownaudio.Utilities.Matchering

Intelligent audio matchering with 30-band EQ and psychoacoustic analysis.

AudioAnalyzer Class

ProcessEQMatching()

public void ProcessEQMatching(string sourceFile, string targetFile, string outputFile)
Example
var analyzer = new AudioAnalyzer();

// Match source to reference track
analyzer.ProcessEQMatching(
    "my_track.wav",       // Source audio
    "reference.wav",      // Professional reference
    "mastered.wav"        // Output file
);

// Use playback system presets
analyzer.ProcessWithPreset(
    "source.wav", 
    "club_version.wav", 
    PlaybackSystem.ClubPA
);

Audio Visualization

Ownaudio.Utilities

Avalonia waveform display component for audio visualization.

WaveAvaloniaDisplay

Key Properties

Methods

public void SetAudioData(float[] audioData) public void LoadFromAudioFile(string filePath) public async Task LoadFromAudioFileAsync(string filePath)
XAML Usage
<audio:WaveAvaloniaDisplay x:Name="waveDisplay"
                          WaveformBrush="DodgerBlue"
                          PlaybackPositionBrush="Red"
                          VerticalScale="1.0"
                          DisplayStyle="MinMax"/>
C# Usage
// Load audio data
waveDisplay.SetAudioData(sourceManager[0].GetFloatAudioData(TimeSpan.Zero));

// Handle position changes
waveDisplay.PlaybackPositionChanged += (sender, position) =>
{
    sourceManager.Seek(TimeSpan.FromSeconds(position * sourceManager.Duration.TotalSeconds));
};
Complete Examples: For more detailed examples and use cases, check out the Examples section or the demo application.