public void ChannelSetDevice(byte device, string _name) { try { // if you want to change the output of the first stream to the second output // you might call this (even during playback) bool rez = Bass.BASS_ChannelSetDevice(_Stream, device); int dev = Bass.BASS_GetDevice(); int num = Bass.BASS_GetDeviceCount(); BASS_DEVICEINFO info = new BASS_DEVICEINFO(); info.name = string.Empty; info.driver = string.Empty; info.flags = 0; Bass.BASS_GetDeviceInfo(num, info); if (!rez) { System.Windows.MessageBox.Show( "Ошибка устройства вывода " + device.ToString() + "\nИмя " + _name + "/" + info.name + "\ndriver= " + info.driver + "\nflags= " + info.flags + "\nТекущее " + dev.ToString() + "\nВсего устр. " + num.ToString() ); } } catch (Exception ex) { System.Windows.MessageBox.Show("ошибка " + ex.Message); } }
/// <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> private 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_DEVICEINFO bassDeviceInfo = Bass.BASS_GetDeviceInfo(deviceNo); if (bassDeviceInfo == null) { throw new BassLibraryException("BASS_GetDeviceInfo"); } BASS_INFO bassInfo = Bass.BASS_GetInfo(); if (bassInfo == null) { throw new BassLibraryException("BASS_GetInfo"); } DeviceInfo deviceInfo = new DeviceInfo { Name = bassDeviceInfo.name, Driver = bassDeviceInfo.driver, Channels = bassInfo.speakers, MinRate = bassInfo.minrate, MaxRate = bassInfo.maxrate, Latency = TimeSpan.FromMilliseconds(bassInfo.latency) }; lock (_deviceInfos) _deviceInfos.Add(deviceNo, deviceInfo); } Log.Debug("DirectSound device info: {0}", _deviceInfos[_deviceNo].ToString()); }
private BassEngine(BASS_DEVICEINFO deviceInfo = null) { this.PlayCommand = new DelegateCommand(() => { if (!IsPlaying) { Play(); } }, () => this.CanPlay); this.PauseCommand = new DelegateCommand(() => { if (IsPlaying) { Pause(); } }, () => this.CanPause); this.StopCommand = new DelegateCommand(() => Stop(), () => CanStop); Initialize(deviceInfo); endTrackSyncProc = (handle, channel, data, user) => { OnTrackEnded(); }; }
/// <summary> /// 显式初始化 /// </summary> public static void ExplicitInitialize(BASS_DEVICEINFO deviceInfo = null) { if (_instance == null) { _instance = new BassEngine(deviceInfo); } }
public static bool Init() { #region dumb obfuscation for email and registration key, just to prevent bots. byte obfu = 0xDA; byte[] eml = new byte[] { 0xBE, 0xBB, 0xB4, 0xBF, 0x9A, 0xA2, 0xBB, 0xA3, 0xA8, 0xF4, 0xBD, 0xBB, }; byte[] rkey = new byte[] { 0xE8, 0x82, 0xE3, 0xE9, 0xE8, 0xE9, 0xEB, 0xE8, 0xEE, 0xE9, 0xE9, }; for (int i = 0; i < eml.Length; i++) { eml[i] ^= (obfu); } for (int i = 0; i < rkey.Length; i++) { rkey[i] ^= (obfu); } #endregion Un4seen.Bass.BassNet.Registration(Encoding.ASCII.GetString(eml), Encoding.ASCII.GetString(rkey)); Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); // Initialize audio engine BassFx.LoadMe(); BASS_DEVICEINFO info = new BASS_DEVICEINFO(); // Print device info. for (int n = 0; Bass.BASS_GetDeviceInfo(n, info); n++) { //Console.WriteLine(info.ToString()); } globalLoopProc = new SYNCPROC(DoLoop); return(true); }
//void init_device() //{ // // init the two output devices // Bass.BASS_Init(1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); // Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); // // set the device context to the first device // Bass.BASS_SetDevice(1); // // create a first stream in this context // //int stream1 = Bass.BASS_StreamCreateFile("test1.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT); // //Bass.BASS_ChannelPlay(stream1, false); // // set the device context to the second device // Bass.BASS_SetDevice(2); // // create a second stream using this context // //int stream2 = Bass.BASS_StreamCreateFile("test2.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT); // //Bass.BASS_ChannelPlay(stream2, false); //} public string getNameDevice(byte num) { BASS_DEVICEINFO info = new BASS_DEVICEINFO(); info.name = string.Empty; Bass.BASS_GetDeviceInfo(num, info); return(info.name); }
/// <summary> /// Get all avialable sound devices /// </summary> /// <param name="comboBox">Fill specified combobox</param> /// <returns></returns> public static void GetAllDevices(ComboBox comboBox) { BASS_DEVICEINFO info = new BASS_DEVICEINFO(); comboBox.Items.Clear(); for (int n = 0; Bass.BASS_GetDeviceInfo(n, info); n++) { comboBox.Items.Add(info.ToString()); } }
/// <summary> /// Retrieves information on a recording device /// </summary> /// <param name="device">The device to get the information of... 0 = first.</param> /// <param name="info">Pointer to a structure to receive the information. </param> /// <returns>returned BASS_DEVICEINFO.</returns> public static BASS_DEVICEINFO RecordGetDeviceInfo(int device) { BASS_DEVICEINFO info = new BASS_DEVICEINFO(device); if (NativeMethods.BASS_RecordGetDeviceInfo(device, ref info._internal)) { return(info); } throw new WavException(BassErrorCode.GetErrorInfo()); }
public int indexOf(BASS_DEVICEINFO di, BASS_DEVICEINFO[] dia) { for (int i = 0; i < dia.Length; i++) { if (di == dia[i]) { return(i); } } return(0); }
private void InitialiseDeviceCombo() { int defaultDevice = Bass.BASS_GetDevice(); for (int deviceId = 1; deviceId < Bass.BASS_GetDeviceCount(); deviceId++) { BASS_DEVICEINFO device = Bass.BASS_GetDeviceInfo(deviceId); cbDevices.Items.Add(device.name); } cbDevices.SelectedIndex = defaultDevice - 1; }
public static void BassInitialize() { if (IsBassInitialized) { return; } IsBassInitialized = true; IsAsioInitialized = false; IsWasapiInitialized = false; BassNet.Registration("*****@*****.**", "2X183372334322"); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 200); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 20); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_FLOATDSP, true); BASS_DEVICEINFO info = new BASS_DEVICEINFO(); for (int n = 0; Bass.BASS_GetDeviceInfo(n, info); n++) { // Console.WriteLine(info.ToString()); if (info.IsEnabled && info.IsDefault) { Console.WriteLine(info.ToString()); m_defaultdevicelongname = info.name; Bass.BASS_SetDevice(n); m_defaultdevice = n; } if (!Bass.BASS_Init(n, 44100, BASSInit.BASS_DEVICE_DEFAULT, PlayerControl.MainFormControl.Handle)) { var error = Bass.BASS_ErrorGetCode(); MessageBox.Show(error.ToString(), "Bass_Init error!"); // return; } } // already create a mixer //m_mixerChannel = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_SAMPLE_FLOAT); m_mixerChannel = MixerStreamCreate(44100); if (m_mixerChannel == 0) { var error = Bass.BASS_ErrorGetCode(); MessageBox.Show(error.ToString(), "Could not create mixer!"); Bass.BASS_Free(); return; } }
/// <summary> /// 全てのデバイスのデバイス情報の配列を返す /// </summary> /// <returns>デバイス情報の配列</returns> public static BASS_DEVICEINFO[] GetDevices() { UInt32 id = 0; BASS_DEVICEINFO? info = new BASS_DEVICEINFO(); List <BASS_DEVICEINFO> list = new List <BASS_DEVICEINFO>(); while ((info = GetDeviceInfo(id)) != null) { list.Add(info.Value); id++; } return(list.ToArray()); }
public int GetDevicesFromString(string devicename) { int i_deviceCount = Bass.BASS_GetDeviceCount(); for (int i = 0; i < i_deviceCount; i++) { BASS_DEVICEINFO bsinfo = Bass.BASS_GetDeviceInfo(i); if (bsinfo.name.Contains(devicename)) { return(i); } } return(-100); }
/// <summary> /// 查找设备的序号 /// </summary> /// <param name="device">要查找的设备</param> /// <param name="returnDefault">当找不到设备时,是否返回默认设备的序号</param> /// <returns></returns> private static int FindDevice(BASS_DEVICEINFO device, bool returnDefault = false) { if (device != null) { int deviceNO = -1; var devices = Bass.BASS_GetDeviceInfos(); var filteredDevices = from d in devices where d.name == device.name select Array.IndexOf(devices, d); if (deviceNO == -1) { if (filteredDevices.Count() == 1) { deviceNO = filteredDevices.First(); } } if (deviceNO == -1) { filteredDevices = from d in devices where d.driver == device.driver select Array.IndexOf(devices, d); if (filteredDevices.Count() == 1) { deviceNO = filteredDevices.First(); } } if (deviceNO == -1 && returnDefault) { return(deviceNO); } else if (deviceNO != -1) { return(deviceNO); } else { throw new Exception("找不到此设备:" + device.name); } } else { return(FindDefaultDevice()); } }
/// <summary> /// 获取可用的录音设备信息列表 /// </summary> /// <param name="maxDeviceIndex">可能的最大设备索引,默认为5</param> /// <returns>可用的录音设备信息列表</returns> public static List <BASS_DEVICEINFO> GetAvailableDeviceInfoList(uint maxDeviceIndex = 5) { //The device to get the information of... 0 = first. List <BASS_DEVICEINFO> availableDeviceInfoList = new List <BASS_DEVICEINFO>(); for (int device = 0; device < maxDeviceIndex; device++) { BASS_DEVICEINFO info = new BASS_DEVICEINFO(device); if (NativeMethods.BASS_RecordGetDeviceInfo(device, ref info._internal)) { availableDeviceInfoList.Add(info); } } return(availableDeviceInfoList); }
public DeviceButton(int DeviceID) : base() { this.DeviceID = DeviceID; this.info = Bass.BASS_GetDeviceInfo(DeviceID); this.Text = $"[{DeviceID}] {info.name}"; buttons.Add(this); // events Click += (object obj, EventArgs args) => { g.vars.DeviceID = DeviceID; ReloadDeviceButtons(); }; }
private void DefaultOutput_Load(object sender, EventArgs e) { try { if (IsIt) { Text = String.Format(Text, "WASAPI"); } else { Text = String.Format(Text, "DirectSound"); } int selecteddeviceprev = (int)OmniMIDIConfiguratorMain.SynthSettings.GetValue("AudioOutput", 0); SwitchDefaultAudio.Checked = Convert.ToBoolean(OmniMIDIConfiguratorMain.SynthSettings.GetValue("FollowDefaultAudioDevice", 0)); BASS_DEVICEINFO info = new BASS_DEVICEINFO(); DevicesList.Items.Add("Default Windows audio output"); Bass.BASS_GetDeviceInfo(selecteddeviceprev - 1, info); Bass.BASS_GetDeviceInfo(-1, info); if (selecteddeviceprev < 1) { DefOut.Text = String.Format("Def. Windows audio output: Default Windows audio output", info.ToString()); } else { DefOut.Text = String.Format("Def. Windows audio output: {0}", (info.ToString() == "") ? "No devices have been found" : info.ToString()); } for (int n = 0; Bass.BASS_GetDeviceInfo(n, info); n++) { DevicesList.Items.Add(info.ToString()); } 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.Message.ToString(), "Oh no! OmniMIDI encountered an error!", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); Dispose(); } }
private void Initialize(BASS_DEVICEINFO device = null) { positionTimer.Interval = TimeSpan.FromMilliseconds(50); positionTimer.Tick += positionTimer_Tick; IsPlaying = false; IntPtr handle = IntPtr.Zero; if (Application.Current.MainWindow != null) { handle = new WindowInteropHelper(Application.Current.MainWindow).EnsureHandle(); } //The device to use... -1 = default device, 0 = no sound, 1 = first real output device. var deviceNO = FindDevice(device, true); var init = Bass.BASS_Init(deviceNO, sampleFrequency, _initFlags, handle); if (init) { var error = Bass.BASS_ErrorGetCode(); int count = Bass.BASS_GetDeviceCount(); for (deviceNO = -1; deviceNO < count; ++deviceNO) { if (deviceNO != 0 && Un4seen.Bass.Bass.BASS_Init(deviceNO, sampleFrequency, _initFlags, handle)) { break; } } if (deviceNO == count) { throw new BassInitializationFailureException(error); } } if (device == null && deviceNO == FindDefaultDevice()) { Device = null; } else { Device = Bass.BASS_GetDeviceInfo(Bass.BASS_GetDevice()); } }
/// <summary> /// Retrieves information on a recording device /// </summary> /// <param name="device">The device to get the information of... 0 = first.</param> /// <param name="info">Pointer to a structure to receive the information. </param> /// <returns>If successful, then TRUE is returned, else FALSE is returned. Use BASS_ErrorGetCode to get the error code.</returns> public static bool RecordGetDeviceInfo(int device, BASS_DEVICEINFO info) { bool flag = NativeMethods.BASS_RecordGetDeviceInfo(device, ref info._internal); if (flag) { //int bassVer = NativeMethods.BASS_GetVersion(); //if (_configUTF8) //{ // int num; // info._name = Utils.IntPtrAsStringUtf8(info._internal.name, out num); // info.driver = Utils.IntPtrAsStringUtf8(info._internal.driver, out num); // if ((num > 0) && (bassVer > 0x2040800)) // { // try // { // //info.id = Utils.IntPtrAsStringUtf8(new IntPtr((info._internal.driver.ToPointer() + num) + 1), out num); // } // catch // { // } // } //} //else //{ // info._name = Utils.IntPtrAsStringAnsi(info._internal.name); // info.driver = Utils.IntPtrAsStringAnsi(info._internal.driver); // if (!string.IsNullOrEmpty(info.driver) && (bassVer > 0x2040800)) // { // try // { // //info.id = Utils.IntPtrAsStringAnsi(new IntPtr((info._internal.driver.ToPointer() + info.driver.Length) + 1)); // } // catch // { // } // } //} //info.flags = info._internal.flags; } return(flag); }
private void KeppySynthDefaultOutput_Load(object sender, EventArgs e) { try { int selecteddeviceprev = (int)KeppySynthConfiguratorMain.SynthSettings.GetValue("defaultdev", 0); BASS_DEVICEINFO info = new BASS_DEVICEINFO(); DevicesList.Items.Add("Default Windows audio output"); Bass.BASS_GetDeviceInfo(selecteddeviceprev - 1, info); Bass.BASS_GetDeviceInfo(-1, info); if (selecteddeviceprev < 1) { DefOut.Text = String.Format("Def. Windows audio output: Default Windows audio output", info.ToString()); } else { if (info.ToString() == "") { DefOut.Text = String.Format("Def. Windows audio output: No devices have been found", info.ToString()); } else { DefOut.Text = String.Format("Def. Windows audio output: {0}", info.ToString()); } } for (int n = 0; Bass.BASS_GetDeviceInfo(n, info); n++) { DevicesList.Items.Add(info.ToString()); } 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.Message.ToString(), "Oh no! Keppy's Synthesizer encountered an error!", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); Dispose(); } }
public void ChangeDevice(BASS_DEVICEINFO device) { var deviceNO = FindDevice(device); var oldDeviceNO = Bass.BASS_GetDevice(); if (oldDeviceNO != deviceNO) { if (!Bass.BASS_GetDeviceInfo(deviceNO).IsInitialized) { var handle = IntPtr.Zero; if (!Bass.BASS_Init(-1, sampleFrequency, BASSInit.BASS_DEVICE_SPEAKERS, handle)) { Debug.WriteLine("Bass Initialize error!"); throw new Exception(Bass.BASS_ErrorGetCode().ToString()); } } if (_activeStreamHandle != 0) { if (!Bass.BASS_ChannelSetDevice(_activeStreamHandle, deviceNO)) { throw new Exception(Un4seen.Bass.Bass.BASS_ErrorGetCode().ToString()); } } if (!Un4seen.Bass.Bass.BASS_SetDevice(oldDeviceNO)) { throw new Exception(Un4seen.Bass.Bass.BASS_ErrorGetCode().ToString()); } if (!Un4seen.Bass.Bass.BASS_Free()) { throw new Exception(Un4seen.Bass.Bass.BASS_ErrorGetCode().ToString()); } if (!Un4seen.Bass.Bass.BASS_SetDevice(deviceNO)) { throw new Exception(Un4seen.Bass.Bass.BASS_ErrorGetCode().ToString()); } } Device = device; }
public static void Init() { #region dumb obfuscation for email and registration key, just to prevent bots. byte obfu = 0xDA; byte[] eml = new byte[] { 0xBE, 0xBB, 0xB4, 0xBF, 0x9A, 0xA2, 0xBB, 0xA3, 0xA8, 0xF4, 0xBD, 0xBB, }; byte[] rkey = new byte[] { 0xE8, 0x82, 0xE3, 0xE9, 0xE8, 0xE9, 0xEB, 0xE8, 0xEE, 0xE9, 0xE9, }; for (int i = 0; i < eml.Length; i++) { eml[i] ^= (obfu); } for (int i = 0; i < rkey.Length; i++) { rkey[i] ^= (obfu); } #endregion Un4seen.Bass.BassNet.Registration(Encoding.ASCII.GetString(eml), Encoding.ASCII.GetString(rkey)); // Registration code, feel free to email me. // Note that because of this, JaiSeqX cannot be used for commercial purposes. Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); // Initialize audio engine BassFx.LoadMe(); // Load the effects library globalLoopProc = new SYNCPROC(DoLoop); // Create our loop proc to bind audio objects to, global and static so it doesn't get collected. g_FadeFreeProc = new SYNCPROC(FadeCollect); BASS_DEVICEINFO info = new BASS_DEVICEINFO(); // Print device info. for (int n = 0; Bass.BASS_GetDeviceInfo(n, info); n++) { Console.WriteLine(info.ToString()); } }
private void LoadDevices() { for (int i = 1; i < Bass.BASS_GetDeviceCount(); i++) { BASS_DEVICEINFO info = Bass.BASS_GetDeviceInfo(i); if (info.IsEnabled) { cmbDevice.Items.Add(info.name); } } if (Properties.Settings.Default.Device == -1) { if (cmbDevice.Items.Count > 0) { cmbDevice.SelectedIndex = 0; } } else { cmbDevice.SelectedIndex = Properties.Settings.Default.Device - 1; } }
private void FillDirectSoundDeviceList() { _directSoundDevices.Clear(); BassPlayerSettings settings = Controller.GetSettings(); BASS_DEVICEINFO[] deviceDescriptions = Bass.BASS_GetDeviceInfos(); for (int i = 0; i < deviceDescriptions.Length; i++) { BASS_DEVICEINFO deviceInfo = deviceDescriptions[i]; ListItem deviceItem = new ListItem(Consts.KEY_NAME, deviceInfo.name) { Selected = deviceInfo.name == settings.DirectSoundDevice }; deviceItem.SelectedProperty.Attach(delegate { var selected = DirectSoundDevices.FirstOrDefault(d => d.Selected); DirectSoundDevice = selected != null ? selected.Labels[Consts.KEY_NAME].ToString() : string.Empty; }); deviceItem.SetLabel(KEY_GROUP, "DirectSound"); _directSoundDevices.Add(deviceItem); } _directSoundDevices.FireChange(); }
public static void OpenAdvancedAudioSettings(String TabToOpen, String ErrorNoWork) { try { BASS_DEVICEINFO info = new BASS_DEVICEINFO(); String DeviceID = "0"; Bass.BASS_GetDeviceInfo(0, info); for (int n = 0; Bass.BASS_GetDeviceInfo(n, info); n++) { if (info.IsDefault == true) { DeviceID = info.driver; break; } } Process.Start( @"C:\Windows\System32\rundll32.exe", String.Format(@"C:\Windows\System32\shell32.dll,Control_RunDLL C:\Windows\System32\mmsys.cpl ms-mmsys:,{0},{1}", DeviceID, TabToOpen)); } catch { Program.ShowError(2, "Error", ErrorNoWork, null); } }
private static extern bool _BASS_GetDeviceInfo(UInt32 device, out BASS_DEVICEINFO info);
public static extern bool BASS_GetDeviceInfo(int device, BASS_DEVICEINFO dinfo);