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 ); }
private void InitBass() { for (var i = 0; i < BassWasapi.DeviceCount; i++) { var device = BassWasapi.GetDeviceInfo(i); if (device.IsEnabled && device.IsLoopback) { _deviceList.Add(string.Format($"{i} - {device.Name}")); } } Bass.Configure(Configuration.UpdateThreads, false); var result = Bass.Init(Device: 0, Frequency: 44100, Flags: DeviceInitFlags.Default, Win: IntPtr.Zero); if (result) { Log.Debug("Successfully initialized BASS.Init()"); } if (!result) { Log.Error("Bass initialization failed:" + Bass.LastError); } }
public static void InitializeInputDeviceList() { _inputDevices = new List <WasapiInputDevice>(); // Keep in local variable to avoid double evaluation var deviceCount = BassWasapi.DeviceCount; for (var deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { var deviceInfo = BassWasapi.GetDeviceInfo(deviceIndex); var isValidInputDevice = deviceInfo.IsEnabled && (deviceInfo.IsLoopback || deviceInfo.IsInput); if (!isValidInputDevice) { continue; } Log.Debug($"Found Wasapi input ID:{_inputDevices.Count} {deviceInfo.Name} LoopBack:{deviceInfo.IsLoopback} IsInput:{deviceInfo.IsInput} (at {deviceIndex})"); _inputDevices.Add(new WasapiInputDevice() { WasapiDeviceIndex = deviceIndex, DeviceInfo = deviceInfo, }); } }
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(); }
protected override void OnRefresh() { AvailableAudioSources.Clear(); WasapiDeviceInfo devInfo; for (var i = 0; BassWasapi.GetDeviceInfo(i, out devInfo); ++i) { AvailableAudioSources.Add(devInfo); } SelectedAudioDevice = AvailableAudioSources[0]; }
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 IEnumerable <SelectionConfigurationOption> GetWASAPIDevices() { yield return(new SelectionConfigurationOption(BassWasapi.DefaultDevice.ToString(), "Default Device")); for (int a = 0, b = BassWasapi.DeviceCount; a < b; a++) { var deviceInfo = default(WasapiDeviceInfo); BassUtils.OK(BassWasapi.GetDeviceInfo(a, out deviceInfo)); if (deviceInfo.IsInput || deviceInfo.IsDisabled || deviceInfo.IsLoopback || deviceInfo.IsUnplugged) { continue; } LogManager.Logger.Write(typeof(BassWasapiStreamOutputConfiguration), LogLevel.Debug, "WASAPI Device: {0} => {1} => {2} => {3} => {4}", a, deviceInfo.ID, deviceInfo.Name, Enum.GetName(typeof(WasapiDeviceType), deviceInfo.Type), deviceInfo.MixFrequency); yield return(new SelectionConfigurationOption(deviceInfo.ID, deviceInfo.Name, string.Format("{0} ({1})", deviceInfo.Name, Enum.GetName(typeof(WasapiDeviceType), deviceInfo.Type)))); } }
public static int GetWasapiDevice(SelectionConfigurationOption option) { if (!string.Equals(option.Id, BassWasapi.DefaultDevice.ToString())) { for (int a = 0, b = BassWasapi.DeviceCount; a < b; a++) { var deviceInfo = default(WasapiDeviceInfo); BassUtils.OK(BassWasapi.GetDeviceInfo(a, out deviceInfo)); if (string.Equals(deviceInfo.ID, option.Id, StringComparison.OrdinalIgnoreCase)) { return(a); } } } return(BassWasapi.DefaultDevice); }
public void WasapiInit() { int i; do { i = new Random().Next(BassWasapi.DeviceCount); }while (!BassWasapi.GetDeviceInfo(i).IsEnabled); if (BassWasapi.GetDeviceInfo(i).IsInitialized) { BassWasapi.CurrentDevice = i; BassWasapi.Free(); } var proc = new WasapiProcedure((b, c, u) => c); Assert.IsTrue(BassWasapi.Init(i, 44100, 2, WasapiInitFlags.Shared, 0, 0, proc), "Cannot Init a random WASAPI device - {0}", Bass.LastError); Assert.IsTrue(BassWasapi.Free(), "Cannot free initialized WASAPI device - {0}", Bass.LastError); }