Skip to main content

NAudio (.NET)

Runtime scope

The in-browser demo below uses Web Audio because these docs live in a browser. The code snippet on this page applies on the .NET runtime.

Understanding which backend runs where matters when you cross-compile a shared alphaTab integration to another runtime. On .NET, alphaTab's synth pipeline ends at NAudioSynthOutput โ€” a WaveProvider32 implementation that hands 44.1 kHz stereo float samples to a DirectSoundOut device from NAudio.

00:00 / 00:00

What runs on the audio threadโ€‹

NAudioSynthOutput extends NAudio.Wave.WaveProvider32. Under the hood:

  • Samples are buffered through a CircularSampleBuffer sized from the player.bufferTimeInMilliseconds setting, then multiplied by four to absorb NAudio's own internal buffering.
  • DirectSoundOut is initialized with a 40 ms latency target and pulls float samples on demand via Read.
  • Every read triggers samplesPlayed, which drives the alphaTab position cursor and the midiEventsPlayed event.

You do not construct NAudioSynthOutput yourself โ€” the WPF and WinForms controls wire it up when the player is enabled. What you can configure is which DirectSound device receives the audio.

Selecting an output deviceโ€‹

AlphaTabApi.EnumerateOutputDevices returns every DirectSound sink except the null GUID. SetOutputDevice tears down the current DirectSoundOut and rebuilds it against the chosen device, so live switching is supported.

Show it in codeโ€‹

using AlphaTab;
using AlphaTab.Synth;

var api = GetAlphaTabApi(); // your WPF or WinForms AlphaTabApi instance

api.PlayerReady.On(async () =>
{
var devices = await api.EnumerateOutputDevices();
foreach (var device in devices)
{
Console.WriteLine($"{device.Label} (default: {device.IsDefault})");
}

// Route to a specific device; pass null to fall back to the system default.
var preferred = devices.FirstOrDefault(d => d.Label.Contains("Headphones"));
await api.SetOutputDevice(preferred);
});

GetAlphaTabApi() is a placeholder for the platform-specific step of obtaining the API instance โ€” on .NET you get one from the AlphaTab WPF control or the WinForms host you embedded.

Where to look nextโ€‹