BASS.NET API for the Un4seen BASS Audio LibraryBassWasapiHandler ClassBASS.NET API for the Un4seen BASS Audio Library
This class provides ready-made members for direct and more simple WASAPI usage together with BASS channels.
Inheritance Hierarchy

SystemObject
  Un4seen.BassWasapiBassWasapiHandler

Namespace: Un4seen.BassWasapi
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.12.0
Syntax

public class BassWasapiHandler

The BassWasapiHandler type exposes the following members.

Constructors

  NameDescription
Public methodBassWasapiHandler(Int32, Boolean, Int32, Int32, Single, Single)
Creates an instance of the WASAPI handler.
Public methodBassWasapiHandler(Int32, Boolean, Boolean, Int32, Int32, Single, Single)
Creates an instance of the WASAPI handler.
Top
Properties

  NameDescription
Public propertyBufferLength
Gets the actual buffer length (in seconds) being used with the Device.
Public propertyBypassFullDuplex
Gets or Sets the bypass flag for full-duplex WASAPI output processing (default is ).
Public propertyDevice
Returns the WASAPI device (endpoint) being used by the Wasapi handler.
Public propertyDeviceMute
Gets or Sets the mute status of the Device.
Public propertyDeviceVolume
Gets or Sets the linear volume of the Device between 0 (silent) and 1 (full).
Public propertyEventSystem
Returns , if the WASAPI event-driven system is used - else the standard push system is used.
Public propertyExclusive
Returns , if the WASAPI handler is used in exclusive mode - else shared mode is used.
Public propertyInputChannel
Returns an input channel which allows you to retrieve the recorded sample data and/or apply any DSP/FX on Wasapi input.
Public propertyInternalMixer
Gets the internal mixer being used with this WASAPI handler (when used with an output device).
Public propertyInternalWasapiProc
Gets the WASAPIPROC currently being used by the Wasapi handler.
Public propertyIsInput
Returns , if the WASAPI handler is used with a WASAPI input device (capture or loopback endpoint).
Public propertyIsInputFullDuplex
Returns , if the WASAPI handler is used with an WASAPI input device and the full-duplex option was set via SetFullDuplex(Int32, BASSFlag, Boolean).
Public propertyNumChans
Gets the actual number of channels being used with the Device.
Public propertyOutputChannel
Gets the BASS output channel handle which is used with this WASAPI input handler in case of full-duplex monitoring.
Public propertyPan
Gets or Sets the panning of the channels between -1 (left) to +1 (right), 0=centered.
Public propertySampleRate
Gets the actual sample rate in Hz which is being used.
Public propertySessionMute
Gets or Sets the mute status of the session.
Public propertySessionVolume
Gets or Sets the session volume between 0 (silent) and 1 (full).
Public propertyUpdatePeriod
Gets the actual update period (in seconds) being used with the Device.
Public propertyUseInput
Enables the use of the InputChannel channel with WASAPI input (which is the default for Wasapi input).
Public propertyVolume
Gets or Sets the volume of the channels between 0 (silent) and 1 (full).
Top
Methods

  NameDescription
Public methodAddOutputSource
Adds a new source to the WASAPI handler for output.
Public methodDispose
Disposes an instance of this class also stops and frees the used WASAPI device/driver (endpoint).
Protected methodFinalize
Finalization code.
(Overrides ObjectFinalize.)
Public methodInit
Public methodPause
Pauses or Unpauses the WASAPI Device being used.
Public methodRemoveFullDuplex
Removes the full-duplex option from WASAPI input.
Public methodSetFullDuplex
Sets the full-duplex option for WASAPI input using the given BASS output device.
Public methodStart
Starts the WASAPI Device.
Public methodStop
Stops the WASAPI Device.
Public methodWasapiInputCallback
Provides a ready made WASAPIPROC callback procedure which might be used for WASAPI input.
Public methodWasapiOutputCallback
Provides a ready made WASAPIPROC callback procedure which might be used for WASAPI output.
Top
Events

  NameDescription
Public eventNotification
Event handler used to notify that an Wasapi handler notification event (sync) has occurred.
Top
Remarks

You might use this class for almost all use cases in terms of Wasapi handling, e.g.:
Scenario:How-To:
Wasapi outputA Bass decoding channel feeding Wasapi output.

Simply create an instance of this class using an output device endpoint and then call the AddOutputSource(Int32, BASSFlag) method to add your decoding channel(s) to be used for output. Now you call the Init(Boolean) and Start methods to actually start the Wasapi output processing. You might also use the InternalMixer property (which returns the internally used Un4seen.Bass.AddOn.Mix mixer channel) to add or remove any decoding channel yourself.

Wasapi inputDirectly record from Wasapi input.

Simply create an instance of this class using an input device endpoint you want to record at (this automatically sets the UseInput property to ). To retrieve the input sample data use the InputChannel channel (e.g. setup an own DSP, use it with the WaveWriter or Encoder Framework).

Wasapi input, full-duplex to WasapiMonitor your Wasapi input on any Wasapi output.

Not supported directly by this class (but you can simply do this yourself, by initializing an output device with a WASAPIPROC and calling from within your input devices WASAPIPROC).

Wasapi input, full-duplex to BASSMonitor your Wasapi input on any BASS device.

To enable full-duplex just call the SetFullDuplex(Int32, BASSFlag, Boolean) method (when done call RemoveFullDuplex). Note: You might also specify the "no sound" BASS device (0) and use the BASS_STREAM_DECODE with the SetFullDuplex(Int32, BASSFlag, Boolean) call in order to retrieve a full-duplex decoding Bass stream, which you can now assign to an output instance of this class via AddOutputSource(Int32, BASSFlag) to preform a full-duplex Wasapi input to output monitoring.

DSP/FXYou can set any DSP/FX on either the input and/or the output (full-duplex).

See InputChannel and InternalMixer for more details.

You might use the Volume and Pan properties to easily control your Wasapi input/output settings.

Wasapi channels can be paused and resumed at any time by using the Pause(Boolean) method. To physically start the Wasapi device the Init(Boolean) followed by Start methods might be used. Stop will disable and stop the Wasapi device (if really needed).

Caution: Once you created an instance of this class and called the Init(Boolean) method, the respective WASAPI device is enabled and a session is created. The used WASAPI device will be disabled and freed automatically when an instance of this class is being disposed by the .Net Garbage Collector! Call the Dispose method manually to free the WASAPI device, including any full-duplex options.

Note: This class internally uses Un4seen.Bass as well as the Un4seen.Bass.AddOn.Mix add-on, so you need to provide the native bass.dll and the bassmix.dll as well when using this class.

Examples

Automatic use of the BassWasapiHandler (a Bass channel is feeding Wasapi output):
VB
Private _wasapi As BassWasapiHandler
...
' not playing anything via BASS, so don't need an update thread
Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0)
' setup BASS - "no sound" device
Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
...
Dim stream As Integer = Bass.BASS_StreamCreateFile(fileName, 0, 0, 
                             BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
If stream <> 0 Then
  ' assign WASAPI output in shared-mode
  _wasapi = new BassWasapiHandler(-1, false, 48000, 2, 0f, 0f)
  ' add the source channel
  _wasapi.AddOutputSource(stream, BASSFlag.BASS_DEFAULT)
  ' init and start WASAPI
  _wasapi.Init()
  _wasapi.Start()
End If
private BassWasapiHandler _wasapi;
...
// not playing anything via BASS, so don't need an update thread
Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
// setup BASS - "no sound" device
Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
...
int stream = Bass.BASS_StreamCreateFile(fileName, 0, 0, 
                  BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
if (stream != 0)
{
    // assign WASAPI output in shared-mode
    _wasapi = new BassWasapiHandler(-1, false, 48000, 2, 0f, 0f);
    // add the source channel
    _wasapi.AddOutputSource(stream, BASSFlag.BASS_DEFAULT)
    // init and start WASAPI
    _wasapi.Init();
    _wasapi.Start();
}
Automatic use of the BassWasapiHandler (Wasapi recording input):
VB
Private _wasapi As BassWasapiHandler
...
' not playing anything via BASS, so don't need an update thread
Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0)
' setup BASS - "no sound" device
Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
...
' assign WASAPI input in shared-mode
_wasapi = new BassWasapiHandler(-2, false, 48000, 2, 0f, 0f)
' init and start WASAPI
_wasapi.Init()
Dim recordStream As Integer = _wasapi.InputChannel
' double check, that the device is not muted externally
If _wasapi.DeviceMute Then
   _wasapi.DeviceMute = False
End If
_wasapi.Start()
End If
...
' now you can use recordStream to setup any DSP/FX etc.
private BassWasapiHandler _wasapi;
...
// not playing anything via BASS, so don't need an update thread
Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
// setup BASS - "no sound" device
Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
...
// assign WASAPI input in shared-mode
_wasapi = new BassWasapiHandler(-2, false, 48000, 2, 0f, 0f);
// init and start WASAPI
_wasapi.Init();
int recordStream = _wasapi.InputChannel;
// double check, that the device is not muted externally
if (_wasapi.DeviceMute)
    _wasapi.DeviceMute = false;
_wasapi.Start();
...
// now you can use recordStream to setup any DSP/FX etc.
Setup a full-duplex stream on Wasapi input and pass that to an Wasapi output instance:
VB
' setup a full-duplex stream
_wasapiInput.SetFullDuplex(0, BASSFlag.BASS_STREAM_DECODE, False, 2000)
Dim fullDuplexStream As Integer = _wasapiInput.OutputChannel
' and assign it to an output
_wasapiOutput.AddOutputSource(fullDuplexStream, BASSFlag.BASS_DEFAULT)
// setup a full-duplex stream
_wasapiInput.SetFullDuplex(0, BASSFlag.BASS_STREAM_DECODE, false, 2000);
int fullDuplexStream = _wasapiInput.OutputChannel;
// and assign it to an output
_wasapiOutput.AddOutputSource(fullDuplexStream, BASSFlag.BASS_DEFAULT);
See Also

Reference