Initializes an output device.
BOOL BASS_Init( int device, DWORD freq, DWORD flags, HWND win, GUID *clsid );
device | The device to use... -1 = default device, 0 = no sound, 1 = first real output device. BASS_GetDeviceInfo can be used to enumerate the available devices. | ||||||||||||||||||||||||||
freq | Output sample rate. | ||||||||||||||||||||||||||
flags | A combination of these flags.
| ||||||||||||||||||||||||||
win | The application's main window... 0 = the desktop window (use this for console applications). This is only needed when using DirectSound output. | ||||||||||||||||||||||||||
clsid | Class identifier of the object to create, that will be used to initialize DirectSound... NULL = use default. |
BASS_ERROR_DX | DirectX (or ALSA on Linux) is not installed. |
BASS_ERROR_DEVICE | device is invalid. |
BASS_ERROR_ALREADY | The device has already been initialized. BASS_Free must be called before it can be initialized again. |
BASS_ERROR_DRIVER | There is no available device driver. |
BASS_ERROR_BUSY | Something else has exclusive use of the device. |
BASS_ERROR_FORMAT | The specified format is not supported by the device. Try changing the freq and flags parameters. |
BASS_ERROR_MEM | There is insufficient memory. |
BASS_ERROR_NO3D | Could not initialize 3D support. |
BASS_ERROR_UNKNOWN | Some other mystery problem! |
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 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.
The sample format specified in the freq and flags parameters has no effect on the device output on iOS or OSX, and not on Windows unless VxD drivers are used (on Windows 98/95); with WDM drivers (on Windows XP/2000/Me/98SE), the output format is automatically set depending on the format of what is played and what the device supports, while on Vista and newer, the output format is determined by the user's choice in the Sound control panel. 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 iOS or OSX, 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.
When DirectSound output is used on Windows, BASS will not be generating the final output mix and so some BASS features will be unavailable, including sample rate conversion quality configuration, playback buffer bypassing, and access to the final mix.
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
On Windows, when specifying a class identifier (clsid), BASS_GetDSoundObject can be used to retrieve the DirectSound object after successful initialization, and through that access any special interfaces that the object may provide.
The win and clsid parameters are only used with DirectSound output on Windows and are ignored in all other cases. That applies to the BASS_DEVICE_LATENCY flag too, as latency information is otherwise available without it. The BASS_DEVICE_CPSPEAKERS and BASS_DEVICE_SPEAKERS flags only have effect on pre-Vista Windows; the number of available speakers is always accurately detected otherwise. The BASS_DEVICE_STEREO flag is ignored on Windows and OSX.
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.
BASS_Init(-1, 44100, 0, hwnd, NULL);