BASS.NET API for the Un4seen BASS Audio LibraryBassAsioHandler Constructor BASS.NET API for the Un4seen BASS Audio Library
Default constructor - leaving all defaults and not assigning any ASIO channel.

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

public BassAsioHandler()
Remarks

Use this constructor, if you for example want to leverage the AsioToBassFullDuplexCallback(Boolean, Int32, IntPtr, Int32, IntPtr), AsioInputCallback(Boolean, Int32, IntPtr, Int32, IntPtr) or AsioToAsioFullDuplexCallback(Boolean, Int32, IntPtr, Int32, IntPtr) callback methods. In this case make sure to also set the OutputChannel property, since this member will be used in the mentioned default callback procedures. Also make sure, that the ASIO channel use will use matches the samplerate and the format of the OutputChannel!
Examples

Manual use of the BassAsioHandler:
VB
Private _myAsioProc As ASIOPROC
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
  _asio = New BassAsioHandler()
  _asio.OutputChannel = stream

  ' now setup ASIO manually
  _myAsioProc = New ASIOPROC(AddressOf _asio.BassToAsioOutputCallback)
  ' get the stream channel info
  Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
  ' enable 1st output channel...(0=first)
  BassAsio.BASS_ASIO_ChannelEnable(False, 0, _myAsioProc, stream)
  ' and join the next channels to it
  Dim a As Integer
  For a = 1 To info.chans - 1
    BassAsio.BASS_ASIO_ChannelJoin(False, a, 0)
  Next a
  ' since we joined the channels, the next commands will apply to all channles joined
  ' so setting the values to the first channels changes them all automatically
  ' set the source format (float, as the decoding channel is)
  BassAsio.BASS_ASIO_ChannelSetFormat(False, 0, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT)
  ' set the source rate
  BassAsio.BASS_ASIO_ChannelSetRate(False, 0, CDbl(info.freq))
  ' try to set the device rate too (saves resampling)
  BassAsio.BASS_ASIO_SetRate(CDbl(info.freq))
  ' and start playing it...start output using default buffer/latency
  _asio.Start(0)
End If
private ASIOPROC _myAsioProc;
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)
{
  _asio = new BassAsioHandler();
  _asio.OutputChannel = stream;

  // now setup ASIO manually
  _myAsioProc = new ASIOPROC(_asio.BassToAsioOutputCallback);
  // get the stream channel info
  BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
  // enable 1st output channel...(0=first)
  BassAsio.BASS_ASIO_ChannelEnable(false, 0, _myAsioProc, stream);
  // and join the next channels to it
  for (int a=1; a<info.chans; a++)
    BassAsio.BASS_ASIO_ChannelJoin(false, a, 0);
  // since we joined the channels, the next commands will apply to all channles joined
  // so setting the values to the first channels changes them all automatically
  // set the source format (float, as the decoding channel is)
  BassAsio.BASS_ASIO_ChannelSetFormat(false, 0, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT);
  // set the source rate
  BassAsio.BASS_ASIO_ChannelSetRate(false, 0, (double)info.freq);
  // try to set the device rate too (saves resampling)
  BassAsio.BASS_ASIO_SetRate( (double)info.freq );
  // and start playing it...start output using default buffer/latency
  _asio.Start(0);
}
See Also

Reference