This project has moved and is read-only. For the latest updates, please go here.

Audio Output

Driver Selection

NAudio supports a number of Audio Output Drivers:

1) WaveOut

2) DirectSound




Each of these Audio Output Drivers have different Pro’s and Con’s and the following discussion of each approach is designed to help you make your selection.

The common component for all of these audio driver outputs, is that NAudio does the wrapping of the low level DLL’s and COM objects for you so that you get a nice, clean, convenient .NET library that you can call and not have to worry about a bunch of PInvoke code.

1) WaveOut

WaveOut is one of the oldest and most basic Audio Output Drivers available. You will find support for it on every OS that NAudio will run on. WaveOut is reliable and if your undertaking a project which just requires simple functionality such as read-file-and-play-it-out (and you have a basic windows application) then this is a good choice for you.

The WaveOut driver requires a call back handle for the audio to continue to play. Effectively the audio playback is tied to the UI thread of your application, which is why, when your declaring an instance using the WaveOut driver you need to pass in a Window Handle. This has been simplified in the latter versions of NAudio so that the call back can be setup and done for you with very little code.

The following snippets show the different ways to setup the WaveOut Device using the different Windowing and call back options:

//WaveOut Setup - New Window
WaveCallbackInfo callbackInfo = WaveCallbackInfo.NewWindow();           
WaveOut outputDevice = new WaveOut(callbackInfo);
//WaveOut Setup - Function Call Back
WaveCallbackInfo callbackInfo = WaveCallbackInfo.FunctionCallback();
WaveOut outputDevice = new WaveOut(callbackInfo);
//WaveOut Setup – On a GUI Thread Only
WaveOut outputDevice = new WaveOut();

2) DirectSound

DirectSound is a latter Audio Output Driver than WaveOut but has still been around since the days of Windows NT. DirectSound is commonly associated with Games, as it is often referred to in conjunction with the rest of the DirectX library; which supports DirectX3D, Direct Input etc. This Driver was designed to be fast, with a low latency. How this implementation is actually achieved on the more recent Windows OS’s is outside the scope of this discussion but it’s worth noting the roots of the library.

Last edited Dec 23, 2010 at 1:20 AM by OpenSebJ, version 3


No comments yet.