Xylocopadream.Audio.Wasapi 0.1.0

Prefix Reserved
dotnet add package Xylocopadream.Audio.Wasapi --version 0.1.0
                    
NuGet\Install-Package Xylocopadream.Audio.Wasapi -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xylocopadream.Audio.Wasapi" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Xylocopadream.Audio.Wasapi" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Xylocopadream.Audio.Wasapi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Xylocopadream.Audio.Wasapi --version 0.1.0
                    
#r "nuget: Xylocopadream.Audio.Wasapi, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Xylocopadream.Audio.Wasapi@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Xylocopadream.Audio.Wasapi&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Xylocopadream.Audio.Wasapi&version=0.1.0
                    
Install as a Cake Tool

Xylocopadream.Audio

Short sounds played at once and overlapping: key clicks, notes, game effects, notifications.

One output that never stops (silence when nothing plays) keeps the device awake: a sound starts at the next period, never clipped at its start. The sounds are decoded once (WAV), resampled to the rate of the mix and kept in mono 16 bits.

Package Output Platforms
Xylocopadream.Audio the player, the mixer, WAV decoding, resampling all (no dependency but logging abstractions)
Xylocopadream.Audio.MiniAudio MiniAudioOutput: miniaudio through SoundFlow, 10 ms periods Windows, Linux, macOS
Xylocopadream.Audio.Wasapi WasapiAudioOutput: WASAPI shared mode, event driven, 40 ms, through NAudio Windows (WPF, WinUI, MAUI, Avalonia)

Use

dotnet add package Xylocopadream.Audio.MiniAudio     # or Xylocopadream.Audio.Wasapi
// one for the app (a singleton): disposing it closes the device
var player = new SamplePlayer(new MiniAudioOutput(), name => Task.FromResult<Stream>(File.OpenRead(name)), logger);

// at startup, off the UI thread: opens the device (about half a second) and decodes the sounds
await player.PreloadAsync("sounds/ok.wav", "sounds/error.wav");

// at once, from any thread; sounds overlap
player.Play("sounds/ok.wav", volume: 0.8);

With dependency injection:

services.AddSingleton<IAudioOutput, MiniAudioOutput>();
services.AddSingleton(provider => new SamplePlayer(
    provider.GetRequiredService<IAudioOutput>(), OpenSound, provider.GetService<ILogger<SamplePlayer>>()));
  • Play on a sound not loaded yet starts loading it and skips it this time (a late sound is worse than none).
  • Without a device (none plugged, none allowed), IsAvailable is false and Play does nothing; the error is logged.
  • A sound that cannot be loaded is logged, left out, and loaded again when asked again.

Formats

WAV: PCM 8, 16, 24 or 32 bits, or 32-bit float, also in the extensible format; any number of channels (averaged to mono), any rate (resampled with a windowed sinc to SamplePlayer.DefaultSampleRate, 44100 Hz, unless another rate is given).

Your own output

Implement IAudioOutput: Start(IAudioSource) opens the device and reads the source (32-bit float, interleaved stereo) on the audio thread until disposed.

Publish a new version

.\publish.ps1 -Bump                                           # local feed (%UserProfile%\nuget_local)
$env:NUGET_API_KEY = '...'; .\publish.ps1 -Bump -NuGetOrg    # tests, then nuget.org

License

MIT. Uses SoundFlow (MIT, miniaudio) and NAudio (MIT).

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 105 10/13/2026