BASS.NET API for the Un4seen BASS Audio Library

BassBASS_Init Method

BASS.NET API for the Un4seen BASS Audio Library
Initializes an output device.

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

public static bool BASS_Init(
	int device,
	int freq,
	BASSInit flags,
	IntPtr win


Type: SystemInt32
The device to use... -1 = default device, 0 = no sound, 1 = first real output device. BASS_GetDeviceInfo(Int32, BASS_DEVICEINFO) or BASS_GetDeviceCount can be used to get the total number of devices.
Type: SystemInt32
Output sample rate.
Type: Un4seen.BassBASSInit
Any combination of these flags (see BASSInit):
BASS_DEVICE_16BITSLimit the output to 16-bit.
BASS_DEVICE_MONOUse mono, else stereo.
BASS_DEVICE_STEREOLimit the output to stereo, saving some CPU if the device has more speakers available.
BASS_DEVICE_NOSPEAKERIgnore speaker arrangement. This flag tells BASS not to make any special consideration for speaker arrangements when using the SPEAKER flags, eg. swapping the CENLFE and REAR speaker channels in 5/7.1 speaker output. This flag should be used with plain multi-channel (rather than 5/7.1) devices.
BASS_DEVICE_FREQSet the device's output rate to freq, otherwise leave it as it is.
BASS_DEVICE_DSOUNDInitialize the device to use the old DirectSound output system instead of WASAPI. If WASAPI is not available (pre-Vista Windows), then this will be applied automatically.
BASS_DEVICE_AUDIOTRACKInitialize the device to use AudioTrack output instead of OpenSL ES. If OpenSL ES is not available (pre-2.3 Android), then this will be applied automatically.
BASS_DEVICE_DMIXLinux only: Initialize the device using the ALSA "dmix" plugin, else initialize the device for exclusive access.
BASS_DEVICE_SOFTWAREDisable hardware/fastpath output.
BASS_DEVICE_REINITReinitialize the device while retaining the device's existing BASS channels and 3D settings. This flag cannot be used with device -1.
Type: SystemIntPtr
The application's main window... Zero = the desktop window (use this for console applications).

Return Value

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

This function must be successfully called before using any sample, stream or MOD music functions. The recording functions may be used without having called this function.

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_SetDevice(Int32) is used to switch the current device. When successful, BASS_Init automatically sets the current thread's device to the one that was just initialized.

When using the default device (device = -1), BASS_GetDevice can be used to find out which device it was mapped to.

The BASS_CONFIG_DEV_BUFFER and BASS_CONFIG_DEV_PERIOD config options determine how much data is buffered for the device and how often it is updated.

When the BASS_DEVICE_REINIT flag is specified to request reinitialization, any BASS channels that were playing prior will continue to do so, if successful. But there is likely to be a small interruption to the sound, so it is best to reinitialize while nothing is playing. If reinitialization fails then playback will be paused and the device will be left in a partially-freed state. Reinitialization could be tried again with different parameters or BASS_Free used to fully free the device. Until BASS_Free is used, the device's BASS channels will still exist and can be moved to another device via BASS_ChannelSetDevice(Int32, Int32).

ERROR CODEDescription
BASS_ERROR_DXDirectX (or ALSA) is not installed.
BASS_ERROR_DEVICEThe device number specified is invalid.
BASS_ERROR_ALREADYThe device has already been initialized. You must call BASS_Free before you can initialize it again.
BASS_ERROR_DRIVERThere is no available device driver... the device may already be in use.
BASS_ERROR_FORMATThe specified format is not supported by the device. Try changing the freq and flags parameters.
BASS_ERROR_MEMThere is insufficient memory.
BASS_ERROR_NO3DThe device has no 3D support.
BASS_ERROR_UNKNOWNSome other mystery problem!


The sample format specified in the freq and flags parameters has no effect on the output on macOS or iOS, or Windows Vista and above - the device's native sample format is automatically used. On Linux, the output device will use the specified format if possible, but will otherwise use a format as close to it as possible. On Android, the device's native sample rate (as reported by the AudioTrack getNativeOutputSampleRate method) will be used unless the BASS_DEVICE_FREQ flag is specified, in which case the freq parameter will be used (this only affects BASS's output format, not the device's output format). If the BASS_DEVICE_FREQ flag is specified on macOS or iOS then the device's output rate will be set to the freq parameter if possible. The BASS_DEVICE_FREQ flag has no effect on other platforms. BASS_GetInfo can be used to check what the output format actually is.

On Android, when the BASS_DEVICE_AUDIOTRACK flag is not specified, AAudio or OpenSL ES output may be used depending on the BASS_CONFIG_ANDROID_AAUDIO config option setting. AAudio has a low latency mode, which will be enabled when BASS_CONFIG_DEV_BUFFER is set below 50.

The win parameter is only used with DirectSound output on Windows and is ignored in all other cases. The BASS_DEVICE_STEREO flag is ignored on macOS and Windows, except when using DirectSound output.

The BASS_DEVICE_SOFTWARE flag is only used on Windows to disable DirectSound hardware mixing and on Android to disable AAudio fastpath output.

The BASS_DEVICE_DMIX flag is only available on Linux, and allows multiple applications to share the device (if they all use 'dmix'). It may also be possible for multiple applications to use exclusive access if the device is capable of hardware mixing. If exclusive access initialization fails, the BASS_DEVICE_DMIX flag will automatically be tried; if that happens, it can be detected via BASS_GetInfo and the initflags.


Initialize BASS with the current form window handle:
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
See Also