Initializes a device.
BOOL BASS_WASAPI_Init( int device, DWORD freq, DWORD chans, DWORD flags, float buffer, float period, WASAPIPROC *proc, void *user );
|device||The device to use... -1 = default output device, -2 = default input device, -3 = default loopback input device. BASS_WASAPI_GetDeviceInfo can be used to enumerate the available devices.|
|freq||The sample rate... 0 = "mix format" sample rate|
|chans||The number of channels... 0 = "mix format" channels, 1 = mono, 2 = stereo, etc.|
|flags||Any combination of these flags.
|buffer||The length of the device's buffer in seconds or samples, depending on BASS_WASAPI_SAMPLES. This is a minimum and the driver may choose to use a larger buffer; BASS_WASAPI_GetInfo can be used to confirm what the buffer size is. For an output device, the buffer size determines the latency. With event-driven exclusive mode, there will be 2 buffers of this length, so the total buffer length is double.|
|period||The interval (in seconds or samples depending on BASS_WASAPI_SAMPLES) between callback function calls... 0 = use default. If the specified period is below the minimum update period, it will automatically be raised to that. This is ignored when the BASS_WASAPI_EVENT flag is specified, except in shared mode when buffer = 0 on Windows 10 (see remarks).|
|proc||The callback function to provide/receive sample data, or one of the following.|
|user||User instance data to pass to the callback function, or a BASS channel handle with WASAPIPROC_BASS. Unused with WASAPIPROC_PUSH.|
|BASS_ERROR_WASAPI||WASAPI is not available.|
|BASS_ERROR_DEVICE||device is invalid.|
|BASS_ERROR_ALREADY||The device has already been initialized. BASS_WASAPI_Free must be called before it can be initialized again.|
|BASS_ERROR_NOTAVAIL||Exclusive mode and/or event-driven buffering is unavailable on the device, or WASAPIPROC_PUSH is unavailable on input devices and when using event-driven buffering.|
|BASS_ERROR_DRIVER||The driver could not be initialized.|
|BASS_ERROR_HANDLE||The BASS channel handle in user is invalid, or not of the required type.|
|BASS_ERROR_FORMAT||The specified format (or that of the BASS channel) is not supported by the device. If the BASS_WASAPI_AUTOFORMAT flag was specified, no other format could be found either.|
|BASS_ERROR_BUSY||The device is already in use, eg. another process may have initialized it in exclusive mode.|
|BASS_ERROR_INIT||BASS has not been initialized.|
|BASS_ERROR_WASAPI_BUFFER||buffer is too large or small (exclusive mode only).|
|BASS_ERROR_WASAPI_CATEGORY||The category/raw mode could not be set.|
|BASS_ERROR_WASAPI_DENIED||Access to the device is denied. This could be due to privacy settings.|
|BASS_ERROR_UNKNOWN||Some other mystery problem!|
WASAPI does not support arbitrary sample formats, like DirectSound does. In particular, only the "mix format" (available from BASS_WASAPI_GetDeviceInfo) is generally supported in shared mode. BASS_WASAPI_CheckFormat 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.
A loopback device can only be used when the corresponding output device is not being used in exclusive mode, and it will only deliver data when the ouput device does; if the output device produces no data, then the loopback device will capture no data.
Shared mode usually has a fixed period of 10ms, but Windows 10 supports shorter periods, which allows smaller buffers and lower latency. A shorter period (and buffer) can be requested by setting buffer to 0 and period to the length wanted. If the requested period is lower than the device (or Windows) supports, then it will be automatically raised to the minimum supported. It will also be rounded up if it does not match the device's granularity. The actual period in use can be determined from the (minimum) amount of data that gets requested from the WASAPIPROC callback function. The shared mode period is a system-wide setting that affects all users of the device, particular those using event-driven buffering; they will be asked to provide data at the new period. If another process is already using a non-default period, then it will not be possible to set a different period until they finish; the existing period will have to be used in the meantime.
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 is used to switch the current device. When successful, BASS_WASAPI_Init 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.
BASS_WASAPI_Init(-1, 44100, 2, BASS_WASAPI_EXCLUSIVE, 0.1, 0, MyWasapiProc, NULL);
Initialize BASSWASAPI to feed a BASS channel to the default output device in event-driven exclusive mode, with a 100ms buffer (2x 50ms).
BASS_WASAPI_Init(-1, 0, 0, BASS_WASAPI_EXCLUSIVE|BASS_WASAPI_EVENT, 0.05, 0, WASAPIPROC_BASS, (void*)handle);