Пример #1
0
        public void tick(Object source, ElapsedEventArgs e)
        {
            //            if (comboboxDevices.SelectedItem != null)
            //          {
            //        var device = (MMDevice)comboboxDevices.SelectedItem;
            NAudio.CoreAudioApi.MMDeviceEnumerator devEnum       = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            NAudio.CoreAudioApi.MMDevice           defaultDevice = devEnum.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Multimedia);
            loudness        = defaultDevice.AudioMeterInformation.MasterPeakValue * 255;
            transformedData = FFT(transformedData);
            int bandWidth = transformedData.Length / 18;

            for (int i = 0; i < 18; i++)
            {
                double sum = 0;
                for (int j = 0; j < bandWidth; j++)
                {
                    sum += transformedData[j * 18 + i];
                }
                wavesScaling[i] = sum;
            }
            //string concatenated = string.Join("#", loudBandData);

            //try
            //{
            //  if (networking.client.Connected)
            //{
            //networking.SendMessage("L" + concatenated + "#");
            //}
            //}
            //catch { }
        }
Пример #2
0
        public Form1()
        {
            InitializeComponent();
            NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active);

            comboBox1.Items.AddRange(devices.ToArray());
            comboBox1.SelectedIndex = 1;


            List <string> waves = new List <string>();

            waves.Add("Sin");
            waves.Add("Triangle");
            waves.Add("Square");
            waves.Add("SawTooth");
            waves.Add("PinkNoise");
            waves.Add("WhiteNoise");
            waves.Add("Sweep");
            cb_waves.DataSource  = waves;
            vsb_volumeL.Value    = 50;
            lb_volumeL.Text      = "50";
            lb_volumeR.Text      = "50";
            lb_volumeM.Text      = "50";
            btn_stop.Enabled     = false;
            btn_pause.Enabled    = false;
            trb_progress.Enabled = false;
            vsb_volumeL.Enabled  = false;
            vsb_volumeR.Enabled  = false;
            vsb_volumeM.Enabled  = false;
            cb_controle.Enabled  = false;
        }
Пример #3
0
        public IDeviceManualTriggerContext ManualTrigger(DeviceManualTriggerContextOption Option = null)
        {
            if (Option != null)
            {
                DeviceAddedEventHandler threadSafeEventHandler = DeviceAdded;
                SixtyBeatAudioDevice    device = SixtyBeatAudioDevice.Create(Option.Tag as string);
                if (device != null)
                {
                    threadSafeEventHandler?.Invoke(this, device);
                }
                return(null);
            }

            SixtyBeatAudioDeviceManualTriggerContext ResponseData = new SixtyBeatAudioDeviceManualTriggerContext();

            ResponseData.Options = new List <DeviceManualTriggerContextOption>();

            var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();

            //cycle through all audio devices
            for (int i = 0; i < WaveIn.DeviceCount; i++)
            {
                // these happen to enumate the same order
                NAudio.CoreAudioApi.MMDevice dev = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Capture, NAudio.CoreAudioApi.DeviceState.Active)[i];

                string DeviceID = dev.Properties[new NAudio.CoreAudioApi.PropertyKey(DevPKey.Native.PnpDevicePropertyAPINative.DEVPKEY_Audio_InstanceId.fmtid, (int)DevPKey.Native.PnpDevicePropertyAPINative.DEVPKEY_Audio_InstanceId.pid)].Value.ToString();
                if (!SixtyBeatAudioDevice.DeviceKnown(DeviceID))
                {
                    ResponseData.Options.Add(new DeviceManualTriggerContextOption(dev.FriendlyName, DeviceID));
                }
            }
            enumerator.Dispose();

            return(ResponseData);
        }
Пример #4
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            var deviceEnum = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var devices    = deviceEnum.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active).ToList();

            return(new StandardValuesCollection(devices));
        }
Пример #5
0
        public static void MuteChannel(int channelIndex, bool isMute, int delayMilliseconds = 0)
        {
            new Thread(() =>
            {
                if (delayMilliseconds > 0)
                {
                    Thread.Sleep(delayMilliseconds);
                }

                NAudio.CoreAudioApi.MMDeviceEnumerator mmde = new NAudio.CoreAudioApi.MMDeviceEnumerator();

                NAudio.CoreAudioApi.MMDeviceCollection devCol = mmde.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);

                foreach (NAudio.CoreAudioApi.MMDevice dev in devCol)
                {
                    try
                    {
                        if (dev.State == NAudio.CoreAudioApi.DeviceState.Active)
                        {
                            dev.AudioSessionManager.Sessions[dev.AudioSessionManager.Sessions.Count - channelIndex - 1].SimpleAudioVolume.Mute = isMute;
                        }
                    }
                    catch { /* ignored */ }
                }
            }).Start();
        }
Пример #6
0
        private void LoadDevices()
        {
            NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();

            foreach (NAudio.CoreAudioApi.MMDevice device in enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active))
            {
                string Key = device.ID + device.FriendlyName;
                if (this.UserData.Devices.ContainsKey(Key))
                {
                    this.UserData.Devices[Key].CurrentDevice      = device;
                    this.UserData.Devices[Key].DeviceFriendlyName = device.FriendlyName;
                }
                else
                {
                    SaveFile.Device NewDevice = new SaveFile.Device
                    {
                        DeviceID           = device.ID,
                        CurrentDevice      = device,
                        DeviceFriendlyName = device.FriendlyName
                    };
                    this.UserData.Devices.Add(Key, NewDevice);
                }
            }
            this.UserData.Save(this.SaveFileLocation);
        }
Пример #7
0
 public static int GetVolume()
 {
     try
     {
         //Instantiate an Enumerator to find audio devices
         NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
         //Get all the devices, no matter what condition or status
         NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active);
         //Loop through all devices
         foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
         {
             try
             {
                 if (dev.State == NAudio.CoreAudioApi.DeviceState.Active)
                 {
                     float volume    = dev.AudioEndpointVolume.MasterVolumeLevelScalar;
                     int   volumeInt = (int)(volume * 100);
                     return(volumeInt);
                 }
             }
             catch (Exception ex)
             {
                 //Do something with exception when an audio endpoint could not be muted
                 Debug.WriteLine(dev.FriendlyName + " could not be muted with error " + ex);
             }
         }
     }
     catch (Exception ex)
     {
         //When something happend that prevent us to iterate through the devices
         Debug.WriteLine("Could not enumerate devices due to an excepion: " + ex.Message);
     }
     return(-1);
 }
 public static int GetVolume()
 {
     try
     {
         //Instantiate an Enumerator to find audio devices
         NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
         //Get all the devices, no matter what condition or status
         NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active);
         //Loop through all devices
         foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
         {
             try
             {
                 if (dev.State == NAudio.CoreAudioApi.DeviceState.Active)
                 {
                     float volume = dev.AudioEndpointVolume.MasterVolumeLevelScalar;
                     int volumeInt = (int)(volume * 100);
                     return volumeInt;
                 }
             }
             catch (Exception ex)
             {
                 //Do something with exception when an audio endpoint could not be muted
                 Debug.WriteLine(dev.FriendlyName + " could not be muted with error " + ex);
             }
         }
     }
     catch (Exception ex)
     {
         //When something happend that prevent us to iterate through the devices
         Debug.WriteLine("Could not enumerate devices due to an excepion: " + ex.Message);
     }
     return -1;
 }
Пример #9
0
        private void wASAPIToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();

            lbInputDevice.Items.Clear();
            int i = 0;

            foreach (var wasapi in enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Capture, NAudio.CoreAudioApi.DeviceState.Active))
            {
                lbInputDevice.Items.Add(wasapi.DataFlow + @" "
                                        + wasapi.FriendlyName + @" "
                                        + wasapi.DeviceFriendlyName + @" "
                                        + wasapi.State + @"?"
                                        + wasapi.ID);
                i += 1;
            }
            // Output device set
            //var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            lbOutputDevice.Items.Clear();
            i = 0;
            foreach (var wasapi in enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active))
            {
                lbOutputDevice.Items.Add(wasapi.DataFlow + @" "
                                         + wasapi.FriendlyName + @" "
                                         + wasapi.DeviceFriendlyName + @" "
                                         + wasapi.State + @"?"
                                         + wasapi.ID);
                i += 1;
            }
        }
Пример #10
0
        public AudioControllerPluginConfigViewModel(PluginSystem.IPlugin Plugin, PluginSystem.PluginConfig PluginConfig)
            : base(Plugin, PluginConfig)
        {
            Uri uri = new Uri("pack://application:,,,/LauncherSilo.AudioControllerPlugin;component/AudioControllerPluginResource.xaml");
            StreamResourceInfo info   = Application.GetResourceStream(uri);
            XamlReader         reader = new XamlReader();
            var dictionary            = reader.LoadAsync(info.Stream) as ResourceDictionary;

            PluginConfigControlTemplate = dictionary["AudioControllerPluginConfigView"] as ControlTemplate;

            NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            NAudio.CoreAudioApi.MMDeviceCollection endPoints  = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
            foreach (NAudio.CoreAudioApi.MMDevice endPoint in endPoints)
            {
                if (endPoint.State == NAudio.CoreAudioApi.DeviceState.NotPresent)
                {
                    continue;
                }
                if (endPoint.DataFlow == NAudio.CoreAudioApi.DataFlow.Render)
                {
                    AudioPlaybackDeviceVM.Add(new AudioDeviceViewModel(endPoint));
                }
                else if (endPoint.DataFlow == NAudio.CoreAudioApi.DataFlow.Capture)
                {
                    AudioCaptureDeviceVM.Add(new AudioDeviceViewModel(endPoint));
                }
            }
        }
Пример #11
0
 private void muteOff()
 {
     try
     {
         //Instantiate an Enumerator to find audio devices
         NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
         //Get all the devices, no matter what condition or status
         NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
         //Loop through all devices
         foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
         {
             try
             {
                 //Show us the human understandable name of the device
                 System.Diagnostics.Debug.Print(dev.FriendlyName);
                 //Mute it
                 dev.AudioEndpointVolume.Mute = false;
             }
             catch (Exception ex)
             {
                 //Do something with exception when an audio endpoint could not be muted
             }
         }
     }
     catch (Exception ex)
     {
         //When something happend that prevent us to iterate through the devices
     }
 }
Пример #12
0
        /// <summary>
        /// Enumerate this instance.
        /// </summary>
        /// <returns>Enumeration of audio input devices as GUID/FriendlyName string pair.</returns>
        public List <MicDevice> enumerate()
        {
            if (Taskmaster.Trace)
            {
                Log.Verbose("<Microphone> Enumerating devices...");
            }

            var devices = new List <MicDevice>();
            var mm_enum = new NAudio.CoreAudioApi.MMDeviceEnumerator();

            if (mm_enum != null)
            {
                var devs = mm_enum.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Capture, NAudio.CoreAudioApi.DeviceState.Active);
                foreach (var dev in devs)
                {
                    var mdev = new MicDevice {
                        Name = dev.DeviceFriendlyName, GUID = dev.ID.Split('}')[1].Substring(2)
                    };
                    devices.Add(mdev);
                    if (Taskmaster.Trace)
                    {
                        Log.Verbose("<Microphone> Device: {Microphone} [GUID: {GUID}]", mdev.Name, mdev.GUID);
                    }
                }
            }

            if (Taskmaster.Trace)
            {
                Log.Verbose("<Microphone> {DeviceCount} microphone(s)", devices.Count);
            }

            return(devices);
        }
Пример #13
0
        /// <exception cref="InitFailure">If audio device can not be found.</exception>
        public AudioManager()
        {
            Context = System.Threading.Thread.CurrentThread;

            var mm_enum = new NAudio.CoreAudioApi.MMDeviceEnumerator();

            mmdev_media = mm_enum?.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Multimedia);
            if (mmdev_media == null)
            {
                throw new InitFailure("Failed to capture default audio output device.");
            }

            Serilog.Log.Information("<Audio> Defalt device: {Device}", mmdev_media.DeviceFriendlyName);

            mmdev_media.AudioSessionManager.OnSessionCreated += OnSessionCreated;

            /*
             * var cfg = Taskmaster.Config.Load(configfile);
             *
             * foreach (var section in cfg)
             * {
             *
             * }
             */
        }
Пример #14
0
        public SixtyBeatAudioDevice(string deviceId)
        {
            var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            //cycle through all audio devices
            int audioDeviceNumber = -1;

            for (int i = 0; i < WaveIn.DeviceCount; i++)
            {
                // these happen to enumate the same order
                NAudio.CoreAudioApi.MMDevice dev = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Capture, NAudio.CoreAudioApi.DeviceState.Active)[i];
                //Guid scratch = (Guid)(dev.Properties[new NAudio.CoreAudioApi.PropertyKey(DevPKey.Native.PnpDevicePropertyAPINative.DEVPKEY_Device_ContainerId.fmtid, (int)DevPKey.Native.PnpDevicePropertyAPINative.DEVPKEY_Device_ContainerId.pid)].Value);
                //blder.AppendLine($"{i}\t{scratch}\t{dev}");

                string ItemDeviceID = dev.Properties[new NAudio.CoreAudioApi.PropertyKey(DevPKey.Native.PnpDevicePropertyAPINative.DEVPKEY_Audio_InstanceId.fmtid, (int)DevPKey.Native.PnpDevicePropertyAPINative.DEVPKEY_Audio_InstanceId.pid)].Value.ToString();
                //Dictionary<DevPKey.Native.PnpDevicePropertyAPINative.DEVPROPKEY, string> properties = DevPKey.PnpDevicePropertyAPI.GetDeviceProperties(DeviceID);
                if (ItemDeviceID == deviceId)
                {
                    audioDeviceNumber = i;
                    this.DeviceID     = ItemDeviceID;
                    break;
                }
            }

            Properties = new Dictionary <string, dynamic>();

            previousValues    = new RingBuffer <Int16>(BUFFER);
            previousAbsValues = new RingBuffer <Int16>(BUFFER);

            wi = new WaveInEvent();
            wi.DeviceNumber       = audioDeviceNumber;
            wi.WaveFormat         = new NAudio.Wave.WaveFormat(RATE, 1);
            wi.BufferMilliseconds = (int)((double)BUFFERSIZE / (double)RATE * 1000.0);
            wi.DataAvailable     += new EventHandler <WaveInEventArgs>(AudioDataAvailable);
        }
Пример #15
0
        public AudioDeltaTest()
        {
            InitializeComponent();

            NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active);

            comboBox1.Items.AddRange(devices.ToArray());

            RMeter.Show();
            LMeter.Show();
            RMeter.TopMost = true;
            LMeter.TopMost = true;

            LMeter.MinimumSize = new Size(50, 50);
            RMeter.MinimumSize = new Size(50, 50);

            LMeter.Opacity = (double)((numericUpDown1.Value / 100));
            RMeter.Opacity = (double)((numericUpDown1.Value / 100));

            barColor   = Color.Blue;
            barBGColor = Color.Transparent;

            LMeter.progressBarLeft.BarColorSolid  = Color.Blue;
            RMeter.progressBarRight.BarColorSolid = Color.Blue;

            redBarTime.Start();
            redBarTimeR.Start();
        }
Пример #16
0
        public Form1()
        {
            InitializeComponent();
            NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active);

            comboBox1.Items.AddRange(devices.ToArray());
        }
Пример #17
0
        public static void SwitchMute()
        {
            NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            //Get all the devices, no matter what condition or status
            NAudio.CoreAudioApi.MMDevice dev = MMDE.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Communications);

            dev.AudioEndpointVolume.Mute = !dev.AudioEndpointVolume.Mute;
        }
Пример #18
0
        public static void VolumeUp(int parUpPercent)
        {
            NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            //Get all the devices, no matter what condition or status
            NAudio.CoreAudioApi.MMDevice dev = MMDE.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Communications);

            dev.AudioEndpointVolume.VolumeStepUp();
        }
Пример #19
0
        public Array GetSourcesArray()
        {
            NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();

            var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Capture, DeviceState.Active);

            return(devices.ToArray());
        }
Пример #20
0
        /// <summary>
        /// 系统静音/取消系统静音
        /// </summary>
        public static void SethMute()
        {
            NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            //Get all the devices, no matter what condition or status
            NAudio.CoreAudioApi.MMDevice dev = MMDE.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Communications);

            dev.AudioEndpointVolume.Mute = !dev.AudioEndpointVolume.Mute;
        }
Пример #21
0
        private void InitializeNAudio()
        {
            // Get all Audio devices in the system
            DeviceList = new List <NAudio.CoreAudioApi.MMDevice>();
            NAudio.CoreAudioApi.MMDeviceEnumerator enumerator =
                new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All,
                                                             NAudio.CoreAudioApi.DeviceState.Active);

            DeviceList.AddRange(devices.ToArray());
        }
Пример #22
0
        public Form1()
        {
            InitializeComponent();

            NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active);

            NAudio.CoreAudioApi.MMDeviceEnumerator devEnum       = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            NAudio.CoreAudioApi.MMDevice           defaultDevice = devEnum.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Multimedia);
            comboBox1.Items.AddRange(devices.ToArray());
            CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice;
        }
        public Form1()
        {
            InitializeComponent();
            //Listing audio devices in comboBox1
            NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active);

            comboBox1.Items.AddRange(devices.ToArray());
            globalVariable.oldPeak = 0;
            //Trying to open a serial port. Program won't fail if Arduino is not connected.
            try { serialPort1.Open(); }
            catch { }
        }
Пример #24
0
        public override void Init()
        {
            NAudio.CoreAudioApi.MMDeviceEnumerator a = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var dev = a.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Multimedia);
            o = new WasapiOut(dev,NAudio.CoreAudioApi.AudioClientShareMode.Shared,false, 50);

            //o = new WaveOut();
            bwp = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(16000, 1));
            bwp.BufferDuration = TimeSpan.FromMilliseconds(2000);
            bwp.DiscardOnBufferOverflow = true;
            o.Init(bwp);
            o.Play();
            //delaypos = 0;
        }
Пример #25
0
        public override void Init()
        {
            NAudio.CoreAudioApi.MMDeviceEnumerator a = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var dev = a.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Multimedia);

            o = new WasapiOut(dev, NAudio.CoreAudioApi.AudioClientShareMode.Shared, false, 50);

            //o = new WaveOut();
            bwp = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(16000, 1));
            bwp.BufferDuration          = TimeSpan.FromMilliseconds(2000);
            bwp.DiscardOnBufferOverflow = true;
            o.Init(bwp);
            o.Play();
            //delaypos = 0;
        }
Пример #26
0
 public void SetVolumeNAudio(float volumeScalar)
 {
     try
     {
         NAudio.CoreAudioApi.MMDeviceEnumerator MMDE   = new NAudio.CoreAudioApi.MMDeviceEnumerator();
         NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active);
         foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
         {
             dev.AudioEndpointVolume.MasterVolumeLevelScalar = volumeScalar;
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Print("Excepion: " + ex.Message);
     }
 }
Пример #27
0
 public float GetVolumeNAudio()
 {
     try
     {
         NAudio.CoreAudioApi.MMDeviceEnumerator MMDE   = new NAudio.CoreAudioApi.MMDeviceEnumerator();
         NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active);
         foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
         {
             Console.WriteLine("Name of device: " + dev.FriendlyName);
             return(dev.AudioEndpointVolume.MasterVolumeLevelScalar);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Print("Excepion: " + ex.Message);
     }
     return(1.0f);
 }
Пример #28
0
 public void ChangeVolume(int level)
 {
     NAudio.CoreAudioApi.MMDeviceEnumerator MMDE   = new NAudio.CoreAudioApi.MMDeviceEnumerator();
     NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
     foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
     {
         try
         {
             if (dev.State == NAudio.CoreAudioApi.DeviceState.Active)
             {
                 var newVolume = (float)Math.Max(Math.Min(level, 100), 0) / (float)100;
                 dev.AudioEndpointVolume.MasterVolumeLevelScalar = newVolume;
                 dev.AudioEndpointVolume.Mute = level == 0;
             }
         }
         catch (Exception) {}
     }
 }
Пример #29
0
        public Form1()
        {
            InitializeComponent();
            trackBar1.ValueChanged += trackBar1_ValueChanged;
            try
            {
                //Instantiate an Enumerator to find audio devices
                NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
                //Get all the devices, no matter what condition or status
                NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
                //Loop through all devices
                foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
                {
                    try
                    {
                        dev.AudioEndpointVolume.MasterVolumeLevel = 0;
                        Trace.WriteLine("MasterVolumeLevel:" + dev.AudioEndpointVolume.StepInformation.StepCount);
                        trackBar1.Minimum = (int)dev.AudioEndpointVolume.VolumeRange.MinDecibels;
                        trackBar1.Maximum = (int)dev.AudioEndpointVolume.VolumeRange.MaxDecibels;
                        trackBar1.Scale(dev.AudioEndpointVolume.MasterVolumeLevelScalar);
                        trackBar1.Value = (int)dev.AudioEndpointVolume.MasterVolumeLevel;
                        //Set at maximum volume
                        //dev.AudioEndpointVolume.MasterVolumeLevel = 0;

                        //Get its audio volume
                        System.Diagnostics.Debug.Print("Volume of " + dev.FriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevel.ToString());

                        //Mute it
                        //dev.AudioEndpointVolume.Mute = true;
                        System.Diagnostics.Debug.Print(dev.FriendlyName + " is muted");
                    }
                    catch (Exception ex)
                    {
                        //Do something with exception when an audio endpoint could not be muted
                        System.Diagnostics.Debug.Print(dev.FriendlyName + " could not be muted");
                    }
                }
            }
            catch (Exception ex)
            {
                //When something happend that prevent us to iterate through the devices
                System.Diagnostics.Debug.Print("Could not enumerate devices due to an excepion: " + ex.Message);
            }
        }
Пример #30
0
        public static List <string> GetDeviceList()
        {
            NAudio.CoreAudioApi.MMDeviceEnumerator enu = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            var           devices = enu.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active);
            List <string> ret     = new List <string>();

            foreach (var d in devices)
            {
                try
                {
                    ret.Add(d.FriendlyName);
                }
                catch (Exception exc)
                {
                }
            }
            ret.Sort();
            return(ret);
        }
Пример #31
0
        public static void SetVolume(int level)
        {
            try
            {
                //Instantiate an Enumerator to find audio devices
                NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
                //Get all the devices, no matter what condition or status
                NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active);
                //Loop through all devices
                foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
                {
                    try
                    {
                        if (dev.State == NAudio.CoreAudioApi.DeviceState.Active)
                        {
                            var newVolume = (float)Math.Max(Math.Min(level, 100), 0) / (float)100;

                            //Set at maximum volume
                            dev.AudioEndpointVolume.MasterVolumeLevelScalar = newVolume;

                            //dev.AudioEndpointVolume.Mute = level == 0;

                            //Get its audio volume
                            Debug.WriteLine("Volume of " + dev.FriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevelScalar.ToString());
                        }
                        else
                        {
                            Debug.WriteLine("Ignoring device " + dev.FriendlyName + " with state " + dev.State);
                        }
                    }
                    catch (Exception ex)
                    {
                        //Do something with exception when an audio endpoint could not be muted
                        Debug.WriteLine(dev.FriendlyName + " could not be muted with error " + ex);
                    }
                }
            }
            catch (Exception ex)
            {
                //When something happend that prevent us to iterate through the devices
                Debug.WriteLine("Could not enumerate devices due to an excepion: " + ex.Message);
            }
        }
Пример #32
0
        public void SetVolume(int level)
        {
            try
            {
                //Instantiate an Enumerator to find audio devices
                NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
                //Get all the devices, no matter what condition or status
                NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
                //Loop through all devices
                foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
                {
                    try
                    {
                        if (dev.State == NAudio.CoreAudioApi.DeviceState.Active)
                        {
                            var newVolume = (float)Math.Max(Math.Min(level, 100), 0) / (float)100;

                            //Set at maximum volume
                            dev.AudioEndpointVolume.MasterVolumeLevelScalar = newVolume;

                            dev.AudioEndpointVolume.Mute = level == 0;

                            //Get its audio volume
                            Console.WriteLine("Volume of " + dev.FriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevelScalar.ToString());
                        }
                        else
                        {
                            Console.WriteLine("Ignoring device " + dev.FriendlyName + " with state " + dev.State);
                        }
                    }
                    catch (Exception ex)
                    {
                        //Do something with exception when an audio endpoint could not be muted
                        Console.WriteLine(dev.FriendlyName + " could not be muted with error " + ex);
                    }
                }
            }
            catch (Exception ex)
            {
                //When something happend that prevent us to iterate through the devices
                Console.WriteLine("Could not enumerate devices due to an excepion: " + ex.Message);
            }
        }
Пример #33
0
        public int GetValueVolume()
        {
            int volume = 0;

            NAudio.CoreAudioApi.MMDeviceEnumerator MMDE   = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
            foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
            {
                try
                {
                    if (dev.State == NAudio.CoreAudioApi.DeviceState.Active)
                    {
                        volume = Convert.ToInt32(dev.AudioEndpointVolume.MasterVolumeLevelScalar * 100);
                    }
                }
                catch (Exception) { }
            }
            return(volume);
        }
Пример #34
0
 private void GetDevice()
 {
     listBox1.Items.Add("GetDevice");
     try
     {
         //Instantiate an Enumerator to find audio devices
         NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
         //Get all the devices, no matter what condition or status
         NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
         //Loop through all devices
         foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
         {
             try
             {
                 if (dev.State == NAudio.CoreAudioApi.DeviceState.Active)
                 {
                     listBox1.Items.Add("Device 찾음");
                     listBox1.Items.Add(dev.FriendlyName);
                     cbDevice.Items.Add(dev);
                 }
                 else
                 {
                     Console.WriteLine("Ignoring device " + dev.FriendlyName + " with state " + dev.State);
                 }
             }
             catch (Exception ex)
             {
                 listBox1.Items.Add(ex.ToString());
             }
         }
     }
     catch (Exception ex)
     {
         listBox1.Items.Add(ex.ToString());
     }
     if (cbDevice.Items.Count > 0)
     {
         cbDevice.SelectedIndex = 0;
         master = (NAudio.CoreAudioApi.MMDevice)cbDevice.Items[0];
     }
 }
Пример #35
0
        public void setSystemVolume(float vol)
        {
            try
            {
                NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
                NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);

                foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
                {
                    try
                    {
                        //System.Diagnostics.Debug.Print(dev.FriendlyName);
                        dev.AudioEndpointVolume.MasterVolumeLevelScalar = vol;
                        break;
                    }
                    catch { }
                }

            }
            catch { }
        }
Пример #36
0
        private void buttonDown_Click(object sender, EventArgs e)
        {
            try
            {
                //Instantiate an Enumerator to find audio devices
                NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
                //Get all the devices, no matter what condition or status
                NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
                //Loop through all devices
                foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
                {
                    try
                    {
                        dev.AudioEndpointVolume.VolumeStepDown();
                        Trace.WriteLine(dev.AudioEndpointVolume.MasterVolumeLevel);
                        trackBar1.Value = (int)dev.AudioEndpointVolume.MasterVolumeLevel;
                        //Trace.WriteLine(trackBar1.Value);
                        //Set at maximum volume
                        //dev.AudioEndpointVolume.MasterVolumeLevel = 0;

                        //Get its audio volume
                        System.Diagnostics.Debug.Print("Volume of " + dev.FriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevel.ToString());

                        //Mute it
                        //dev.AudioEndpointVolume.Mute = true;
                        System.Diagnostics.Debug.Print(dev.FriendlyName + " is muted");
                    }
                    catch (Exception ex)
                    {
                        //Do something with exception when an audio endpoint could not be muted
                        System.Diagnostics.Debug.Print(dev.FriendlyName + " could not be muted");
                    }
                }
            }
            catch (Exception ex)
            {
                //When something happend that prevent us to iterate through the devices
                System.Diagnostics.Debug.Print("Could not enumerate devices due to an excepion: " + ex.Message);
            }
        }
Пример #37
0
        public void SetVolume(Int32 iLevel)
        {
            Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.info, "Attempting tomute the volume of all connected audio devices.");
            try
            {
                NAudio.CoreAudioApi.MMDeviceEnumerator pMDEEnum    = new NAudio.CoreAudioApi.MMDeviceEnumerator();
                NAudio.CoreAudioApi.MMDeviceCollection pMDCDevices = pMDEEnum.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
                foreach (NAudio.CoreAudioApi.MMDevice curDevice in pMDCDevices)
                {
                    try
                    {
                        if (curDevice.State == NAudio.CoreAudioApi.DeviceState.Active)
                        {
                            float pFltNewVolume = (float)Math.Max(Math.Min(iLevel, 100), 0) / (float)100;

                            curDevice.AudioEndpointVolume.MasterVolumeLevelScalar = pFltNewVolume;
                            curDevice.AudioEndpointVolume.Mute = (iLevel == 0);

                            Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.info, "Volume of {0} is {1}.", curDevice.FriendlyName, curDevice.AudioEndpointVolume.MasterVolumeLevelScalar.ToString());
                        }
                        else
                        {
                            Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.debug, "Ignoring device {0} with state {1}.", curDevice.FriendlyName, curDevice.State);
                        }
                    }
                    catch (Exception ex)
                    {
                        Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.error, "{0} could not be muted.", curDevice.FriendlyName);
                        Program.Logger.WriteException(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.error, "Unable to enumerate audio devices.");
                Program.Logger.WriteException(ex);
            }
        }
Пример #38
0
        public void SetVolume(Int32 iLevel)
        {
            Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.info, "Attempting tomute the volume of all connected audio devices.");
            try
            {
                NAudio.CoreAudioApi.MMDeviceEnumerator pMDEEnum = new NAudio.CoreAudioApi.MMDeviceEnumerator();
                NAudio.CoreAudioApi.MMDeviceCollection pMDCDevices = pMDEEnum.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
                foreach (NAudio.CoreAudioApi.MMDevice curDevice in pMDCDevices)
                {
                    try
                    {
                        if (curDevice.State == NAudio.CoreAudioApi.DeviceState.Active)
                        {
                            float pFltNewVolume = (float)Math.Max(Math.Min(iLevel, 100), 0) / (float)100;

                            curDevice.AudioEndpointVolume.MasterVolumeLevelScalar = pFltNewVolume;
                            curDevice.AudioEndpointVolume.Mute = (iLevel == 0);

                            Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.info, "Volume of {0} is {1}.", curDevice.FriendlyName, curDevice.AudioEndpointVolume.MasterVolumeLevelScalar.ToString());
                        }
                        else
                        {
                            Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.debug, "Ignoring device {0} with state {1}.", curDevice.FriendlyName, curDevice.State);
                        }
                    }
                    catch (Exception ex)
                    {
                        Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.error, "{0} could not be muted.", curDevice.FriendlyName);
                        Program.Logger.WriteException(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.error, "Unable to enumerate audio devices.");
                Program.Logger.WriteException(ex);
            }
        }
Пример #39
0
 public void GetAudioDevices()
 {
     NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
     NAudio.CoreAudioApi.MMDeviceCollection devices = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
     try
     {
         foreach (NAudio.CoreAudioApi.MMDevice dev in devices)
         {
             try
             {
                 bool mute = dev.AudioEndpointVolume.Mute;
                 System.Diagnostics.Debug.Print("Device {0} mute value: {1} ", dev.FriendlyName, mute);
                 audioDevices[dev] = mute;
             }
             catch
             {
             }
         }
     }
     catch
     {
     }
 }
Пример #40
0
 private void mute(bool flag)
 {
     try
     {
         NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
         NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
         foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
         {
             try
             {
                 //System.Diagnostics.Debug.Print(dev.FriendlyName);		//TODO: Understand
                 dev.AudioEndpointVolume.Mute = flag;
             }
             catch { }
         }
     }
     catch { }
 }
Пример #41
0
        public void SetVolume(int value)
        {
            NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
            NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active);

            foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
            {
                var sessions = dev.AudioSessionManager.Sessions;
                for(int i = 0; i < sessions.Count; i++)
                {
                    Process process = Process.GetProcessById((int)sessions[i].GetProcessID);
                    if (process.ProcessName == "Spotify")
                    {
                        sessions[i].SimpleAudioVolume.Mute = (value > 0) ? false : true;
                    }
                }
            }
        }
Пример #42
0
        public void init()
        {
            List<LSDevice> ldev = new List<LSDevice>();
            try
            {
                NAudio.CoreAudioApi.MMDeviceEnumerator mde = new NAudio.CoreAudioApi.MMDeviceEnumerator();
                Logger.app.a("Created MM enumerator");
                try
                {
                    foreach (
                        NAudio.CoreAudioApi.MMDevice device
                         in mde.EnumerateAudioEndPoints(
                            NAudio.CoreAudioApi.DataFlow.All,
                            NAudio.CoreAudioApi.DeviceState.All))
                    {
                        try
                        {
                            LSDevice add = new LSDevice();
                            add.mm = device;
                            add.isRec = device.DataFlow == NAudio.CoreAudioApi.DataFlow.Capture;
                            add.isPlay = device.DataFlow == NAudio.CoreAudioApi.DataFlow.Render;
                            if (device.DataFlow == NAudio.CoreAudioApi.DataFlow.All)
                            {
                                add.isRec = add.isPlay = true;
                            }
                            Logger.app.a("Df " + add.isPlay + " " + add.isRec);

                            add.id = device.ID;
                            Logger.app.a("ID " + add.id);

                            add.name = device.ToString();
                            Logger.app.a("Na " + add.name);

                            ldev.Add(add);
                        }
                        catch { Logger.app.a("Failed !"); }
                    }
                }
                catch { Logger.app.a("Failed !!"); }
            }
            catch { Logger.app.a("Failed !!!"); }

            devs = ldev.ToArray();
            if (string.IsNullOrEmpty(s_devRec)) s_devRec = "";
            if (string.IsNullOrEmpty(s_devMic)) s_devMic = "";
            if (string.IsNullOrEmpty(s_devOut)) s_devOut = "";
            if (!string.IsNullOrEmpty(s_devRec)) devRec = getDevByID(s_devRec); // ?? devs.First(x => x.isPlay);
            if (!string.IsNullOrEmpty(s_devMic)) devMic = getDevByID(s_devMic);
            if (!string.IsNullOrEmpty(s_devOut)) devOut = getDevByID(s_devOut);
        }
Пример #43
0
        /// <summary>
        /// Метод события до загрузки формы
        /// </summary>
        /// <param name="sender">отправитель</param>
        /// <param name="e">параметры</param>
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {

            #region Инициализация переменных и чтение параметров из конфигурационного файла

                this.Text = "VolumeLight " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

                connected = false;

                states = new List<State>(10);

                for (int i = 0; i < 10; i++)
                {
                    states.Add(new State(i + 1, Color.Black));
                }

                period = 1;
                start = 5;
                end = 105;
                host = "127.0.0.1";
                port = 3636;

                System.IO.StreamReader sr = new System.IO.StreamReader("config");
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (line.IndexOf("led") > -1)
                    {
                        int lednumber = Int32.Parse(line.Substring(3, line.IndexOf("=") - 3));
                        line = line.Substring(line.IndexOf("=") + 1);
                        int position = Int32.Parse(line.Substring(0, line.IndexOf("|")));
                        string color = line.Substring(line.IndexOf("|") + 1, line.Length - line.IndexOf("|") - 1);

                        states[lednumber - 1] = new State(position, color);
                    }
                    if (line.IndexOf("period") > -1)
                    {
                        period = Int32.Parse(line.Substring(line.IndexOf("=") + 1, line.Length - line.IndexOf("=") - 1));
                    }
                    if (line.IndexOf("start") > -1)
                    {
                        start = Int32.Parse(line.Substring(line.IndexOf("=") + 1, line.Length - line.IndexOf("=") - 1));
                    }
                    if (line.IndexOf("end") > -1)
                    {
                        end = Int32.Parse(line.Substring(line.IndexOf("=") + 1, line.Length - line.IndexOf("=") - 1));
                    }
                    if (line.IndexOf("host") > -1)
                    {
                        host = line.Substring(line.IndexOf("=") + 1, line.Length - line.IndexOf("=") - 1);
                    }
                    if (line.IndexOf("port") > -1)
                    {
                        port = Int32.Parse(line.Substring(line.IndexOf("=") + 1, line.Length - line.IndexOf("=") - 1));
                    }
                }
                sr.Close();

                en = new NAudio.CoreAudioApi.MMDeviceEnumerator();
                mmdevice = en.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Multimedia);
                api = new ApiLightpack();

                numericUpDown2.Value = period;
                numericUpDown3.Value = start;
                numericUpDown4.Value = end;
                textBox1.Text = host;
                numericUpDown1.Value = port;

                label_1.Text = states[0].Position.ToString();
                label_2.Text = states[1].Position.ToString();
                label_3.Text = states[2].Position.ToString();
                label_4.Text = states[3].Position.ToString();
                label_5.Text = states[4].Position.ToString();
                label_6.Text = states[5].Position.ToString();
                label_7.Text = states[6].Position.ToString();
                label_8.Text = states[7].Position.ToString();
                label_9.Text = states[8].Position.ToString();
                label_10.Text = states[9].Position.ToString();

                timer1.Interval = period;

            #endregion

                //Запуск таймера
                timer1.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Сообщение: " + ex.Message + Environment.NewLine + "StackTrace: " + Environment.NewLine + ex.StackTrace, "Произошла ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
        }
Пример #44
0
 private void InitializeNAudio()
 {
     // Get all Audio devices in the system
     DeviceList = new List<NAudio.CoreAudioApi.MMDevice>();
     NAudio.CoreAudioApi.MMDeviceEnumerator enumerator =
         new NAudio.CoreAudioApi.MMDeviceEnumerator();
     var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All,
         NAudio.CoreAudioApi.DeviceState.Active);
     DeviceList.AddRange(devices.ToArray());
 }
Пример #45
0
        public void UpdateDeviceInfo()
        {
            inDeviceInfo = new List<DeviceInfo>();
            outDeviceInfo = new List<DeviceInfo>();

            // Get devices for in and out
            List<WaveInCapabilities> inDevCaps = new List<WaveInCapabilities>();
            int waveInDevices = WaveIn.DeviceCount;
            for (int waveInDevice = 0; waveInDevice < waveInDevices; waveInDevice++)
            {
                WaveInCapabilities devCaps = WaveIn.GetCapabilities(waveInDevice);
                inDevCaps.Add(devCaps);
                logger.Info("AudioDevices::UpdateDeviceInfo Device {0}: {1}, {2} channels",
                    waveInDevice, devCaps.ProductName, devCaps.Channels);
            }

            List<WaveOutCapabilities> outDevCaps = new List<WaveOutCapabilities>();
            int waveOutDevices = WaveOut.DeviceCount;
            for (int waveOutDevice = 0; waveOutDevice < waveOutDevices; waveOutDevice++)
            {
                WaveOutCapabilities devCaps = WaveOut.GetCapabilities(waveOutDevice);
                outDevCaps.Add(devCaps);
                logger.Info("AudioDevices::UpdateDeviceInfo Device {0}: {1}, {2} channels",
                    waveOutDevice, devCaps.ProductName, devCaps.Channels);
            }

            // Now go through MM devices to match up
            try
            {
                //Instantiate an Enumerator to find audio devices
                NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
                //Get all the devices, no matter what condition or status
                NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
                //Loop through all devices
                foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
                {
                    try
                    {
                        for (int idx = 0; idx < inDevCaps.Count; idx++)
                            if (DevicesMatch(inDevCaps[idx].ProductName, dev.FriendlyName))
                            {
                                DeviceInfo devInfo = new DeviceInfo();
                                devInfo.waveDeviceNumber = idx;
                                devInfo.deviceName = dev.FriendlyName;
                                devInfo.deviceId = dev.ID;
                                devInfo.waveInCaps = inDevCaps[idx];
                                inDeviceInfo.Add(devInfo);
                                if (_curInDevice == null)
                                {
                                    _curInDevice = dev;
                                    _curWaveInDeviceInfoIdx = inDeviceInfo.Count - 1;
                                }
                            }
                        for (int idx = 0; idx < outDevCaps.Count; idx++)
                            if (DevicesMatch(outDevCaps[idx].ProductName, dev.FriendlyName))
                            {
                                DeviceInfo devInfo = new DeviceInfo();
                                devInfo.waveDeviceNumber = idx;
                                devInfo.deviceName = dev.FriendlyName;
                                devInfo.deviceId = dev.ID;
                                devInfo.waveOutCaps = outDevCaps[idx];
                                outDeviceInfo.Add(devInfo);
                                bool bUseThis = false;
                                if (_curOutDevice == null)
                                    bUseThis = true;
                                else if (!_curOutDevice.FriendlyName.Contains("Speakers") && dev.FriendlyName.Contains("Speakers"))
                                    bUseThis = true;
                                if (bUseThis)
                                {
                                    _curOutDevice = dev;
                                    _curWaveOutDeviceInfoIdx = outDeviceInfo.Count - 1;
                                }
                            }                            

                    }
                    catch (Exception ex)
                    {
                        //Do something with exception when an audio endpoint could not be muted
                        logger.Error("AudioDevices::UpdateDeviceInfo Exception in Update {0}", ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                //When something happend that prevent us to iterate through the devices
                logger.Error("AudioDevices::UpdateDeviceInfo Could not enumerate devices due to an excepion: {0}", ex.Message);
            }
        }