private bool setAudioDevice(int deviceIndex) { var device = audioDevices.ElementAtOrDefault(deviceIndex); // device is invalid if (!device.IsEnabled) { return(false); } // initialize new device bool initSuccess = InitBass(deviceIndex); if (Bass.LastError != Errors.Already && BassUtils.CheckFaulted(false)) { return(false); } if (!initSuccess) { Logger.Log("BASS failed to initialize but did not provide an error code", level: LogLevel.Error); 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); return(true); }
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 bool initSuccess = InitBass(deviceIndex); 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; FreeBass(); initSuccess = InitBass(deviceIndex); } if (BassUtils.CheckFaulted(false)) { return(false); } if (!initSuccess) { Logger.Log("BASS failed to initialize but did not provide an error code", level: LogLevel.Error); 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); }
private bool setAudioDevice(int deviceIndex) { var device = audioDevices.ElementAtOrDefault(deviceIndex); // device is invalid if (!device.IsEnabled) { return(false); } // we don't want bass initializing with real audio device on headless test runs. if (deviceIndex != Bass.NoSoundDevice && DebugUtils.IsNUnitRunning) { return(false); } // initialize new device bool initSuccess = InitBass(deviceIndex); if (Bass.LastError != Errors.Already && BassUtils.CheckFaulted(false)) { return(false); } if (!initSuccess) { Logger.Log("BASS failed to initialize but did not provide an error code", level: LogLevel.Error); return(false); } Logger.Log($@"🔈 BASS initialised BASS version: {Bass.Version} BASS FX version: {BassFx.Version} BASS MIX version: {BassMix.Version} Device: {device.Name} Driver: {device.Driver} Update period: {Bass.UpdatePeriod} ms Device buffer length: {Bass.DeviceBufferLength} ms Playback buffer length: {Bass.PlaybackBufferLength} ms"); //we have successfully initialised a new device. UpdateDevice(deviceIndex); return(true); }