BASS.NET API for the Un4seen BASS Audio LibraryBassWasapiBASS_WASAPI_Init Method (Int32, Int32, Int32, BASSWASAPIInit, BASSWASAPIFormat, Single, Single, WASAPIPROC, IntPtr)BASS.NET API for the Un4seen BASS Audio Library
Initializes a Wasapi device/driver (endpoint) in exclusive mode.

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

public static bool BASS_WASAPI_Init(
	int device,
	int freq,
	int chans,
	BASSWASAPIInit flags,
	BASSWASAPIFormat format,
	float buffer,
	float period,
	IntPtr user


Type: SystemInt32
The device to use... 0 = first device, -1 = default output device, -2 = default input device. BASS_WASAPI_GetDeviceInfo(Int32, BASS_WASAPI_DEVICEINFO) can be used to enumerate the available devices.
Type: SystemInt32
The sample rate to use... 0 = "mix format" sample rate.
Type: SystemInt32
The number of channels to use... 0 = "mix format" channels, 1 = mono, 2 = stereo, etc.
Type: Un4seen.BassWasapiBASSWASAPIInit
Any combination of these flags (see BASSWASAPIInit):
BASS_WASAPI_EXCLUSIVEThis flag will be applied automatically by this overload! The format parameter can be used to limit the sample format that is used in exclusive mode.
BASS_WASAPI_AUTOFORMATAutomatically choose another sample format if the specified format is not supported. If possible, a higher sample rate than freq will be used, rather than a lower one.
BASS_WASAPI_BUFFEREnable double buffering, for use by BASS_WASAPI_GetData(IntPtr, Int32) and BASS_WASAPI_GetLevel. This requires the BASS "no sound" device to have been initilized, via BASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr).
BASS_WASAPI_EVENTEnables the event-driven system. It is only supported when a WASAPIPROC function is provided, ie. not when using BASS_WASAPI_PutData(IntPtr, Int32). When used with shared mode, the user-provided 'buffer' and 'period' lengths are ignored and WASAPI decides what buffer to use (BASS_WASAPI_GetInfo(BASS_WASAPI_INFO) can be used to check that).
Type: Un4seen.BassWasapiBASSWASAPIFormat
Limit the sample format that is used in exclusive mode. The default is to try 32-bit floating-point, 32-bit integer, 24-bit integer, 16-bit integer, 8-bit integer, in that order. A BASS_WASAPI_FORMAT value (see BASS_WASAPI_INFO) can be used to bypass the formats that precede it in that list.
Type: SystemSingle
The length of the device's buffer in seconds. This is a minimum and the driver may choose to use a larger buffer; BASS_WASAPI_GetInfo(BASS_WASAPI_INFO) can be used to confirm what the buffer size is. For an output device, the buffer size determines the latency.
Type: SystemSingle
The interval (in seconds) between callback function calls... 0 = use default. If the specified period is below the minimum update period, it will automatically be raised to that.

The update period specifies the time between WASAPIPROC calls. The BASS_WASAPI_DEVICEINFO (see BASS_WASAPI_GetDeviceInfo(Int32, BASS_WASAPI_DEVICEINFO)) "minperiod" and "defperiod" values are actually minimum/default update periods.

Type: Un4seen.BassWasapiWASAPIPROC
The user defined function to process the channel. Use to create a Wasapi "push" device (to which you can feed sample data via BASS_WASAPI_PutData(IntPtr, Int32)).
Type: SystemIntPtr
User instance data to pass to the callback function.

Return Value

Type: Boolean
If the device was successfully initialized, is returned, else is returned. Use BASS_ErrorGetCode to get the error code.

For convenience, devices are always initialized to use their highest sample resolution and that is then converted to 32-bit floating-point, so that WASAPIPROC callback functions and the BASS_WASAPI_PutData(IntPtr, Int32) and BASS_WASAPI_GetData(IntPtr, Int32) functions are always dealing with the same sample format. The device's sample format can be obtained via BASS_WASAPI_GetInfo(BASS_WASAPI_INFO).

WASAPI does not support arbitrary sample formats, like DirectSound does. In particular, only the "mix format" (available from BASS_WASAPI_GetDeviceInfo(Int32, BASS_WASAPI_DEVICEINFO)) is generally supported in shared mode. BASS_WASAPI_CheckFormat(Int32, Int32, Int32, BASSWASAPIInit) can be used to check whether a particular sample format is supported. The BASSmix add-on can be used to play (or record) in otherwise unsupported sample formats, as well as playing multiple sources.

The initialized device will not begin processing data until BASS_WASAPI_Start is called.

Simultaneously using multiple devices is supported in the BASS API via a context switching system; instead of there being an extra "device" parameter in the function calls, the device to be used is set prior to calling the functions. BASS_WASAPI_SetDevice(Int32) is used to switch the current device. When successful, BASS_WASAPI_Init(Int32, Int32, Int32, BASSWASAPIInit, Single, Single, WASAPIPROC, IntPtr) automatically sets the current thread's device to the one that was just initialized.

When using the default output or input device, BASS_WASAPI_GetDevice can be used to find out which device it was mapped to.

In SHARED mode you must initialize the device with the current WASAPI mixer sample rate and number of channels (see the BASS_WASAPI_DEVICEINFO "mixfreq" and "mixchans" properties).

In EXCLUSIVE mode you might use any sample rate and number of channels which are supported by the device/driver.

This function must be successfully called before any input or output can be performed.

In EXCLUSIVE mode, the "period" value will affect what's an acceptable "buffer" value (it appears that the buffer must be at least 4x the period). In SHARED mode, it's the other way round, the "period" will be reduced to fit the "buffer" if necessary (with a minimum of the "defperiod" value). The system will limit them to an acceptable range, so for example, you could use a very small value (eg. 0.0001) for both, to get the minimum possible latency.

Note: When initializing an input (capture or loopback) device, it might be the case, that the device is automatically muted once initialized. You can use the BASS_WASAPI_GetMute(BASSWASAPIVolume)/BASS_WASAPI_SetMute(BASSWASAPIVolume, Boolean) methods to check and probably toggle this.

ERROR CODEDescription
BASS_ERROR_DEVICEThe device number specified is invalid.
BASS_ERROR_ALREADYA device has already been initialized. You must call BASS_WASAPI_Free before you can initialize again.
BASS_ERROR_ILLPARAMAn illegal parameter was specified (a WASAPIPROC must be provided for an input device).
BASS_ERROR_DRIVERThe driver could not be initialized.
BASS_ERROR_FORMATThe specified format is not supported by the device. If the BASS_WASAPI_AUTOFORMAT flag was specified, no other format could be found either.
BASS_ERROR_INITThe BASS "no sound" device has not been initialized.
BASS_ERROR_BUSYThe device is busy (eg. in "exclusive" use by another process).
BASS_ERROR_UNKNOWNSome other mystery error.

See Also