예제 #1
0
        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();
        }
예제 #2
0
        //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 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();
        }
예제 #4
0
        private BassEngine()
        {
            //Setup Bass bullshit
            BassNet.Registration("*****@*****.**", "2X1837515183722");
            BassNet.OmitCheckVersion = true;
            Bass.LoadMe();
            Bass.BASS_Init(0, 48000, 0, IntPtr.Zero);
            BassWasapi.LoadMe();


            if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_SPEAKERS, Process.GetCurrentProcess().MainWindowHandle))
            {
                Console.WriteLine("Bass initialization error!");
            }

            #region WASAPI
            int WASAPIDeviceIndex = -100;

            var devices = BassWasapi.BASS_WASAPI_GetDeviceInfos();
            for (int i = 0; i < devices.Length; i++)
            {
                if (devices[i].IsEnabled && devices[i].SupportsRecording && devices[i].IsLoopback)
                {
                    WASAPIDeviceIndex = i;
                    break;
                }
            }
            if (WASAPIDeviceIndex != -100)
            {
                BASS_WASAPI_DEVICEINFO devInfo = devices[WASAPIDeviceIndex];

                if (devInfo.IsInitialized)
                {
                    Console.WriteLine("Deinitializing WASAPI device");
                    BassWasapi.BASS_WASAPI_Stop(true);
                    BassWasapi.BASS_WASAPI_Free();
                }

                if (!BassWasapi.BASS_WASAPI_Init(WASAPIDeviceIndex, devInfo.mixfreq, devInfo.mixchans, BASSWASAPIInit.BASS_WASAPI_AUTOFORMAT | BASSWASAPIInit.BASS_WASAPI_BUFFER, 0f, 0f, new WASAPIPROC(delegate(IntPtr buffer, int length, IntPtr user) { return(1); }), IntPtr.Zero))
                {
                    BASSError error = Bass.BASS_ErrorGetCode();
                }
                if (!BassWasapi.BASS_WASAPI_Start())
                {
                    BASSError error = Bass.BASS_ErrorGetCode();
                }

                IsPlaying = true;
            }
            else
            {
                IsPlaying = false;
            }
            #endregion WASAPI
        }
예제 #5
0
        private static int AutodetectWasapiDevice()
        {
            int deviceId = 0;

            foreach (var device in BassWasapi.BASS_WASAPI_GetDeviceInfos())
            {
                if (device.SupportsRecording && device.IsEnabled)
                {
                    return(deviceId);
                }
                deviceId++;
            }
            return(-1);
        }
예제 #6
0
        public static int GetInputDefaultDevice()
        {
            BASS_WASAPI_DEVICEINFO[] wasapiDevices = BassWasapi.BASS_WASAPI_GetDeviceInfos();
            int inputItem = 0;

            for (int i = 0; i < wasapiDevices.Length; i++)
            {
                BASS_WASAPI_DEVICEINFO info = wasapiDevices[i];

                if (info.IsInput && info.IsDefault)
                {
                    inputItem = i;
                    break;
                }
            }

            return(inputItem);
        }
예제 #7
0
        public static int GetOutputDefaultDevice()
        {
            BASS_WASAPI_DEVICEINFO[] wasapiDevices = BassWasapi.BASS_WASAPI_GetDeviceInfos();
            int outputItem = 0;

            for (int i = 0; i < wasapiDevices.Length; i++)
            {
                BASS_WASAPI_DEVICEINFO info = wasapiDevices[i];

                if (!info.IsInput && info.IsDefault)
                {
                    outputItem = i;
                    Player.DefaultDeviceLongName = info.name;
                    break;
                }
            }

            return(outputItem);
        }
예제 #8
0
        /// <summary>
        /// Gets the device number for the selected DirectSound device.
        /// </summary>
        /// <returns>Number of the device to be used for the BASS player.</returns>
        protected static int GetDeviceNo()
        {
            string deviceName = Controller.GetSettings().WASAPIDevice;
            int    deviceNo   = BassConstants.BassDefaultDevice;

            if (String.IsNullOrEmpty(deviceName) || deviceName == Controller.GetSettings().WASAPIDevice)
            {
                Log.Info("Initializing default WASAPI device");
            }
            else
            {
                bool found = false;
                BASS_WASAPI_DEVICEINFO[] deviceDescriptions = BassWasapi.BASS_WASAPI_GetDeviceInfos();
                for (int i = 0; i < deviceDescriptions.Length; i++)
                {
                    var deviceInfo = deviceDescriptions[i];

                    // Skip input devices, they have same name as output devices.
                    if (!IsValidDevice(deviceInfo))
                    {
                        continue;
                    }

                    if (deviceInfo.name == deviceName)
                    {
                        deviceNo = i;
                        found    = true;
                        break;
                    }
                }
                if (found)
                {
                    Log.Info("Initializing WASAPI device '{0}' (device no {1})", deviceName, deviceNo);
                }
                else
                {
                    Log.Warn("Specified WASAPI device '{0}' does not exist. Initializing default WASAPI device", deviceName);
                }
            }
            return(deviceNo);
        }
예제 #9
0
        private void CaptureDefaultDevice()
        {
            _process = new WASAPIPROC(Process);
            var defaultDevice = BassWasapi.BASS_WASAPI_GetDeviceInfos().FirstOrDefault(d => d.IsDefault && !d.IsInput);
            var devices       = BassWasapi.BASS_WASAPI_GetDeviceInfos(); // MUST be compiled as x86 since basswasapi.dll is ancient

            DefaultAudioDevice = devices.FirstOrDefault(d => d.IsEnabled && d.IsLoopback && d.name == defaultDevice?.name);
            if (DefaultAudioDevice == null)
            {
                return;
            }

            Un4seen.Bass.Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATETHREADS, false);
            Un4seen.Bass.Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);

            var deviceIndex = Array.FindIndex(devices, d => d == DefaultAudioDevice);

            BassWasapi.BASS_WASAPI_Init(deviceIndex, 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, _process, IntPtr.Zero);
            BassWasapi.BASS_WASAPI_Start();
            _updateSpectrumDispatcherTimer.Start();
        }
예제 #10
0
        private List <AudioDevice> InitAudiodeviceList()
        {
            List <AudioDevice> devices = new List <AudioDevice>();

            devices.Add(new AudioDevice()
            {
                DeviceId = -1, Name = "Autodetect"
            });
            int devicecount = 0;

            if (HasWasapi)
            {
                foreach (var bassdevice in BassWasapi.BASS_WASAPI_GetDeviceInfos())
                {
                    if (bassdevice.IsEnabled && bassdevice.IsInput)
                    {
                        devices.Add(new AudioDevice()
                        {
                            DeviceId = devicecount, Name = bassdevice.name + ((bassdevice.IsLoopback) ? " (Loopback)" : "")
                        });
                    }
                    devicecount++;
                }
            }
            else
            {
                foreach (var bassdevice in Bass.BASS_RecordGetDeviceInfos())
                {
                    if (bassdevice.IsEnabled)
                    {
                        devices.Add(new AudioDevice()
                        {
                            DeviceId = devicecount, Name = bassdevice.name
                        });
                    }
                    devicecount++;
                }
            }
            return(devices);
        }
예제 #11
0
        public static List <Tuple <string, int> > GetBassDevices()
        {
            List <Tuple <string, int> > deviceList = new List <Tuple <string, int> >();

            BASS_WASAPI_DEVICEINFO[] devices = BassWasapi.BASS_WASAPI_GetDeviceInfos();
            for (int i = 0; i < devices.Length; i++)
            {
                BASS_WASAPI_DEVICEINFO device = devices[i];
                if (!device.IsEnabled || !device.SupportsRecording)
                {
                    continue;
                }

                string deviceName = device.name;
                if (device.IsLoopback)
                {
                    deviceName += " (Loopback)";
                }

                deviceList.Add(new Tuple <string, int>(deviceName, i));
            }

            return(deviceList);
        }
예제 #12
0
        /// <summary>
        /// Get some information for the selected sound device
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void soundDeviceComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            int sounddevice = -1;

            BASS_DEVICEINFO[] soundDeviceDescriptions = Bass.BASS_GetDeviceInfos();
            for (int i = 0; i < soundDeviceDescriptions.Length; i++)
            {
                if (soundDeviceDescriptions[i].name == soundDeviceComboBox.Text)
                {
                    sounddevice = i;
                    break;
                }
            }

            // Run the following code in a Thread to avoid delays, when entering the Music screen
            new System.Threading.Thread(() =>
            {
                // Find out the minimum Buffer length possible
                Bass.BASS_Free();
                if (Bass.BASS_Init(sounddevice, 48000, BASSInit.BASS_DEVICE_LATENCY, IntPtr.Zero, Guid.Empty))
                {
                    BASS_INFO info = Bass.BASS_GetInfo();
                    if (info != null)
                    {
                        int currentBuffer = trackBarBuffering.Value;
                        if (currentBuffer < info.minbuf)
                        {
                            trackBarBuffering.Value = info.minbuf;
                        }
                        trackBarBuffering.Minimum = info.minbuf;
                    }
                }

                // Detect WASAPI Speaker Setup
                if (audioPlayerComboBox.SelectedIndex == 2)
                {
                    Bass.BASS_Free();
                    Bass.BASS_Init(0, 48000, 0, IntPtr.Zero, Guid.Empty);       // No sound device
                    BASS_WASAPI_DEVICEINFO[] wasapiDevices = BassWasapi.BASS_WASAPI_GetDeviceInfos();

                    int i = 0;
                    // Check if the WASAPI device read is amongst the one retrieved
                    for (i = 0; i < wasapiDevices.Length; i++)
                    {
                        if (wasapiDevices[i].name == soundDeviceComboBox.Text)
                        {
                            sounddevice = i;
                            break;
                        }
                    }

                    int channels = 0;

                    // Let's assume a maximum of 8 speakers attached to the device
                    for (int c = 1; c < 9; c++)
                    {
                        BASSWASAPIFormat format = BassWasapi.BASS_WASAPI_CheckFormat(sounddevice, 44100, c,
                                                                                     BASSWASAPIInit.
                                                                                     BASS_WASAPI_SHARED);

                        if (format != BASSWASAPIFormat.BASS_WASAPI_FORMAT_UNKNOWN)
                        {
                            channels = c;
                        }
                    }
                    if (channels > WasApiSpeakersCombo.SelectedIndex + 1)
                    {
                        switch (channels)
                        {
                        case 1:
                            WasApiSpeakersCombo.SelectedIndex = 0;
                            break;

                        case 2:
                            WasApiSpeakersCombo.SelectedIndex = 1;
                            break;

                        case 4:
                            WasApiSpeakersCombo.SelectedIndex = 2;
                            break;

                        case 6:
                            WasApiSpeakersCombo.SelectedIndex = 3;
                            break;

                        case 8:
                            WasApiSpeakersCombo.SelectedIndex = 4;
                            break;
                        }
                    }
                }
                Bass.BASS_Free();
            }
                                        ).Start();
        }
예제 #13
0
        /// <summary>
        /// Get the sound devices for the selected Player
        /// </summary>
        /// <param name="player">
        /// 0 - Bass Directshow
        /// 1 - ASIO
        /// 2 - WASAPI
        /// 3 - Internal Dshow Player
        /// </param>
        private void GetAvailableSoundDevices(int player)
        {
            switch (player)
            {
            case (int)AudioPlayer.Bass:
            case (int)AudioPlayer.DShow:

                // Get all available devices and add them to the combo box
                BASS_DEVICEINFO[] soundDevices = Bass.BASS_GetDeviceInfos();

                // For Directshow player, we need to have the exact wording here
                if (audioPlayerComboBox.SelectedIndex == 1)
                {
                    soundDeviceComboBox.Items.Add(new SoundDeviceItem("Default DirectSound Device", ""));
                }
                else
                {
                    soundDeviceComboBox.Items.Add(new SoundDeviceItem("Default Sound Device", ""));
                }

                // Fill the combo box, starting at 1 to skip the "No Sound" device
                for (int i = 1; i < soundDevices.Length; i++)
                {
                    soundDeviceComboBox.Items.Add(new SoundDeviceItem(soundDevices[i].name, soundDevices[i].id));
                }

                break;

            case (int)AudioPlayer.Asio:

                // Get all available ASIO devices and add them to the combo box
                BASS_ASIO_DEVICEINFO[] asioDevices = BassAsio.BASS_ASIO_GetDeviceInfos();
                if (asioDevices.Length == 0)
                {
                    MessageBox.Show(this, "No ASIO Devices available in the system.",
                                    "MediaPortal - Setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    // Default back to BASS Player
                    audioPlayerComboBox.SelectedIndex = 0;
                }
                else
                {
                    foreach (BASS_ASIO_DEVICEINFO deviceInfo in asioDevices)
                    {
                        soundDeviceComboBox.Items.Add(new SoundDeviceItem(deviceInfo.name, deviceInfo.driver));
                    }
                }

                break;

            case (int)AudioPlayer.WasApi:
                // Get all available ASIO devices and add them to the combo box
                BASS_WASAPI_DEVICEINFO[] wasapiDevices = BassWasapi.BASS_WASAPI_GetDeviceInfos();
                if (wasapiDevices.Length == 0)
                {
                    MessageBox.Show(this, "No WASAPI Devices available in the system.",
                                    "MediaPortal - Setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    // Default back to BASS Player
                    audioPlayerComboBox.SelectedIndex = 0;
                }
                else
                {
                    foreach (BASS_WASAPI_DEVICEINFO deviceInfo in wasapiDevices)
                    {
                        // Only add enabled and output devices to the list
                        if (deviceInfo.IsEnabled && !deviceInfo.IsInput)
                        {
                            soundDeviceComboBox.Items.Add(new SoundDeviceItem(deviceInfo.name, deviceInfo.id));
                        }
                    }
                }
                if (soundDeviceComboBox.Items.Count == 0)
                {
                    // Add default sound device to avoid crash.
                    soundDeviceComboBox.Items.Add(new SoundDeviceItem("Default Sound Device", ""));
                    soundDeviceComboBox.Items[0] = new SoundDeviceItem("Default Sound Device", "");
                }
                break;
            }
        }
예제 #14
0
        private void Preferences_Load(object sender, EventArgs e)
        {
            try
            {
                PrefTabControl.SelectTab(PlayerControl.PRefsTabIndex);
                m_tooltip.SetToolTip(chkBoxRefreshAsio, "Enable this option when noise artifact is present in audio.");

                string videoDir = Main_Form.iniFileHelper.Read("Video", "Video Path");

                videoLbl.Text = videoDir == string.Empty ? "Video: Default" : "Video: " + videoDir;

                if (videoDir == string.Empty)
                {
                    videoDir = VlcPlayer.BGVideoPath + @"VIDEO_NATURE\";
                }

                PlayerControl.GetVideoBG(videoDir);

                PlayerControl.SetDefaultVideoBG(panelPlayer.Handle);

                DataTable dt = new DataTable();
                dt.Columns.Add("ID", typeof(int));
                dt.Columns.Add("Name");

                DataRow dr = dt.NewRow();

                if (Equalizer.ArrBandValue[11].PreSet == -1)
                {
                    dr["Name"] = "";
                    dr["ID"]   = 0;

                    dt.Rows.Add(dr);

                    defBandValue = Equalizer.ArrBandValue;
                }

                for (int i = 0; i < VlcPlayer.EqPresets.Values.Count(); i++)
                {
                    dr         = dt.NewRow();
                    dr["Name"] = VlcPlayer.EqPresets[i].Name;
                    dr["ID"]   = VlcPlayer.EqPresets[i].Index;

                    dt.Rows.Add(dr);
                }

                comboBoxEQPresets.DataSource    = dt;// VlcPlayer.EqPresets.Values.ToList();
                comboBoxEQPresets.DisplayMember = "Name";
                comboBoxEQPresets.DropDownStyle = ComboBoxStyle.DropDownList;

                comboBoxEQPresets.SelectedIndex = Equalizer.ArrBandValue[11].PreSet;

                SetBandGain();

                if (PlayerControl.DefaultAudioOutput == DefaultAudioOutput.Bass)
                {
                    radioBtnBass.Checked     = true;
                    asio_control_btn.Enabled = false;
                }

                if (PlayerControl.DefaultAudioOutput == DefaultAudioOutput.Wasapi)
                {
                    radioBtnWasapi.Checked   = true;
                    asio_control_btn.Enabled = false;
                }

                if (PlayerControl.DefaultAudioOutput == DefaultAudioOutput.Asio)
                {
                    radioBtnAsio.Checked     = true;
                    asio_control_btn.Enabled = true;
                }

                if (Player.IsWasapiInitialized)
                {
                    int defaulInputDevice  = 0;
                    int defaulOutputDevice = 0;
                    this.comboBoxInputDevice.Items.Clear();
                    this.comboBoxOutputDevice.Items.Clear();
                    BASS_WASAPI_DEVICEINFO[] wasapiDevices = BassWasapi.BASS_WASAPI_GetDeviceInfos();
                    for (int i = 0; i < wasapiDevices.Length; i++)
                    {
                        BASS_WASAPI_DEVICEINFO info = wasapiDevices[i];

                        if (info.IsEnabled && info.IsInput)
                        {
                            defaulInputDevice = i;
                            int index = this.comboBoxInputDevice.Items.Add(new DeviceInfo(info, defaulInputDevice)); //string.Format("{0} - {1}", i, info.name));
                            if (info.IsDefault)
                            {
                                this.comboBoxInputDevice.SelectedIndex = index;
                            }

                            //defaulInputDevice++;
                        }

                        if (info.IsEnabled && !info.IsInput)
                        {
                            defaulOutputDevice = i;
                            int index = this.comboBoxOutputDevice.Items.Add(new DeviceInfo(info, defaulOutputDevice));
                            if (info.IsDefault)
                            {
                                this.comboBoxOutputDevice.SelectedIndex = index;
                            }

                            // defaulOutputDevice++;
                        }
                    }

                    RefreshEffects();
                }

                if (Player.IsAsioInitialized)
                {
                    this.comboBoxInputDevice.Items.Clear();
                    this.comboBoxInputDevice.Items.AddRange(BassAsioDevice.GetAsioInputChannels.ToArray());
                    if (this.comboBoxInputDevice.Items.Count > 0)
                    {
                        this.comboBoxInputDevice.SelectedIndex = BassAsioDevice.inputDevice;
                    }

                    this.comboBoxOutputDevice.Items.Clear();
                    this.comboBoxOutputDevice.Items.AddRange(BassAsioDevice.AsioOutputChannels.ToArray());
                    if (this.comboBoxOutputDevice.Items.Count > 0)
                    {
                        this.comboBoxOutputDevice.SelectedIndex = BassAsioDevice.outputDevice;
                    }

                    microphone_setting.Enabled = true;

                    if (AppSettings.Get <bool>("IsAsioAutoRestart"))
                    {
                        chkBoxRefreshAsio.Checked = true;
                    }
                    else
                    {
                        chkBoxRefreshAsio.Checked = false;
                    }

                    chkBoxRefreshAsio.Enabled = true;

                    groupMicrophoneEffects.Enabled = true;

                    RefreshEffects();
                }

                if (Player.IsBassInitialized)
                {
                    this.comboBoxOutputDevice.Items.Clear();
                    this.comboBoxOutputDevice.Items.AddRange(Bass.BASS_GetDeviceInfos());

                    if (this.comboBoxOutputDevice.Items.Count > 0)
                    {
                        this.comboBoxOutputDevice.SelectedIndex = Player.DefaultDevice;
                    }

                    microphone_setting.Enabled     = false;
                    chkBoxRefreshAsio.Enabled      = false;
                    groupMicrophoneEffects.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                Logger.LogFile(ex.Message, "", "Preferences_Load", ex.LineNumber(), this.Name);
            }
        }