private static void Update(int device, WasapiInitFlags flags) { var info = default(WasapiInfo); var deviceInfo = default(WasapiDeviceInfo); BassUtils.OK(BassWasapi.GetInfo(out info)); BassUtils.OK(BassWasapi.GetDeviceInfo(BassWasapi.CurrentDevice, out deviceInfo)); Info = new BassWasapiDeviceInfo( BassWasapi.CurrentDevice, deviceInfo.MixFrequency, 0, deviceInfo.MixChannels, info.BufferLength, GetSupportedFormats( BassWasapi.CurrentDevice, flags ), BassWasapi.CheckFormat( BassWasapi.CurrentDevice, deviceInfo.MixFrequency, deviceInfo.MixChannels, flags ), device == BassWasapi.DefaultDevice ); }
public static void Init(int device, bool exclusive, bool eventDriven, bool dither, int frequency = 0, int channels = 0) { LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Initializing BASS WASAPI."); var flags = WasapiInitFlags.Shared; if (exclusive) { flags |= WasapiInitFlags.Exclusive; } if (eventDriven) { flags |= WasapiInitFlags.EventDriven; } if (dither) { flags |= WasapiInitFlags.Dither; } BassUtils.OK(BassWasapiHandler.Init(device, frequency, channels, flags, 0, 0)); IsInitialized = true; Device = device; Exclusive = exclusive; EventDriven = eventDriven; var exception = default(Exception); for (var a = 1; a <= INIT_ATTEMPTS; a++) { LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detecting WASAPI device, attempt: {0}", a); try { var deviceInfo = default(WasapiDeviceInfo); BassUtils.OK(BassWasapi.GetDeviceInfo(device, out deviceInfo)); Devices[device] = new BassWasapiDeviceInfo( deviceInfo.MixFrequency, 0, deviceInfo.MixChannels, GetSupportedFormats(device, flags), BassWasapi.CheckFormat(device, deviceInfo.MixFrequency, deviceInfo.MixChannels, flags) ); LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Inputs => {1}, Outputs = {2}, Rate = {3}, Format = {4}", Device, Devices[device].Inputs, Info.Outputs, Info.Rate, Enum.GetName(typeof(WasapiFormat), Info.Format)); LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Rates => {1}", Device, string.Join(", ", Devices[device].SupportedRates)); return; } catch (Exception e) { exception = e; LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Warn, "Failed to detect WASAPI device: {0}", e.Message); } Thread.Sleep(INIT_ATTEMPT_INTERVAL); } if (exception != null) { Free(); throw exception; } throw new NotImplementedException(); }
public static void Detect(int device, bool exclusive, bool autoFormat, bool buffer, bool eventDriven, bool dither) { if (IsInitialized) { throw new InvalidOperationException("Device is already initialized."); } IsInitialized = true; LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detecting WASAPI device."); try { var flags = GetFlags(exclusive, autoFormat, buffer, eventDriven, dither); BassUtils.OK( BassWasapiHandler.Init( device, 0, 0, flags ) ); var deviceInfo = default(WasapiDeviceInfo); BassUtils.OK(BassWasapi.GetDeviceInfo(BassWasapi.CurrentDevice, out deviceInfo)); Info = new BassWasapiDeviceInfo( BassWasapi.CurrentDevice, deviceInfo.MixFrequency, 0, deviceInfo.MixChannels, GetSupportedFormats( BassWasapi.CurrentDevice, flags ), BassWasapi.CheckFormat( BassWasapi.CurrentDevice, deviceInfo.MixFrequency, deviceInfo.MixChannels, flags ), device == BassWasapi.DefaultDevice ); LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Inputs => {1}, Outputs = {2}, Rate = {3}, Format = {4}", BassWasapi.CurrentDevice, Info.Inputs, Info.Outputs, Info.Rate, Enum.GetName(typeof(WasapiFormat), Info.Format)); LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Rates => {1}", BassWasapi.CurrentDevice, string.Join(", ", Info.SupportedRates)); } finally { Free(); } }
private static IDictionary <int, WasapiFormat> GetSupportedFormats(int device, WasapiInitFlags flags) { var supportedFormats = new Dictionary <int, WasapiFormat>(); foreach (var rate in OutputRate.PCM) { var format = BassWasapi.CheckFormat(device, rate, BassWasapi.Info.Channels, flags); if (format == WasapiFormat.Unknown) { continue; } supportedFormats.Add(rate, format); } return(supportedFormats); }