Delegate WasapiProcedure
User defined WASAPI output/input processing callback function (to be used with Init(Int32, Int32, Int32, WasapiInitFlags, Single, Single, WasapiProcedure, IntPtr)).
Namespace: System.Dynamic.ExpandoObject
Assembly: ManagedBass.Wasapi.dll
Syntax
public delegate int WasapiProcedure(IntPtr Buffer, int Length, IntPtr User);
Parameters
IntPtr
Buffer
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. |
Int32
Length
The number of bytes to process. |
IntPtr
User
The user instance data given when Init(Int32, Int32, Int32, WasapiInitFlags, Single, Single, WasapiProcedure, IntPtr) was called. |
Returns
Int32
In the case of an output device, the number of bytes written to the buffer. In the case of an input device, 0 = stop the device, else continue. |
Remarks
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. GetData(IntPtr, Int32) (Available) can be used to check how much data is buffered.
An output device's WasapiProcedure 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 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, CurrentDevice can be used to determine which device the channel is on.
It is not supported to change the WasapiProcedure once a device was initialized via Init(Int32, Int32, Int32, WasapiInitFlags, Single, Single, WasapiProcedure, IntPtr). If you need to change some internal processing logic during processing, you might use some kind of "if" statements within this callback procedure.