Initializes a device.

    int device,
    DWORD freq,
    DWORD chans,
    DWORD flags,
    float buffer,
    float period,
    WASAPIPROC *proc,
    void *user


deviceThe 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.
freqThe sample rate... 0 = "mix format" sample rate
chansThe number of channels... 0 = "mix format" channels, 1 = mono, 2 = stereo, etc.
flagsAny combination of these flags.
BASS_WASAPI_ASYNCCall the callback function asynchronously. This only applies to event-driven exclusive mode output and is otherwise ignored. When enabled, a buffer is filled asynchronously in advance. This reduces the chances of underruns but also increases latency by up to one buffer length. If an underrun does occur, a silent buffer (rather than nothing) is still sent to the device, which can prevent sound glitches on some devices following an underrun.
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. This flag disables resampling.
BASS_WASAPI_BUFFEREnable double buffering, for use by BASS_WASAPI_GetData and BASS_WASAPI_GetLevel and BASS_WASAPI_GetLevelEx. This requires BASS to have been initilized, via BASS_Init.
BASS_WASAPI_DITHERApply dither (TPDF) when converting floating-point sample data to the device's format. This flag only has effect on exclusive mode output.
BASS_WASAPI_EVENTEnable event-driven buffering. BASSWASAPI will normally periodically write data to (or read data from) the device's buffer according to the period parameter, but with the event-driven system WASAPI will signal to BASSWASAPI when more data should be written to (or read from) the buffer. So the period parameter is ignored. In exclusive mode, there are 2 buffers of buffer length that are processed alternately. Event-driven buffering is unavailable on loopback devices.
BASS_WASAPI_EXCLUSIVEInitialize the device in exclusive mode, else shared mode. The HIWORD -- use MAKELONG(flags,format) -- can be used to 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. Exclusive mode is unavailable on loopback devices.
BASS_WASAPI_RAWRequest raw mode, which bypasses any sound enhancements that have been enabled on the device. This is only available on Windows 8.1 and above.
BASS_WASAPI_SAMPLESbuffer and period are in samples rather than seconds.
One of the following can also be used to set the audio category on Windows 8 and above (otherwise ignored).
BASS_WASAPI_CATEGORY_ALERTSAlert sounds. For output devices only.
BASS_WASAPI_CATEGORY_COMMUNICATIONSReal-time communications, such as VOIP or chat.
BASS_WASAPI_CATEGORY_GAMECHATGame chat audio. Similar to COMMUNICATIONS except that this will not attenuate other streams. For output devices only.
BASS_WASAPI_CATEGORY_GAMEEFFECTSGame sound effects. For output devices only.
BASS_WASAPI_CATEGORY_GAMEMEDIABackground audio for games. For output devices only.
BASS_WASAPI_CATEGORY_MEDIAStream that includes audio without dialog. For output devices only.
BASS_WASAPI_CATEGORY_MOVIEStream that includes audio with dialog. For output devices only.
BASS_WASAPI_CATEGORY_SOUNDEFFECTSSound effects. For output devices only.
bufferThe 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.
periodThe 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).
procThe callback function to provide/receive sample data, or one of the following.
WASAPIPROC_BASSFeed data to/from a BASS channel, specified in the user parameter. It must be a decoding channel (using BASS_STREAM_DECODE) for an output device, or a "push" or "dummy" stream (using STREAMPROC_PUSH or STREAMPROC_DUMMY) for an input device. The freq and chans parameters are ignored and the sample format of the BASS channel is used instead, but it must be floating-point (BASS_SAMPLE_FLOAT).
WASAPIPROC_PUSHInstead of BASSWASAPI pulling data from a WASAPIPROC function, data is pushed to BASSWASAPI via BASS_WASAPI_PutData. This cannot be used with input devices or the BASS_WASAPI_EVENT flag.
userUser instance data to pass to the callback function, or a BASS channel handle with WASAPIPROC_BASS. Unused with WASAPIPROC_PUSH.

Return value

If the device was successfully initialized, TRUE is returned, else FALSE is returned. Use BASS_ErrorGetCode to get the error code.

Error codes

BASS_ERROR_DEVICEdevice is invalid.
BASS_ERROR_ALREADYThe device has already been initialized. BASS_WASAPI_Free must be called before it can be initialized again.
BASS_ERROR_NOTAVAILExclusive 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_DRIVERThe driver could not be initialized.
BASS_ERROR_HANDLEThe BASS channel handle in user is invalid, or not of the required type.
BASS_ERROR_FORMATThe 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_BUSYThe device is already in use, eg. another process may have initialized it in exclusive mode.
BASS_ERROR_INITBASS has not been initialized.
BASS_ERROR_WASAPI_BUFFERbuffer is too large or small (exclusive mode only).
BASS_ERROR_WASAPI_CATEGORYThe category/raw mode could not be set.
BASS_ERROR_WASAPI_DENIEDAccess to the device is denied. This could be due to privacy settings.
BASS_ERROR_UNKNOWNSome other mystery problem!


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

WASAPI can resample when required in shared mode (if the BASS_WASAPI_AUTOFORMAT flag is not specified), except with loopback input devices prior to Windows 10. WASAPI will not resample in exclusive mode; the requested sample format must be supported by the device. 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 formats, as well as playing multiple sources. When using BASSmix for mixing, it is generally a good idea to also have it handle resampling even if WASAPI could, to avoid the possiblity of resampling twice (from source format to mixer format to WASAPI format).

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.


Initialize BASSWASAPI to use the default output device in exclusive mode, with 44100 Hz stereo output, and a 100ms buffer with the default period.
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).


See also