BASS.NET API for the Un4seen BASS Audio LibraryBassAsioHandlerAssignOutputChannel Method BASS.NET API for the Un4seen BASS Audio Library
Assigns a (new) BASS channel handle for ASIO output.

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

public bool AssignOutputChannel(
	int outputChannel
)

Parameters

outputChannel
Type: SystemInt32
The BASS channel handle which should be used with ASIO output (should be a decoding or recording channel and must be either 16-bit or 32-bit) - or 0 (zero) to remove an existing OutputChannel.

Return Value

Type: Boolean
On success is returned, else will be returned (use BASS_ASIO_ErrorGetCode to retrieve the error code).
Exceptions

ExceptionCondition
ArgumentExceptionInvalid channel: must be a valid BASS channel (either decoding or recording).
Remarks

The following will be done internally:

1. The current ASIO channel will be paused (if already enabled).

2. The samplerate, format and number of channels will be determined from the given outputChannel.

3. The ASIO device will be set to the determined samplerate. If this fails, the current ASIO samplerate will not be changed. In this case it might happen (if ASIO device samplerate and stream samplerate are different) that the ASIO output needs to be resampled.

4a. ASIO Channel enabled: use the AsioOutputCallback(Boolean, Int32, IntPtr, Int32, IntPtr) as the internal ASIOPROC, if the ASIO Channel was already enabled and joined, it will not be changed.

4b. ASIO Channel disabled: Enable and join the given Asio Channel with the following channels according to the total number of chans of the outputChannel.

5. Set the ASIO Channel format and samplerate according to the given samplerate and format of the outputChannel.

6. The current ASIO channel will be unpaused (if it was paused before).

This method can not be used with ASIO input (see IsInput). It will immediately return with no effect.

Tyically a decoding channel must be used, but a recording channel will also work, since the internal ASIO procedure being used simply calls BASS_ChannelGetData(Int32, IntPtr, Int32) to pull the sample data from the OutputChannel as needed and requested by ASIO.

Examples

Automatic use of the BassAsioHandler (output):
VB
Private _asio As BassAsioHandler
...
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
  BassAsio.BASS_ASIO_Start(0)
End If
...
' assign a new channel to ASIO output
Bass.BASS_StreamFree(stream)
Dim newStream As Integer = Bass.BASS_StreamCreateFile(newFileName, 0, 0, 
                                BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
_asio.AssignOutputChannel(newStream)
private BassAsioHandler _asio;
...
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
  BassAsio.BASS_ASIO_Start(0);
}
...
// assign a new channel to ASIO output
Bass.BASS_StreamFree(stream);
int newStream = Bass.BASS_StreamCreateFile(newFileName, 0, 0, 
                     BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT );
_asio.AssignOutputChannel(newStream);
See Also

Reference