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

SystemObject
  Un4seen.BassAsioBassAsioHandler

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

public class BassAsioHandler

The BassAsioHandler type exposes the following members.

Constructors

  NameDescription
Public methodCode exampleBassAsioHandler
Default constructor - leaving all defaults and not assigning any ASIO channel.
Public methodCode exampleBassAsioHandler(Int32, Int32, Int32)
Creates an instance of the ASIO handler for output - initializing and enabling the given ASIO device and channel according to the Bass stream.
Public methodCode exampleBassAsioHandler(Boolean, Int32, Int32, Int32, BASSASIOFormat, Double)
Creates an instance of the ASIO handler - initializing and enabling the given ASIO device and channel.
Top
Properties

  NameDescription
Public propertyBypassFullDuplex
Gets or Sets the bypass flag for full-duplex ASIO output processing (default is ).
Public propertyChannel
Returns the first ASIO channel being used.
Public propertyChannelNumChans
Gets the total number of ASIO channel which are joined together, starting with Channel.
Public propertyDevice
Returns the ASIO device being used by the Asio handler.
Public propertyDeviceVolume
Gets or Sets the master volume of the Device between 0 (silent) and 1 (full).
Public propertyFormat
Gets or Sets the actual ASIO channel format (default is BASS_ASIO_FORMAT_FLOAT).
Public propertyFullDuplexChannel
Returns the first full-duplex ASIO output channel being used (or -1, if not used).
Public propertyFullDuplexDevice
Returns the full-duplex ASIO output device being used (or -1, if not used).
Public propertyInputChannel
Returns an input channel which allows you to retrieve the recorded sample data and/or apply any DSP/FX on Asio input.
Public propertyInternalAsioProc
Gets the ASIOPROC currently being used by the Asio handler.
Public propertyIsInput
Returns , if the ASIO handler is used with an ASIO input device.
Public propertyIsInputFullDuplex
Returns , if the ASIO handler is used with an ASIO input device and the full-duplex option was set via SetFullDuplex(Int32, Int32).
Public propertyIsMirrored
Returns if the ASIO Channel is being mirrored to another output channel.
Public propertyIsResampling
Returns , if resampling takes place on the used Channel and Device.
Public propertyMirrorChannel
Gets the first ASIO mirror channel (or -1 if not mirrored).
Public propertyOutputChannel
Gets or Sets the BASS output channel handle which is used with this ASIO handler.
Public propertyPan
Gets or Sets the panning of the Channel (and all joined ChannelNumChans) between -1 (left) to +1 (right), 0=centered.
Public propertyPanMirror
Gets or Sets the panning of the MirrorChannel (and all attached ChannelNumChans) between -1 (left) to +1 (right), 0=centered.
Public propertySampleRate
Gets or Sets the actual ASIO channel sample rate in Hz (default is 48000).
Public propertyUseInput
Enables the use of the InputChannel channel with ASIO input (which is the default for Asio input).
Public propertyVolume
Gets or Sets the volume of the Channel (and all joined ChannelNumChans) between 0 (silent) and 1 (full).
Public propertyVolumeMirror
Gets or Sets the volume of the MirrorChannel (and all attached ChannelNumChans) between 0 (silent) and 1 (full).
Top
Methods

  NameDescription
Public methodCode exampleAsioInputCallback
Provides a ready made ASIOPROC callback procedure which might be used for ASIO input.
Public methodCode exampleAsioOutputCallback
Provides a ready made ASIOPROC callback procedure which might be used for ASIO output.
Public methodCode exampleAsioToAsioFullDuplexCallback
Provides a ready made ASIOPROC callback procedure which might be used for full-duplex ASIO input to Asio output.
Public methodCode exampleAsioToBassFullDuplexCallback
Provides a ready made ASIOPROC callback procedure which might be used for full-duplex ASIO input to Bass output.
Public methodCode exampleAssignOutputChannel
Assigns a (new) BASS channel handle for ASIO output.
Public methodDispose
Disposes an instance of this class also unjoining and disabling all used ASIO channels.
Protected methodFinalize
Finalization code.
(Overrides ObjectFinalize.)
Public methodPause
Pauses or Unpauses the ASIO Channel(s) being used.
Public methodPauseMirror
Pauses or Unpauses the MirrorChannel(s) being used.
Public methodCode exampleRemoveFullDuplex
Removes the full-duplex option from ASIO input.
Public methodRemoveMirror
Removes a mirror set on the current ASIO Channel.
Public methodCode exampleSetFullDuplex(Int32, Int32)
Sets the full-duplex option for ASIO input using the given ASIO output device and channel.
Public methodCode exampleSetFullDuplex(Int32, BASSFlag, Boolean)
Sets the full-duplex option for ASIO input using the given BASS output device.
Public methodCode exampleSetMirror
Mirrors the current ASIO Channel to the given output channel.
Public methodStart
Starts the Asio Device.
Public methodStartFullDuplex
Starts the Asio FullDuplexDevice.
Public methodStop
Stops the Asio Device.
Public methodStopFullDuplex
Stops the Asio FullDuplexDevice.
Top
Events

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

  NameDescription
Public fieldStatic memberUseDedicatedThreads
Gets or Sets, if the driver should be hosted in a dedicated thread.
Top
Remarks

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

Simply use the corresponding output constructor to specify the Asio Device and Channel as well the OutputChannel to use and you are done. The SampleRate, ChannelNumChans and Format will automatically be aligned. Use the AssignOutputChannel(Int32) method to change the underlying bass channel on the fly.

Asio inputDirectly record from Asio input.

Simply use the corresponding input constructor to specify the Asio Device, Channel, SampleRate, ChannelNumChans and Format you want to record at. To retrieve the input sample data use the InputChannel channel (e.g. setup an own DSP, use it with the WaveWriter or Encoder Framework).

Asio input, full-duplex to AsioMonitor your Asio input on any Asio output.

To enable full-duplex just call the Asio overload of the SetFullDuplex(Int32, Int32) method (when done call RemoveFullDuplex(Boolean)).

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

To enable full-duplex just call the bass overload of the SetFullDuplex(Int32, Int32) method (when done call RemoveFullDuplex(Boolean)).

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

See InputChannel and OutputChannel for more details.

You might use the Volume and Pan properties to easily control your Asio input/output settings. Asio mirrors are also supported via the SetMirror(Int32) and RemoveMirror methods. Mirrors have independent VolumeMirror and PanMirror settings.

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

Caution: Once you created an instance of this class, the respective ASIO channels are joined and enabled. The used ASIO channels will NOT be unjoined or disabled automatically when an instance of this class is being disposed by the .Net Garbage Collector! Call the Dispose method manually to completely free all assigned ASIO channels, including any full-duplex and the mirror options. However, calling Dispose will not stop the Asio device - this has to be done manually in any case (e.g. by calling Stop)!

Note: This class internally uses Un4seen.Bass, so you need to provide the native BASS.dll as well when using this class.

The AsioOutputCallback(Boolean, Int32, IntPtr, Int32, IntPtr), AsioInputCallback(Boolean, Int32, IntPtr, Int32, IntPtr), AsioToAsioFullDuplexCallback(Boolean, Int32, IntPtr, Int32, IntPtr) and AsioToBassFullDuplexCallback(Boolean, Int32, IntPtr, Int32, IntPtr) callbacks are virtual methods which might be overloaded if you want to derive your own ASIO handler with any special callback handling.

Examples

Automatic use of the BassAsioHandler (a Bass channel is feeding Asio output):
VB
Private _asio As BassAsioHandler
...
' 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 but 48000 (default for ASIO)
Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
...
Dim stream As Integer = Bass.BASS_StreamCreateFile(fileName, 0, 0, 
                             BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
If stream <> 0 Then
  ' assign ASIO output to the first device and channel
  ' and assume the ASIO format, samplerate and number of channels from the BASS stream
  _asio = New BassAsioHandler(0, 0, stream)
  ' start ASIO
  _asio.Start(0)
End If
private BassAsioHandler _asio;
...
// 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 but 48000 (default for ASIO)
Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
...
int stream = Bass.BASS_StreamCreateFile(fileName, 0, 0, 
                  BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
if (stream != 0)
{
    // assign ASIO output to the first device and channel
    // and assume the ASIO format, samplerate and number of channels from the BASS stream
    _asio = new BassAsioHandler(0, 0, stream);
    // start ASIO
    _asio.Start(0);
}
Automatic use of the BassAsioHandler (Asio recording input, Asio full-duplex output):
VB
Private _asio As BassAsioHandler
...
' 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 but 48000 (default for ASIO)
Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
...
' assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
_asio = New BassAsioHandler(True, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000)
' set the full-duplex option to the first ASIO output device and channel
' the ASIO output format will aways be the same as the input for full-duplex
_asio.SetFullDuplex(0, 0)
' start ASIO
_asio.Start(0)
...
' when you want to disbale all associated channels, call:
_asio.Dispose()
private BassAsioHandler _asio;
...
// 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 but 48000 (default for ASIO)
Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
...
// assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
_asio = new BassAsioHandler(true, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000);
// set the full-duplex option to the first ASIO output device and channel
// the ASIO output format will aways be the same as the input for full-duplex
_asio.SetFullDuplex(0, 0);
// start ASIO
_asio.Start(0);
...
// when you want to disbale all associated channels, call:
_asio.Dispose();
See Also

Reference