//Reinitializes active WASAPI device if necessary private void UpdateDevice() { if (WASAPIDeviceIndex == -1) { return; } if (deviceInitialized) { Console.WriteLine("Deinitializing WASAPI device"); BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); deviceInitialized = false; } BASS_WASAPI_DEVICEINFO devInfo = BassWasapi.BASS_WASAPI_GetDeviceInfo(WASAPIDeviceIndex); if (devInfo == null) { throw new WASAPIInitializationException("Device " + WASAPIDeviceIndex + " is invalid!"); } if (!BassWasapi.BASS_WASAPI_Init(WASAPIDeviceIndex, devInfo.mixfreq, devInfo.mixchans, BASSWASAPIInit.BASS_WASAPI_AUTOFORMAT | BASSWASAPIInit.BASS_WASAPI_BUFFER, 0f, 0f, WasapiProc, IntPtr.Zero)) { BASSError error = Bass.BASS_ErrorGetCode(); throw new WASAPIInitializationException("Unable to initialize WASAPI device " + WASAPIDeviceIndex, error); } if (!BassWasapi.BASS_WASAPI_Start()) { BASSError error = Bass.BASS_ErrorGetCode(); throw new WASAPIInitializationException("Unable to start WASAPI!", error); } Console.WriteLine("WASAPI device initialized"); deviceNumber = WASAPIDeviceIndex; sampleFrequency = devInfo.mixfreq; BuildLookupTables(); deviceInitialized = true; }
protected int tWASAPI処理(IntPtr buffer, int length, IntPtr user) { // BASSミキサからの出力データをそのまま WASAPI buffer へ丸投げ。 int num = Bass.BASS_ChannelGetData(this.hMixer_DeviceOut, buffer, length); // num = 実際に転送した長さ if (num == -1) { num = 0; } // 経過時間を更新。 // データの転送差分ではなく累積転送バイト数から算出する。 int n未再生バイト数 = BassWasapi.BASS_WASAPI_GetData(null, (int)BASSData.BASS_DATA_AVAILABLE); // 誤差削減のため、必要となるギリギリ直前に取得する。 this.n経過時間ms = (this.n累積転送バイト数 - n未再生バイト数) * 1000 / this.nミキサーの1秒あたりのバイト数; this.n経過時間を更新したシステム時刻ms = this.tmシステムタイマ.nシステム時刻ms; // 実出力遅延を更新。 // 未再生バイト数の平均値。 long n今回の遅延ms = n未再生バイト数 * 1000 / this.nミキサーの1秒あたりのバイト数; this.n実出力遅延ms = (this.b最初の実出力遅延算出) ? n今回の遅延ms : (this.n実出力遅延ms + n今回の遅延ms) / 2; this.b最初の実出力遅延算出 = false; // 経過時間を更新後に、今回分の累積転送バイト数を反映。 this.n累積転送バイト数 += num; return(num); }
/// <summary> /// Detect the supported output formats for WASAPI /// </summary> private void GetDeviceFormats(int deviceNo, DeviceInfo deviceInfo) { int[] channels = { 1, 2, 3, 4, 5, 6, 7, 8 }; int[] sampleRates = { 22050, 32000, 44100, 48000, 88200, 96000, 192000 }; deviceInfo.MaxRate = sampleRates.First(); deviceInfo.MinRate = sampleRates.Last(); foreach (BASSWASAPIInit init in new[] { BASSWASAPIInit.BASS_WASAPI_EXCLUSIVE, BASSWASAPIInit.BASS_WASAPI_SHARED }) { Log.Debug("Check {0} mode", init); foreach (var sampleRate in sampleRates) { foreach (var channel in channels) { BASSWASAPIFormat format = BassWasapi.BASS_WASAPI_CheckFormat(deviceNo, sampleRate, channel, init); if (format != BASSWASAPIFormat.BASS_WASAPI_FORMAT_UNKNOWN) { Log.Debug("- {0,-6} Hz / {1} ch: {2}", sampleRate, channel, format); if (channel > deviceInfo.Channels) { deviceInfo.Channels = channel; } if (sampleRate > deviceInfo.MaxRate) { deviceInfo.MaxRate = sampleRate; } if (sampleRate < deviceInfo.MinRate) { deviceInfo.MinRate = sampleRate; } } } } } }
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 bool GetFFTData(float[] fftDataBuffer) { float[] StereoBuffer = new float[(int)FFT * 2]; if ((BassWasapi.BASS_WASAPI_GetData(StereoBuffer, (int)FFT * 2)) > 0) { //if all the values are 0, then don't bother if (StereoBuffer.Count(x => x != 0) != 0) { float[] YStereoBuffer = new float[(int)FFT * 2]; float[] YBuffer = new float[(int)FFT]; FastFourierTransform(StereoBuffer, YStereoBuffer); //average the left and right channels for (int i = 0; i < (int)FFT; i++) { fftDataBuffer[i] = (StereoBuffer[i] + StereoBuffer[(int)FFT * 2 - i - 1]) / 2; YBuffer[i] = (YStereoBuffer[i] + YStereoBuffer[(int)FFT * 2 - i - 1]) / 2; } for (int i = 0; i < fftDataBuffer.Length / 2; i++) { // Calculate actual intensities for the FFT results. fftDataBuffer[i] = (float)Math.Sqrt(fftDataBuffer[i] * fftDataBuffer[i] + YStereoBuffer[i] * YStereoBuffer[i]) * 4; } } return(true); } else { return(false); } }
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, }); } }
private void FillWASAPIDeviceList() { _WASAPIDevices.Clear(); BassPlayerSettings settings = Controller.GetSettings(); BASS_WASAPI_DEVICEINFO[] deviceDescriptions = BassWasapi.BASS_WASAPI_GetDeviceInfos(); for (int i = 0; i < deviceDescriptions.Length; i++) { // Skip input devices, they have same name as output devices. BASS_WASAPI_DEVICEINFO deviceInfo = deviceDescriptions[i]; if ((deviceInfo.flags & (BASSWASAPIDeviceInfo.BASS_DEVICE_INPUT | BASSWASAPIDeviceInfo.BASS_DEVICE_DISABLED /*| BASSWASAPIDeviceInfo.BASS_DEVICE_UNPLUGGED */)) != 0) { continue; } ListItem deviceItem = new ListItem(Consts.KEY_NAME, deviceInfo.name) { Selected = deviceInfo.name == settings.WASAPIDevice }; deviceItem.SelectedProperty.Attach(delegate { var selected = _WASAPIDevices.FirstOrDefault(d => d.Selected); WASAPIDevice = selected != null ? selected.Labels[Consts.KEY_NAME].ToString() : string.Empty; }); deviceItem.SetLabel(KEY_GROUP, "WASAPI"); _WASAPIDevices.Add(deviceItem); } _WASAPIDevices.FireChange(); }
private void init() { for (int i = 0; i < BassWasapi.BASS_WASAPI_GetDeviceCount(); i++) { var device = BassWasapi.BASS_WASAPI_GetDeviceInfo(i); if (!device.IsEnabled) { continue; } var descriptor = string.Format("{0} - {1}", i, device.name); Console.WriteLine(descriptor); Console.WriteLine(" device.IsInput: " + (device.IsInput ? "true" : "false")); Console.WriteLine(" device.IsLoopback: " + (device.IsLoopback ? "true" : "false")); Console.WriteLine(" device.IsDefault: " + (device.IsDefault ? "true" : "false")); Console.WriteLine(" device.IsEnabled: " + (device.IsEnabled ? "true" : "false")); Console.WriteLine(" device.IsDisabled: " + (device.IsDisabled ? "true" : "false")); Console.WriteLine(" device.IsInitialized: " + (device.IsInitialized ? "true" : "false")); Console.WriteLine(" device.IsUnplugged: " + (device.IsUnplugged ? "true" : "false")); if (device.IsLoopback) { inlist.Items.Add(descriptor); } else if (!device.IsInput) { outlist.Items.Add(descriptor); } } inlist.SelectedIndex = 0; outlist.SelectedIndex = 0; }
public void start(double delay) { latency = (float)delay / 10; var str = (inlist.Items[inlist.SelectedIndex] as string); var array = str.Split(' '); sourceIndex = Convert.ToInt32(array[0]); str = (outlist.Items[outlist.SelectedIndex] as string); array = str.Split(' '); outIndex = Convert.ToInt32(array[0]); Console.WriteLine(sourceIndex + " " + outIndex); Console.WriteLine(delay); stop(); Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); // "No Sound" device init // Garbage collector can't track the reference BassWasapi holds, // so we're adding a reference here to prevent garbage collection inProc = sourceWasapiProc; outProc = outWasapiProc; BassWasapi.BASS_WASAPI_Init(sourceIndex, 44100, 0, 0, 1, 0, inProc, IntPtr.Zero); BassWasapi.BASS_WASAPI_Init(outIndex, 44100, 0, 0, 4 * latency, 1 * latency, outProc, IntPtr.Zero); BassWasapi.BASS_WASAPI_SetDevice(outIndex); pushstr = Bass.BASS_StreamCreatePush(44100, 2, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT, IntPtr.Zero); outstr = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT); BassMix.BASS_Mixer_StreamAddChannel(outstr, pushstr, 0); BassWasapi.BASS_WASAPI_SetDevice(sourceIndex); BassWasapi.BASS_WASAPI_Start(); BassWasapi.BASS_WASAPI_SetDevice(outIndex); BassWasapi.BASS_WASAPI_Start(); }
public float GetCPUusage() { float f; switch (SoundDeviceType) { case ESoundDeviceType.ExclusiveWASAPI: case ESoundDeviceType.SharedWASAPI: f = BassWasapi.BASS_WASAPI_GetCPU(); break; case ESoundDeviceType.ASIO: f = BassAsio.BASS_ASIO_GetCPU(); break; case ESoundDeviceType.BASS: f = Bass.BASS_GetCPU(); break; case ESoundDeviceType.OpenAL: f = 0.0f; break; default: f = 0.0f; break; } return(f); }
protected virtual bool StartWASAPI() { for (var a = 1; a <= START_ATTEMPTS; a++) { Logger.Write(this, LogLevel.Debug, "Starting WASAPI, attempt: {0}", a); try { var success = BassWasapi.Start(); if (success) { Logger.Write(this, LogLevel.Debug, "Successfully started WASAPI."); return(true); } else { Logger.Write(this, LogLevel.Warn, "Failed to start WASAPI: {0}", Enum.GetName(typeof(Errors), Bass.LastError)); } } catch (Exception e) { //Nothing can be done. Logger.Write(this, LogLevel.Warn, "Failed to start WASAPI: {0}", e.Message); } Thread.Sleep(START_ATTEMPT_INTERVAL); } Logger.Write(this, LogLevel.Warn, "Failed to start WASAPI after {0} attempts.", START_ATTEMPTS); return(false); }
/* * private void CreateContextMenu() * { * _notifyIcon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(); * _notifyIcon.ContextMenuStrip.Items.Add("Dashboard").Click += (s, e) => ShowMainWindow(); * _notifyIcon.ContextMenuStrip.Items.Add("Enable All").Click += (s, e) => MyUtils.EnableAll(); * _notifyIcon.ContextMenuStrip.Items.Add("Disable All").Click += (s, e) => MyUtils.DisableAll(); * * ToolStrip ts = new ToolStrip(); * ToolStripDropDownButton tsddb = new ToolStripDropDownButton("device x"); * ts.Items.Add(tsddb); * //tsddb.DropDown = _notifyIcon.ContextMenuStrip; * * * _notifyIcon.ContextMenuStrip.Items.Add("Exit").Click += (s, e) => ExitApplication(); * } */ private void CreateContextMenu2() { System.Windows.Forms.ContextMenu m = new System.Windows.Forms.ContextMenu(); m.MenuItems.Add("Dashboard").Click += (s, e) => ShowMainWindow(); m.MenuItems.Add("Enable All").Click += (s, e) => MyUtils.EnableAll(); m.MenuItems.Add("Disable All").Click += (s, e) => MyUtils.DisableAll(); List <MenuItem> mItems = new List <MenuItem>(); for (int i = 0; i < BassWasapi.BASS_WASAPI_GetDeviceCount(); i++) { var device = BassWasapi.BASS_WASAPI_GetDeviceInfo(i); if (device.IsEnabled && device.IsLoopback) { var x = new MenuItem(string.Format("{0} - {1}", i, device.name), AudioSwitching); mItems.Add(x); } } MenuItem mi = new MenuItem("Audio Device", mItems.ToArray()); m.MenuItems.Add(mi); //tsddb.DropDown = _notifyIcon.ContextMenuStrip; m.MenuItems.Add("Exit").Click += (s, e) => ExitApplication(); _notifyIcon.ContextMenu = m; }
public static void InitializeAudioDevice(string device) { try { if (audioDevices.ContainsKey(device)) { selectedaudioDevices = (JObject)audioDevices[device]; } else { selectedaudioDevices = defaultAudio(); } BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); BassWasapi.BASS_WASAPI_Init((int)selectedaudioDevices["id"], 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, ESPRGB._process, IntPtr.Zero); BassWasapi.BASS_WASAPI_Start(); } catch { selectedaudioDevices = defaultAudio(); BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); BassWasapi.BASS_WASAPI_Init((int)selectedaudioDevices["id"], 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, ESPRGB._process, IntPtr.Zero); BassWasapi.BASS_WASAPI_Start(); } }
public static void BASSInitSystem(Boolean PreviewMode) { try { Bass.BASS_StreamFree(MainWindow.KMCGlobals._recHandle); Bass.BASS_Free(); Bass.BASS_Init(0, Properties.Settings.Default.AudioFreq, BASSInit.BASS_DEVICE_NOSPEAKER, IntPtr.Zero); if (!PreviewMode) { Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_MIDI_VOICES, 100000); } else { BassWasapi.BASS_WASAPI_Init(-1, 0, 2, BASSWASAPIInit.BASS_WASAPI_BUFFER, 0, 0, null, IntPtr.Zero); BASS_WASAPI_DEVICEINFO info = new BASS_WASAPI_DEVICEINFO(); BassWasapi.BASS_WASAPI_GetDeviceInfo(BassWasapi.BASS_WASAPI_GetDevice(), info); MainWindow.KMCGlobals.RealTimeFreq = info.mixfreq; BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); Bass.BASS_Init(0, info.mixfreq, BASSInit.BASS_DEVICE_NOSPEAKER, IntPtr.Zero); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_MIDI_VOICES, 2000); } } catch (Exception ex) { BASSCloseStreamCrash(ex); } }
/// <summary> /// Detect the supported output formats for WASAPI /// </summary> private void GetDeviceFormats(int deviceNo, DeviceInfo deviceInfo) { int[] channels = { 1, 2, 3, 4, 5, 6, 7, 8 }; int[] sampleRates = { 22050, 32000, 44100, 48000, 88200, 96000, 192000 }; deviceInfo.MaxRate = sampleRates.First(); deviceInfo.MinRate = sampleRates.Last(); foreach (var sampleRate in sampleRates) { foreach (var channel in channels) { BASSWASAPIFormat format = BassWasapi.BASS_WASAPI_CheckFormat(deviceNo, sampleRate, channel, _flags & (BASSWASAPIInit.BASS_WASAPI_EXCLUSIVE | BASSWASAPIInit.BASS_WASAPI_SHARED)); if (format != BASSWASAPIFormat.BASS_WASAPI_FORMAT_UNKNOWN) { if (channel > deviceInfo.Channels) { deviceInfo.Channels = channel; } if (sampleRate > deviceInfo.MaxRate) { deviceInfo.MaxRate = sampleRate; } if (sampleRate < deviceInfo.MinRate) { deviceInfo.MinRate = sampleRate; } } } } }
public void Enable(Button enableButton, ComboBox deviceList) { //if (_enabledButton != null) _enabledButton.Content = "Enable"; _enabledButton = enableButton; _enabledComboBox = deviceList; if (!_initialized) { var s = deviceList.Items[deviceList.SelectedIndex] as string; if (s != null) { var array = s.Split(' '); _deviceIndex = Convert.ToInt32(array[0]); } var result = BassWasapi.BASS_WASAPI_Init(_deviceIndex, 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, _process, IntPtr.Zero); if (!result) { var error = Bass.BASS_ErrorGetCode(); MessageBox.Show(error.ToString()); } else { _initialized = true; deviceList.IsEnabled = false; } } _displayRefreshTimer.IsEnabled = true; BassWasapi.BASS_WASAPI_Start(); }
/// <summary> /// Retrieves information on a device and adds it to the static deviceinfo dictionary do it can be reused later. /// </summary> /// <param name="deviceNo">Device number to retrieve information on.</param> protected void CollectDeviceInfo(int deviceNo) { // Device info is saved in a dictionary so it can be reused lateron. if (!_deviceInfos.ContainsKey(deviceNo)) { Log.Debug("Collecting device info"); BASS_WASAPI_DEVICEINFO bassDeviceInfo = BassWasapi.BASS_WASAPI_GetDeviceInfo(deviceNo); if (bassDeviceInfo == null) { throw new BassLibraryException("BASS_WASAPI_GetDeviceInfo"); } BASS_WASAPI_INFO bassInfo = BassWasapi.BASS_WASAPI_GetInfo(); if (bassInfo == null) { throw new BassLibraryException("BASS_WASAPI_GetInfo"); } DeviceInfo deviceInfo = new DeviceInfo { Name = bassDeviceInfo.name, Driver = "WASAPI", Channels = bassInfo.chans, MinRate = bassInfo.freq, MaxRate = bassInfo.freq, }; GetDeviceFormats(deviceNo, deviceInfo); lock (_deviceInfos) _deviceInfos.Add(deviceNo, deviceInfo); } Log.Debug("WASAPI device info: {0}", _deviceInfos[_deviceNo].ToString()); }
//Adds all valid detected WASAPI devices to the Device Selection menu item private void AddValidWasapiDevices() { deviceSelectionToolStripMenuItem.DropDownItems.Clear(); BASS_WASAPI_DEVICEINFO[] devices = BassWasapi.BASS_WASAPI_GetDeviceInfos(); List <string> deviceNameList = new List <string>(); for (int i = 0; i < devices.Length; i++) { var curDevice = devices[i]; if (curDevice.IsEnabled && curDevice.SupportsRecording) { string deviceName = curDevice.name; if (curDevice.IsLoopback) { deviceName = deviceName + " (Loopback)"; } if (deviceNameList.Contains(curDevice.name)) { deviceName = string.Format("{0} ({1})", curDevice.name, i); } deviceNameList.Add(deviceName); if (Properties.Settings.Default.DeviceIndex == i) { AddDeviceToMenuItem(deviceName, i, true); } else { AddDeviceToMenuItem(deviceName, i, false); } } } AddDeviceToMenuItem("Reload Devices...", -2, false); }
private void Init() { bool result = false; //Old code takes years to find devices (because he cycles through devices that aren't even attached) /*for (int i = 0; i < BassWasapi.BASS_WASAPI_GetDeviceCount(); i++) * { * var device = BassWasapi.BASS_WASAPI_GetDeviceInfo(i); * if (device.IsEnabled && device.IsLoopback) * { * windowInst.devicesCombo.Items.Add(string.Format("{0} - {1}", i, device.name)); * } * }*/ BASS_WASAPI_DEVICEINFO info; for (int i = 1; (info = BassWasapi.BASS_WASAPI_GetDeviceInfo(i)) != null; i++) { if (info.IsEnabled && info.IsLoopback) { AudioDevice d = new AudioDevice(info.name, i); devices.Add(d); windowInst.devicesCombo.Items.Add(string.Format("{0} (ID: {1})", d.m_deviceName, d.m_deviceID)); } } windowInst.devicesCombo.SelectedIndex = 0; Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, false); result = Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); if (!result) { throw new Exception("Init error!"); } }
private void InitDevices() { List <string> toAdd = new List <string>(); for (int i = 0; i < BassWasapi.BASS_WASAPI_GetDeviceCount(); i++) { var device = BassWasapi.BASS_WASAPI_GetDeviceInfo(i); if (device.IsEnabled && device.IsLoopback) { toAdd.Add(string.Format("{0} - {1}", i, device.name)); } } cboDevices.Dispatcher.Invoke(() => { cboDevices.Items.Clear(); foreach (string s in toAdd) { cboDevices.Items.Add(s); } }); //cboDevices.SelectedIndex = 0; Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATETHREADS, false); if (!Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)) { MessageBox.Show("Error while initializing the sound device"); } deviceListInitialized = true; }
private void Main_Load(object sender, EventArgs e) { if (IsWinXPOrOlder()) { if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)) { Error("Can't initialize device"); return; } } else { Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_NOSPEAKER, IntPtr.Zero); BassWasapi.BASS_WASAPI_Init(-1, 0, 2, BASSWASAPIInit.BASS_WASAPI_BUFFER | BASSWASAPIInit.BASS_WASAPI_SHARED, 0, 0, null, IntPtr.Zero); BASS_WASAPI_DEVICEINFO info = new BASS_WASAPI_DEVICEINFO(); BassWasapi.BASS_WASAPI_GetDeviceInfo(BassWasapi.BASS_WASAPI_GetDevice(), info); BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); if (!Bass.BASS_Init(0, info.mixfreq, BASSInit.BASS_DEVICE_NOSPEAKER, IntPtr.Zero)) { Error("Can't initialize device"); return; } } GetInfoFromStream.RunWorkerAsync(); KSIntegration.RunWorkerAsync(); VoiceBar.Value = 100; VoiceBar.ContextMenu = VoiceUnlock; Position.ContextMenu = ShowTime; Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_MIDI_VOICES, 100000); }
private void DefaultWASAPIAudioOutput_Load(object sender, EventArgs e) { try { if ((int)KeppySynthConfiguratorMain.SynthSettings.GetValue("wasapiex", 0) == 1) { ExAccess.Checked = true; } DevicesList.Items.Add("Default WASAPI output device"); int selecteddeviceprev = (int)KeppySynthConfiguratorMain.SynthSettings.GetValue("defaultWdev", 0); BASS_WASAPI_DEVICEINFO info = new BASS_WASAPI_DEVICEINFO(); for (int n = 0; BassWasapi.BASS_WASAPI_GetDeviceInfo(n, info); n++) { AddLineToList(info, n, selecteddeviceprev); } try { DevicesList.SelectedIndex = selecteddeviceprev; } catch { DevicesList.SelectedIndex = 0; } DevicesList.SelectedIndexChanged += new System.EventHandler(this.DevicesList_SelectedIndexChanged); } catch (Exception ex) { MessageBox.Show("Unable to load the dialog.\nBASS is probably unable to start, or it's missing.\n\nError:\n" + ex.ToString(), "Oh no! Keppy's Synthesizer encountered an error!", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); Dispose(); } }
private decimal getData() { int ret = BassWasapi.BASS_WASAPI_GetData(this.fft, (int)BASSData.BASS_DATA_FFT2048); //get channel fft data if (ret < -1) { return(0m); } Int32 level = BassWasapi.BASS_WASAPI_GetLevel(); if (level == this.lastLevel && level != 0) { this.hanctr++; } float left = Utils.LowWord32(level); //Required, because some programs hang the output. If the output hangs for a 75ms //this piece of code re initializes the output so it doesn't make a gliched sound for long. if (this.hanctr > 3) { this.hanctr = 0; Free(); Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); this.initialized = false; this.Init(); } // convert to usable percentages decimal data = ((decimal)left / 10000 * 100); return(data); }
public bool StartDevice(int deviceIndex) { var result2 = false; var result = false; if (!_initialized) { devindex = deviceIndex; result2 = Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); if (!result2) { var error = Bass.BASS_ErrorGetCode(); //MessageBox.Show(error.ToString()); } result = BassWasapi.BASS_WASAPI_Init(devindex, 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, _process, IntPtr.Zero); if (!result) { var error = Bass.BASS_ErrorGetCode(); //MessageBox.Show(error.ToString()); } if (result && result2) { _initialized = true; var started = BassWasapi.BASS_WASAPI_Start(); timer.IsEnabled = true; } } return(result && result2); }
// initialization private void Init() { bool result = false; for (int i = 0; i < BassWasapi.BASS_WASAPI_GetDeviceCount(); i++) { var device = BassWasapi.BASS_WASAPI_GetDeviceInfo(i); if (device.IsEnabled && device.IsLoopback) { _devicelist.Items.Add(string.Format("{0} - {1}", i, device.name)); } } foreach (var entry in visualizers) { _visBoz.Items.Add(entry); } _visBoz.SelectedIndex = _visBoz.Items.Count - 1; Visuualizer = visualizers[_visBoz.SelectedIndex]; _devicelist.SelectedIndex = 0; Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATETHREADS, false); result = Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); if (!result) { throw new Exception("Init Error"); } }
private void FillWASAPIDeviceList() { _WASAPIDevices.Clear(); BassPlayerSettings settings = Controller.GetSettings(); BASS_WASAPI_DEVICEINFO[] deviceDescriptions = BassWasapi.BASS_WASAPI_GetDeviceInfos(); for (int i = 0; i < deviceDescriptions.Length; i++) { // Skip input devices, they have same name as output devices. BASS_WASAPI_DEVICEINFO deviceInfo = deviceDescriptions[i]; bool skip = !WASAPIOutputDevice.IsValidDevice(deviceInfo); ServiceRegistration.Get <ILogger>().Debug("{5} WASAPI Device {0}: '{1}' Flags: {2} Device path: [{3}] Ch: {4}", i, deviceInfo.name, deviceInfo.flags, deviceInfo.id, deviceInfo.mixchans, skip ? "Skip" : "Use "); if (skip) { continue; } ListItem deviceItem = new ListItem(Consts.KEY_NAME, deviceInfo.name) { Selected = deviceInfo.name == settings.WASAPIDevice }; deviceItem.SelectedProperty.Attach(delegate { var selected = _WASAPIDevices.FirstOrDefault(d => d.Selected); WASAPIDevice = selected != null ? selected.Labels[Consts.KEY_NAME].ToString() : string.Empty; }); deviceItem.SetLabel(KEY_GROUP, "WASAPI"); _WASAPIDevices.Add(deviceItem); } _WASAPIDevices.FireChange(); }
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); } }
static void Main(string[] args) { BassNet.Registration("*****@*****.**", "2X1837515183722"); BassNet.OmitCheckVersion = true; if (!Bass.LoadMe()) { System.Windows.Forms.MessageBox.Show("Unable to load bass.dll!", "Error", System.Windows.Forms.MessageBoxButtons.OK); return; } if (!Bass.BASS_Init(0, 48000, 0, IntPtr.Zero)) { System.Windows.Forms.MessageBox.Show("Unable to initialize the BASS library!", "Error", System.Windows.Forms.MessageBoxButtons.OK); } if (!BassWasapi.LoadMe()) { System.Windows.Forms.MessageBox.Show("Unable to load BassWasapi.dll!", "Error", System.Windows.Forms.MessageBoxButtons.OK); } Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); mainForm mainForm = new mainForm(); Application.Run(mainForm); }
public bool Enable(int deviceIndex) { if (!_enabled) { if (!_initialized) { bool result = BassWasapi.BASS_WASAPI_Init(deviceIndex, 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, _process, IntPtr.Zero); if (!result) { var error = Bass.BASS_ErrorGetCode(); Console.WriteLine(error.ToString()); return(false); } else { _initialized = true; } } BassWasapi.BASS_WASAPI_Start(); } else { return(false); } System.Threading.Thread.Sleep(500); _t.IsEnabled = true; return(true); }
public int _getLevel() { int value = (Utils.LowWord32(BassWasapi.BASS_WASAPI_GetLevel())); //to get a value between 0 and 100 value = (value * 100) / 32768; return(value); }