API Reference
Complete reference documentation for the OwnAudioSharp library. This guide covers all public classes, methods, and properties.
OwnAudio.Initialize()
and properly disposed with OwnAudio.Free()
.
OwnAudio Class
The main entry point for the OwnAudio library. Handles initialization and cleanup of the audio system.
Static Methods
Initialize()
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. |
try
{
OwnAudio.Initialize();
// Your audio code here
}
finally
{
OwnAudio.Free(); // Always cleanup
}
SourceManager Class
Manages multiple audio sources and provides playback control. Uses singleton pattern for global access.
Properties
Instance
Gets the singleton instance of SourceManager.
IsPlaying
Gets whether any audio source is currently playing.
Duration
Gets the total duration of the longest audio source.
Position
Gets the current playback position.
Sources
Gets a read-only list of all audio sources.
Methods
AddOutputSource()
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. |
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
Adds an input source for audio recording from the default microphone.
AddRealTimeSource()
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()
Starts playback of all audio sources, or starts recording to a file.
Pause()
Pauses playback of all audio sources.
Stop()
Stops playback and resets position to the beginning.
Seek()
Seeks to a specific position in the audio.
Indexer Access
Accesses sources by name or index.
// Access by name
sourceManager["BackgroundMusic"].Volume = 0.5f;
// Access by index
sourceManager[0].Volume = 0.8f;
Source Class
Represents an individual audio source with playback controls and effects.
Properties
Volume
Gets or sets the volume level (0.0 to 1.0).
Tempo
Gets or sets the tempo change in percentage (-20 to +20). Affects speed without changing pitch.
Pitch
Gets or sets the pitch change in semitones (-6 to +6). Affects pitch without changing tempo.
Duration
Gets the total duration of the audio source.
State
Gets the current state (Idle, Playing, Paused, Stopped).
Methods
GetFloatAudioData()
Extracts audio data as float array starting from specified time.
GetByteAudioData()
Extracts audio data as byte array starting from specified time.
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
Real-time audio source for live audio generation and streaming.
Methods
SubmitSamples()
Submits audio samples for real-time playback.
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: 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
Professional quality reverb effect based on the Freeverb algorithm.
Constructor
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) |
// 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
Echo effect with configurable delay time and feedback.
Constructor
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
Dynamic range compressor for controlling audio dynamics.
Constructor
Equalizer Effect
30-band parametric equalizer with dynamic Q-factor optimization.
Constructor
Methods
SetBandGain()
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
Configure audio engine parameters for optimal performance.
Engine Options
// 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
Advanced chord detection and musical analysis capabilities.
DetectChords() Extension Method
// 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
Intelligent audio matchering with 30-band EQ and psychoacoustic analysis.
AudioAnalyzer Class
ProcessEQMatching()
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
Avalonia waveform display component for audio visualization.
WaveAvaloniaDisplay
Key Properties
WaveformBrush
- Color of the waveformPlaybackPositionBrush
- Color of playback position indicatorVerticalScale
- Vertical scaling factorDisplayStyle
- Waveform display style (MinMax, Positive, RMS)ZoomFactor
- Zoom level for detailed view
Methods
<audio:WaveAvaloniaDisplay x:Name="waveDisplay"
WaveformBrush="DodgerBlue"
PlaybackPositionBrush="Red"
VerticalScale="1.0"
DisplayStyle="MinMax"/>
// 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));
};