Quick Start Guide

Get up and running with OwnAudioSharp in minutes. This guide will help you install the library and create your first audio application.

Zero Dependencies: OwnAudioSharp includes MiniAudio by default, so you can start immediately without installing any external libraries.

Installation

NuGet Package Manager

Package Manager Console
Install-Package OwnAudioSharp

.NET CLI

Command Line
dotnet add package OwnAudioSharp

PackageReference

Project File (.csproj)
<PackageReference Include="OwnAudioSharp" Version="1.0.0" />

Dependencies

Ready to Go: MiniAudio is included and works out of the box on all platforms without any setup.

For enhanced functionality, you can optionally install:

Windows Setup

  1. Download FFmpeg 6 binaries and PortAudio DLL
  2. Extract to a folder (e.g., C:\AudioLibs\)
  3. Point to the folder when initializing OwnAudio
C# Initialization
OwnAudio.Initialize(@"C:\AudioLibs\");

macOS Setup

Use Homebrew for easy installation:

Terminal
brew install portaudio
brew install ffmpeg@6

Libraries are automatically detected after installation.

Linux Setup

Install using your distribution's package manager:

Ubuntu/Debian
sudo apt update
sudo apt install portaudio19-dev ffmpeg
CentOS/RHEL
sudo yum install portaudio-devel ffmpeg

Android & iOS

Mobile platforms use MiniAudio exclusively - no additional setup required!

MiniAudio provides excellent performance on mobile devices with built-in format support for MP3, WAV, and FLAC.

Basic Usage

Simple Audio Playback

Program.cs
using Ownaudio;
using Ownaudio.Sources;
using System;
using System.Threading.Tasks;

try 
{
    // Initialize OwnAudio (uses MiniAudio by default)
    OwnAudio.Initialize();

    // Create a source manager
    var sourceManager = SourceManager.Instance;

    // Add an audio file
    await sourceManager.AddOutputSource("path/to/audio.mp3");

    // Play the audio
    sourceManager.Play();

    // Wait for user input
    Console.WriteLine("Press any key to stop playback...");
    Console.ReadKey();

    // Stop playback and clean up
    sourceManager.Stop();
}
catch (Exception ex)
{
    Console.WriteLine($"Audio error: {ex.Message}");
}
finally
{
    OwnAudio.Free();
}

Adding Multiple Audio Sources

Multiple Sources Example
// Add multiple audio files with names
await sourceManager.AddOutputSource("background.mp3", "BackgroundMusic");
await sourceManager.AddOutputSource("sfx.wav", "SoundEffect");

// Control individual volumes
sourceManager["BackgroundMusic"].Volume = 0.6f;  // 60% volume
sourceManager["SoundEffect"].Volume = 0.8f;      // 80% volume

// Play all sources simultaneously
sourceManager.Play();

Platform-Specific Setup

Cross-Platform Initialization

Smart Initialization
using System.Runtime.InteropServices;

// Platform-specific library paths
string libraryPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) 
    ? @"C:\AudioLibs\" 
    : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) 
        ? "/usr/local/lib/" 
        : "/usr/lib/";

// Initialize with automatic fallback to MiniAudio
OwnAudio.Initialize(libraryPath);

Engine Configuration

Audio Engine Options
using Ownaudio.Engines;

// Initialize first
OwnAudio.Initialize();

// Configure output for low-latency applications
SourceManager.OutputEngineOptions = new AudioEngineOutputOptions(
    OwnAudioEngine.EngineChannels.Stereo, 
    44100,    // Sample rate
    0.02      // Low latency (20ms)
);

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

// Set buffer size for optimal performance
SourceManager.EngineFramesPerBuffer = 512;

Your First Audio Project

Let's create a simple console application that demonstrates key features:

Complete Example - AudioPlayer.cs
using Ownaudio;
using Ownaudio.Sources;
using Ownaudio.Processors;
using System;
using System.Threading.Tasks;

class AudioPlayer
{
    private static SourceManager sourceManager;

    static async Task Main(string[] args)
    {
        try
        {
            // Initialize the audio system
            Console.WriteLine("Initializing OwnAudio...");
            OwnAudio.Initialize();
            
            sourceManager = SourceManager.Instance;

            // Load an audio file
            Console.WriteLine("Loading audio file...");
            await sourceManager.AddOutputSource("demo.mp3", "DemoTrack");

            // Start playback
            Console.WriteLine("Starting playback...");
            sourceManager.Play();

            // Interactive menu
            await RunInteractiveMenu();
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
        }
        finally
        {
            OwnAudio.Free();
        }
    }

    static async Task RunInteractiveMenu()
    {
        while (true)
        {
            Console.WriteLine("\n=== Audio Player ===");
            Console.WriteLine("1. Play/Pause");
            Console.WriteLine("2. Adjust Volume");
            Console.WriteLine("3. Apply Reverb");
            Console.WriteLine("4. Seek Position");
            Console.WriteLine("5. Exit");
            Console.Write("Choose option: ");

            var key = Console.ReadKey().KeyChar;
            Console.WriteLine();

            switch (key)
            {
                case '1':
                    TogglePlayback();
                    break;
                case '2':
                    AdjustVolume();
                    break;
                case '3':
                    ApplyReverb();
                    break;
                case '4':
                    SeekPosition();
                    break;
                case '5':
                    return;
            }
        }
    }

    static void TogglePlayback()
    {
        if (sourceManager.IsPlaying)
        {
            sourceManager.Pause();
            Console.WriteLine("Paused");
        }
        else
        {
            sourceManager.Play();
            Console.WriteLine("Playing");
        }
    }

    static void AdjustVolume()
    {
        Console.Write("Enter volume (0.0 - 1.0): ");
        if (float.TryParse(Console.ReadLine(), out float volume))
        {
            sourceManager["DemoTrack"].Volume = Math.Clamp(volume, 0f, 1f);
            Console.WriteLine($"Volume set to {volume:F2}");
        }
    }

    static void ApplyReverb()
    {
        var reverb = new Reverb(0.7f, 0.5f, 0.3f, 0.8f);
        sourceManager.CustomSampleProcessor = reverb;
        Console.WriteLine("Reverb effect applied");
    }

    static void SeekPosition()
    {
        Console.Write("Enter position in seconds: ");
        if (double.TryParse(Console.ReadLine(), out double seconds))
        {
            sourceManager.Seek(TimeSpan.FromSeconds(seconds));
            Console.WriteLine($"Seeked to {seconds:F1} seconds");
        }
    }
}

Next Steps

Explore More: Now that you have the basics working, dive deeper into OwnAudioSharp's advanced features.

Continue your journey with these resources:

📚 API Reference 💡 Code Examples 🎛️ Audio Effects 🎚️ Professional Mastering

Key Concepts to Learn Next

Need Help? Check out the demo application for a complete Avalonia MVVM example, or visit the GitHub repository for documentation and community support.