BASS.NET API for the Un4seen BASS Audio LibraryWASAPIPROC DelegateBASS.NET API for the Un4seen BASS Audio Library
User defined WASAPI output/input processing callback function (to be used with BASS_WASAPI_Init(Int32, Int32, Int32, BASSWASAPIInit, Single, Single, WASAPIPROC, IntPtr)).

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

public delegate int WASAPIPROC(
	IntPtr buffer,
	int length,
	IntPtr user


Type: SystemIntPtr
Pointer to the buffer to put the sample data for an output device, or to get the data from an input device. The sample data is always 32-bit floating-point.
Type: SystemInt32
The number of bytes to process.
Type: SystemIntPtr
The user instance data given when BASS_WASAPI_Init(Int32, Int32, Int32, BASSWASAPIInit, Single, Single, WASAPIPROC, IntPtr) was called.

Return Value

Type: Int32
In the case of an output device, the number of bytes written to the buffer. If the value is negative (high bit set), it will be treated as 0. In the case of an input device, 0 = stop the device, else continue.

An output/input processing function should obviously be as quick as possible, to avoid buffer underruns (output) or overruns (input). Using a larger buffer makes that less crucial. BASS_WASAPI_GetData(IntPtr, Int32) (BASS_DATA_AVAILABLE) can be used to check how much data is buffered.

An output device's WASAPIPROC may return less data than requested, but be careful not to do so by too much, too often. If the buffer gets exhausted, output will stall until more data is provided. If you do return less than the requested amount of data, the number of bytes should still equate to a whole number of samples.

When multiple channels are used, the sample data of the channels is interleaved. For example, with 2 channels (ie. stereo), the sample data would be arranged as channel 1, channel 2, channel 1, channel 2, channel 1, etc.

When an output channel needs to be empty/silent but still enabled, the channel's function could fill the buffer with 0s to achieve that.

Do not call BASS_WASAPI_Free from within a callback function.

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

NOTE: When you pass an instance of a callback delegate to one of the BASS functions, this delegate object will not be reference counted. This means .NET would not know, that it might still being used by BASS. The Garbage Collector might (re)move the delegate instance, if the variable holding the delegate is not declared as global. So make sure to always keep your delegate instance in a variable which lives as long as BASS needs it, e.g. use a global variable or member.

It is not supported to change the WASAPIPROC once a device was initialized via BASS_WASAPI_Init(Int32, Int32, Int32, BASSWASAPIInit, Single, Single, WASAPIPROC, IntPtr). If you need to change some internal processing logic during processing, you might use some kind of "if" statements within this callback procedure.

See Also