예제 #1
1
        public MainForm()
        {
            library = Library.Load();
            if (library == null)
            {
                library = new Library();
                library.Save();
            }
            library.LibraryChanged += library_LibraryChanged;

            settings = Settings.Load(SETTINGSPATH);
            if (settings == null)
                settings = new Settings();

            MMDeviceEnumerator enumerator = new MMDeviceEnumerator();
            defaultAudioDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
            this.musicPlayer.OpenCompleted += equalizerSettings_ShouldSet;

            this.equalizerSettings = EqualizerSettings.Load(EQUALIZERPATH);
            if (this.equalizerSettings == null)
            {
                this.equalizerSettings = new EqualizerSettings();
                this.equalizerSettings.Save(EQUALIZERPATH);
            }
            this.equalizerSettings.ValueChanged += equalizerSettings_ShouldSet;

            SetUpGlobalHotkeys();

            InitializeComponent();
        }
예제 #2
1
 private static MMDevice GetDefaultDevice()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         try
         {
             return enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
         }
         catch (CoreAudioAPIException)
         {
             return null;
         }
     }
 }
 public void InitManager()
 {
     deviceEnum = new MMDeviceEnumerator();
     deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
     device = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
     sessionManager = AudioSessionManager2.FromMMDevice(device);
 }
예제 #4
0
 public static MMDevice GetDefaultSoundDevice()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         return enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
     }
 }
예제 #5
0
 /// <summary>
 /// Returns the default audio endpoint for the specified data-flow direction and role.
 /// </summary>
 /// <param name="dataFlow">The data-flow direction for the endpoint device.</param>
 /// <param name="role">The role of the endpoint device.</param>
 /// <returns><see cref="MMDevice"/> instance of the endpoint object for the default audio endpoint device.</returns>
 public static MMDevice DefaultAudioEndpoint(DataFlow dataFlow, Role role)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         return enumerator.GetDefaultAudioEndpoint(dataFlow, role);
     }
 }
예제 #6
0
 /// <summary>
 /// Returns the default audio endpoint for the specified data-flow direction and role.
 /// </summary>
 /// <param name="dataFlow">The data-flow direction for the endpoint device.</param>
 /// <param name="role">The role of the endpoint device.</param>
 /// <returns><see cref="MMDevice"/> instance of the endpoint object for the default audio endpoint device.</returns>
 public static MMDevice DefaultAudioEndpoint(DataFlow dataFlow, Role role)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         return(enumerator.GetDefaultAudioEndpoint(dataFlow, role));
     }
 }
        private static AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
        {
            using CSCore.CoreAudioAPI.MMDeviceEnumerator enumerator = new CSCore.CoreAudioAPI.MMDeviceEnumerator();
            using var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia);
            var sessionManager = AudioSessionManager2.FromMMDevice(device);

            return(sessionManager);
        }
예제 #8
0
 private CSCore.CoreAudioAPI.AudioSessionManager2 GetDefaultAudioSessionManager2(CSCore.CoreAudioAPI.MMDeviceEnumerator enumerator, CSCore.CoreAudioAPI.DataFlow dataFlow)
 {
     using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, CSCore.CoreAudioAPI.Role.Multimedia))
     {
         var sessionManager = CSCore.CoreAudioAPI.AudioSessionManager2.FromMMDevice(device);
         return(sessionManager);
     }
 }
예제 #9
0
 public CsCoreEngine()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
     }
     endpointVolume = AudioEndpointVolume.FromDevice(device);
 }
 private AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
         {
             var sessionManager = AudioSessionManager2.FromMMDevice(device);
             return sessionManager;
         }
     }
 }
예제 #11
0
파일: Utils.cs 프로젝트: hoangduit/cscore
 public static AudioClient CreateDefaultRenderClient()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console))
         {
             var audioClient = AudioClient.FromMMDevice(device);
             Assert.IsNotNull(audioClient);
             return audioClient;
         }
     }
 }
예제 #12
0
        public MusicPlayer()
        {
            using (var enumerator = new MMDeviceEnumerator())
            {
                device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);

                using (var client = AudioClient.FromMMDevice(device))
                {
                    client.Initialize(AudioClientShareMode.Shared,
                        AudioClientStreamFlags.None, 1000, 0, client.GetMixFormat(), Guid.Empty);
                }
            }
        }
예제 #13
0
 public static float GetSpotifyInstaVolume()
 {
     using (var enumerator = new CSCore.CoreAudioAPI.MMDeviceEnumerator())
         using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia))
             using (var sessionManager = AudioSessionManager2.FromMMDevice(device))
                 using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
                 {
                     foreach (var session in sessionEnumerator)
                     {
                         using (var audioMeterInformation = session.QueryInterface <AudioMeterInformation>())
                             using (var audioIdInformation = session.QueryInterface <AudioSessionControl2>())
                             {
                                 if (audioIdInformation.SessionIdentifier.Contains("Spotify"))
                                 {
                                     return(audioMeterInformation.GetPeakValue());
                                 }
                             }
                     }
                 }
     return(float.NaN);
 }
예제 #14
0
        private void UpdateDefaultAudioDevice()
        {
            MMDevice defaultAudioEndpoint;
            using (var enumerator = new MMDeviceEnumerator())
            {
                defaultAudioEndpoint = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
            }

            foreach (var soundOutMode in SoundOutModes)
            {
                foreach (var soundOutDevice in soundOutMode.Devices)
                    soundOutDevice.IsDefault = false;

                var newDefaultDevice = soundOutMode.Devices.FirstOrDefault(x => x.Id == defaultAudioEndpoint.DeviceID);
                if (newDefaultDevice != null)
                    newDefaultDevice.IsDefault = true;
            }
        }
예제 #15
0
        public ISoundOut GetNewSoundSource()
        {
            var settings = HurricaneSettings.Instance.Config;

            MMDevice defaultDevice;
            using (var enumerator = new MMDeviceEnumerator())
            {
                try
                {
                    defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
                }
                catch (CoreAudioAPIException)
                {
                    defaultDevice = null;
                }
            }


            if (settings.SoundOutMode == SoundOutMode.DirectSound)
            {
                var enumerator = new DirectSoundDeviceEnumerator();
                if (enumerator.Devices.Count == 0)
                {
                    settings.SoundOutMode = SoundOutMode.WASAPI;
                    return GetNewSoundSource();
                }

                DirectSoundDevice device;
                if (settings.SoundOutDeviceID == DefaultDevicePlaceholder)
                {
                    device = defaultDevice != null
                        ? enumerator.Devices.FirstOrDefault(x => x.Description == defaultDevice.FriendlyName) ??
                          enumerator.Devices.First()
                        : enumerator.Devices.First();
                }
                else
                {
                    device = enumerator.Devices.FirstOrDefault(x => x.Guid.ToString() == settings.SoundOutDeviceID);
                    if (device == null)
                    {
                        settings.SoundOutDeviceID = DefaultDevicePlaceholder;
                        return GetNewSoundSource();
                    }
                }

                _currentDeviceId = device.Guid.ToString();
                return new DirectSoundOut { Device = device.Guid, Latency = settings.Latency };
            }
            else
            {
                using (var enumerator = new MMDeviceEnumerator())
                {
                    using (var devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                    {
                        if (defaultDevice == null || devices.Count == 0)
                        {
                            settings.SoundOutMode = SoundOutMode.DirectSound;
                            return GetNewSoundSource();
                        }

                        MMDevice device;
                        if (settings.SoundOutDeviceID == DefaultDevicePlaceholder)
                        {
                            device = defaultDevice;
                        }
                        else
                        {
                            device = devices.FirstOrDefault(x => x.DeviceID == settings.SoundOutDeviceID);

                            if (device == null)
                            {
                                settings.SoundOutDeviceID = DefaultDevicePlaceholder;
                                return GetNewSoundSource();
                            }
                        }
                        _currentDeviceId = device.DeviceID;
                        return new WasapiOut { Device = device, Latency = settings.Latency };
                    }
                }
            }
        }
예제 #16
0
        void UpdateDefaultAudioDevice()
        {
            MMDevice defaultAudioEndpoint;
            using (var enumerator = new MMDeviceEnumerator())
            {
                defaultAudioEndpoint = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
            }

            foreach (var soundOutRepresenter in SoundOutList)
            {
                soundOutRepresenter.AudioDevices.ToList().ForEach(x => x.IsDefault = false);
                var targetDevice =
                    soundOutRepresenter.AudioDevices.FirstOrDefault(x => x.ID == defaultAudioEndpoint.DeviceID);
                if (targetDevice != null) targetDevice.IsDefault = true;
            }
        }
예제 #17
0
 private MMDevice GetDefaultDevice()
 {
     if(WasapiOut.IsSupportedOnCurrentPlatform)
     {
         using (var enumerator = new MMDeviceEnumerator())
         {
             MMDevice dev = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
             return dev;
         }
     }
     return null;
 }
예제 #18
0
 public void GetDefaultRenderEndpoint()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console))
         {
             Debug.WriteLine(device.ToString());
         }
     }
 }
예제 #19
0
        private void LoadSoundOutModes()
        {
            SoundOutModes.Clear();
            using (var enumerator = new MMDeviceEnumerator())
            {
                MMDevice defaultDevice;
                try
                {
                    defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
                }
                catch (CoreAudioAPIException)
                {
                    defaultDevice = null;
                }

                if (WasapiOut.IsSupportedOnCurrentPlatform)
                {
                    var wasApiMode = new SoundOutMode("WASAPI", SoundOutType.WasApi, GetWasApiSoundOutDeviceById, GetWasApiSoundOut, new SoundOutDevice("Windows Default", WindowsDefaultId, SoundOutType.WasApi));

                    using (var devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                    {
                        foreach (var device in devices.Select(x => new SoundOutDevice(x.FriendlyName, x.DeviceID, SoundOutType.WasApi, defaultDevice != null && defaultDevice.DeviceID == x.DeviceID)))
                            wasApiMode.Devices.Add(device);
                    }

                    UpdateWindowsDefault(wasApiMode);
                    SoundOutModes.Add(wasApiMode);
                }

                var directSoundMode = new SoundOutMode("DirectSound", SoundOutType.DirectSound, GetDirectSoundOutDeviceById, GetDirectSoundOut, new SoundOutDevice("Windows Default", WindowsDefaultId, SoundOutType.DirectSound));
                foreach (var device in DirectSoundDeviceEnumerator.EnumerateDevices().Select(x => new SoundOutDevice(x.Description, x.Module, SoundOutType.DirectSound, defaultDevice != null && x.Description == defaultDevice.FriendlyName)))
                   directSoundMode.Devices.Add(device);

                UpdateWindowsDefault(directSoundMode);
                SoundOutModes.Add(directSoundMode);
                CheckCurrentState();
            }
        }
예제 #20
0
 private AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
         {
             Debug.WriteLine("DefaultDevice: " + device.FriendlyName);
             var sessionManager = AudioSessionManager2.FromMMDevice(device);
             return sessionManager;
         }
     }
 }
예제 #21
0
        void RefreshSoundOutRepresenter()
        {
            var result = new ObservableCollection<SoundOutRepresenter>();
            using (var enumerator = new MMDeviceEnumerator())
            {
                MMDevice standarddevice;
                try
                {
                    standarddevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
                }
                catch (CoreAudioAPIException)
                {
                    standarddevice = null;
                }
                
                if (WasapiOut.IsSupportedOnCurrentPlatform)
                {
                    var wasApiItem = new SoundOutRepresenter(deviceId =>
                    {
                        using (var mmdeviceEnumerator = new MMDeviceEnumerator())
                        {
                            var device =
                                mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)
                                    .FirstOrDefault(x => x.DeviceID == deviceId);
                            return device == null ? null : new AudioDevice(device.DeviceID, device.FriendlyName);
                        }
                    }) { Name = "WASAPI", SoundOutMode = SoundOutMode.WASAPI };

                    using (var devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                    {
                        foreach (var device in devices.Select(device => new AudioDevice(device.DeviceID, device.FriendlyName, standarddevice != null && standarddevice.DeviceID == device.DeviceID)))
                        {
                            wasApiItem.AudioDevices.Add(device);
                        }
                    }

                    CheckDefaultAudioDevice(wasApiItem);

                    result.Add(wasApiItem);
                }

                var directSoundItem = new SoundOutRepresenter(deviceId =>
                {
                    var device =
                        new DirectSoundDeviceEnumerator().Devices
                            .FirstOrDefault(x => x.Guid.ToString() == deviceId);
                    return device == null ? null : new AudioDevice(device.Guid.ToString(), device.Description);
                }) { Name = "DirectSound", SoundOutMode = SoundOutMode.DirectSound };

                foreach (var device in new DirectSoundDeviceEnumerator().Devices.Select(x => new AudioDevice(x.Guid.ToString(), x.Description, standarddevice != null && x.Description == standarddevice.FriendlyName)))
                {
                    directSoundItem.AudioDevices.Add(device);
                }

                CheckDefaultAudioDevice(directSoundItem);

                result.Add(directSoundItem);
            }

            SoundOutList = result;
        }