BASS.NET API for the Un4seen BASS Audio Library

BassBASS_SetDevice Method

BASS.NET API for the Un4seen BASS Audio Library
Sets the device to use for subsequent calls in the current thread.

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

[DllImportAttribute("bass")]
public static bool BASS_SetDevice(
	int device
)

Parameters

device
Type: SystemInt32
The device to use... 0 = no sound, 1 = first real output device.

Return Value

Type: Boolean
If successful, then is returned, else is returned. Use BASS_ErrorGetCode to get the error code.
Remarks

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. The device setting is local to the current thread, so calling functions with different devices simultaneously in multiple threads is not a problem.

The functions that use the device selection are the following: BASS_Free, BASS_GetDSoundObject(Int32), BASS_GetInfo(BASS_INFO), BASS_Start, BASS_Stop, BASS_Pause, BASS_SetVolume(Single), BASS_GetVolume, BASS_Set3DFactors(Single, Single, Single), BASS_Get3DFactors(Single, Single, Single), BASS_Set3DPosition(BASS_3DVECTOR, BASS_3DVECTOR, BASS_3DVECTOR, BASS_3DVECTOR), BASS_Get3DPosition(BASS_3DVECTOR, BASS_3DVECTOR, BASS_3DVECTOR, BASS_3DVECTOR). It also determines which device is used by a new sample/stream/music: BASS_MusicLoad(String, Int64, Int32, BASSFlag, Int32), BASS_SampleLoad(String, Int64, Int32, Int32, BASSFlag), BASS_StreamCreateFile(String, Int64, Int64, BASSFlag), etc...

When one of the above functions (or BASS_GetDevice) is called, BASS will check the current thread's device setting, and if no device is selected (or the selected device is not initialized), BASS will automatically select the lowest device that is initialized. This means that when using a single device, there is no need to use this function; BASS will automatically use the device that is initialized. Even if you free the device, and initialize another, BASS will automatically switch to the one that is initialized.

ERROR CODEDescription
BASS_ERROR_DEVICEdevice is invalid.
BASS_ERROR_INITThe device has not been initialized.

Examples

// init device 1 and 2
Bass.BASS_Init(1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
// now device 1 is the current one
Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
// now device 2 is the current one
...
// create the stream for device 1
Bass.BASS_SetDevice(1);
// now device 1 is the current one
int stream = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
...
// create the stream for device 2
Bass.BASS_SetDevice(2);
// now device 2 is the current one
int stream = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
...
// free any initialized device
Bass.BASS_SetDevice(1);
Bass.BASS_Free();
Bass.BASS_SetDevice(2);
Bass.BASS_Free();
See Also

Reference