private bool setAudioDevice(int deviceIndex) { var device = audioDevices.ElementAtOrDefault(deviceIndex); // device is invalid if (!device.IsEnabled) { return(false); } // same device if (device.IsInitialized && deviceIndex == Bass.CurrentDevice) { return(true); } // initialize new device if (!InitBass(deviceIndex) && Bass.LastError != Errors.Already) { return(false); } if (Bass.LastError == Errors.Already) { // We check if the initialization error is that we already initialized the device // If it is, it means we can just tell Bass to use the already initialized device without much // other fuzz. Bass.CurrentDevice = deviceIndex; Bass.Free(); InitBass(deviceIndex); } // Sync newly initialized device syncAudioDevices(); if (Bass.LastError != Errors.OK) { Logger.Log($@"BASS failed to initialize with error code {Bass.LastError:D}: {Bass.LastError}.", LoggingTarget.Runtime, LogLevel.Important); return(false); } Logger.Log($@"BASS Initialized BASS Version: {Bass.Version} BASS FX Version: {ManagedBass.Fx.BassFx.Version} Device: {device.Name} Drive: {device.Driver}"); //we have successfully initialised a new device. UpdateDevice(deviceIndex); Bass.PlaybackBufferLength = 100; Bass.UpdatePeriod = 5; return(true); }