ASIOPROC callback

User defined ASIO channel callback function.

DWORD CALLBACK AsioProc(
    BOOL input,
    DWORD channel,
    void *buffer,
    DWORD length,
    void *user
);

Parameters

inputDealing with an input channel? FALSE = an output channel.
channelThe input/output channel number... 0 = first.
bufferThe buffer containing the recorded data (input channel), or in which to put the data to output (output channel).
lengthThe number of BYTES to process.
userThe user instance data given when BASS_ASIO_ChannelEnable was called.

Return value

In the case of an output channel, the number of bytes written to the buffer (a negative number will be treated as 0). The return value is ignored with input channels.

Remarks

When multiple channels are joined together, the sample data of the channels is interleaved; the channel that was enabled via BASS_ASIO_ChannelEnable comes first, followed by the channels that have been joined to it. The order of the joined channels defaults to numerically ascending order unless the BASS_ASIO_JOINORDER flag was used in the BASS_ASIO_Init call, in which case they will be in the order in which BASS_ASIO_ChannelJoin was called to join then.

When an output channel's function returns less data than requested, the remainder of the buffer is filled with silence, and some processing is saved by that. When 0 is returned, the level of processing is the same as if the channel had been paused with BASS_ASIO_ChannelPause, ie. the ASIO buffer is simply filled with silence and all additional processing (resampling/etc) is bypassed.

ASIO is a low latency system, so a channel callback function should obviously be as quick as possible. BASS_ASIO_GetCPU can be used to monitor that. Do not call the BASS_ASIO_Stop or BASS_ASIO_Free functions from within an ASIO callback. Also, if it is an output channel, BASS_ASIO_ChannelSetFormat and BASS_ASIO_ChannelSetRate should not be used on the channel being processed by the callback.

Prior to calling this function, BASSASIO will set the thread's device context to the device that the channel belongs to. So when using multiple devices, BASS_ASIO_GetDevice can be used to determine which device the channel is on.

Example

Feed a BASS decoding channel into an ASIO channel.
DWORD CALLBACK MyAsioProc(BOOL input, DWORD channel, void *buffer, DWORD length, void *user)
{
    DWORD c = BASS_ChannelGetData(decoder, buffer, length); // decode some data
    if (c == -1) c = 0; // an error, no data (could pause the channel at this point)
    return c;
}

See also

BASS_ASIO_ChannelEnable, BASS_ASIO_ChannelGetFormat