Пример #1
0
        // initialization
        private void Init()
        {
            settings = new SettingGroup("Audio Spectrum Settings", "");

            selectedDevice = new Setting("Selected Device", "", SettingControl.Dropdown, SettingType.Text, "");
            selectedDevice.configuration["options"] = new List <string>();
            settings.settings.Add(selectedDevice);

            channelCount = new Setting("Channels", "", SettingControl.Numeric, SettingType.Integer, 8);
            channelCount.configuration["interval"] = 1;
            settings.settings.Add(channelCount);

            bool result = false;

            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");
            }

            for (int i = 0; i < BassWasapi.BASS_WASAPI_GetDeviceCount(); i++)
            {
                var device = BassWasapi.BASS_WASAPI_GetDeviceInfo(i);
                if (device.IsEnabled && device.IsLoopback)
                {
                    //AudioSpectrumDevice audioDevice = new AudioSpectrumDevice(device,i);
                    //this.Devices.Add(audioDevice);
                    selectedDevice.configuration["options"].Add(string.Format("{0} - {1}", i, device.name));
                }
                //Console.WriteLine(string.Format("{0} - {1}", i, device.name));
            }
            settings.loadSettings();
            if (!string.IsNullOrWhiteSpace(selectedDevice.settingValue))
            {
                var str      = (selectedDevice.settingValue as string);
                var array    = str.Split(' ');
                int devindex = Convert.ToInt32(array[0]);

                var myDevice = BassWasapi.BASS_WASAPI_GetDeviceInfo(devindex);
                AudioSpectrumDevice audioDevice = new AudioSpectrumDevice(myDevice, devindex, (int)Math.Floor((double)channelCount.settingValue));
                this.Devices.Add(audioDevice);
            }
            selectedDevice.PropertyChanged += SelectedDevice_PropertyChanged;
        }
Пример #2
0
        private void SelectedDevice_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(selectedDevice.settingValue))
            {
                foreach (Device dev in Devices)
                {
                    dev.Dispose();
                    //Devices.Remove(dev);
                }
                //this.Devices.Clear();
                var str      = (selectedDevice.settingValue as string);
                var array    = str.Split(' ');
                int devindex = Convert.ToInt32(array[0]);

                var myDevice = BassWasapi.BASS_WASAPI_GetDeviceInfo(devindex);
                AudioSpectrumDevice audioDevice = new AudioSpectrumDevice(myDevice, devindex, (int)Math.Floor((double)channelCount.settingValue));
                this.Devices.Add(audioDevice);
            }
        }