Пример #1
0
        /// <summary>
        /// Gets WaveOut/WaveIn audio device.
        /// </summary>
        /// <param name="dataFlow">Audio data flow.</param>
        /// <returns>Audio device list.</returns>
        private static AudioDevice[] GetWaveAudioDevices(AudioDataFlow dataFlow)
        {
            var devices = new List <AudioDevice>();

            if (dataFlow.HasFlag(AudioDataFlow.Render))
            {
                for (int i = -1; i < WaveOut.DeviceCount; i++)
                {
                    var caps = WaveOut.GetCapabilities(i);

                    devices.Add(
                        new AudioDevice
                    {
                        Id           = Convert.ToBase64String(Encoding.UTF8.GetBytes(String.Format("{0}.{1}", i, caps.ProductName)), Base64FormattingOptions.None).TrimEnd('='),
                        Guid         = caps.ProductGuid,
                        Number       = i,
                        DataFlow     = AudioDataFlow.Render,
                        DeviceType   = AudioDeviceType.Wave,
                        Name         = caps.ProductName,
                        FriendlyName = caps.ProductName,
                    }
                        );
                }
            }

            return(devices.ToArray());
        }
Пример #2
0
        /// <summary>
        /// Gets WASAPI Audio device.
        /// </summary>
        /// <param name="dataFlow">Audio data flow.</param>
        /// <param name="deviceRole">Audio device role.</param>
        /// <returns>Audio device list.</returns>
        private static AudioDevice[] GetWASAPIAudioDevices(AudioDataFlow dataFlow, AudioDeviceRole deviceRole = AudioDeviceRole.Multimedia)
        {
            var devices = new List <AudioDevice>();

            var mmde = new MMDeviceEnumerator();
            var role = deviceRole switch
            {
                AudioDeviceRole.Console => Role.Console,
                AudioDeviceRole.Multimedia => Role.Multimedia,
                AudioDeviceRole.Communications => Role.Communications,
                _ => Role.Multimedia,
            };

            if (dataFlow.HasFlag(AudioDataFlow.Render))
            {
                try
                {
                    var device = mmde.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, role);
                    devices.Add(GetAudioDeviceFromMMDevice(device, AudioDataFlow.Render));
                }
                catch (Exception) { }

                foreach (var item in mmde.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, DeviceState.Active))
                {
                    devices.Add(GetAudioDeviceFromMMDevice(item, AudioDataFlow.Render));
                }
            }

            return(devices.ToArray());
        }
Пример #3
0
        /// <summary>
        /// Gets ASIO audio device.
        /// </summary>
        /// <param name="dataFlow">Audio data flow.</param>
        /// <returns>Audio device list.</returns>
        private static AudioDevice[] GetASIOAudioDevices(AudioDataFlow dataFlow)
        {
            var devices = new List <AudioDevice>();

            if (dataFlow.HasFlag(AudioDataFlow.Render))
            {
                foreach (var item in AsioOut.GetDriverNames())
                {
                    devices.Add(
                        new AudioDevice
                    {
                        Id           = item,
                        DataFlow     = AudioDataFlow.Render,
                        DeviceType   = AudioDeviceType.ASIO,
                        Name         = item,
                        FriendlyName = item,
                    }
                        );
                }
            }

            return(devices.ToArray());
        }
Пример #4
0
        /// <summary>
        /// Get DirectSound audio device.
        /// </summary>
        /// <param name="dataFlow">Audio data flow.</param>
        /// <returns>Audio device list.</returns>
        private static AudioDevice[] GetDirectSoundAudioDevices(AudioDataFlow dataFlow)
        {
            var devices = new List <AudioDevice>();

            if (dataFlow.HasFlag(AudioDataFlow.Render))
            {
                foreach (var item in DirectSoundOut.Devices)
                {
                    devices.Add(
                        new AudioDevice
                    {
                        Id           = item.Guid.ToString(),
                        Guid         = item.Guid,
                        DataFlow     = AudioDataFlow.Render,
                        DeviceType   = AudioDeviceType.DirectSound,
                        Name         = item.ModuleName,
                        FriendlyName = item.Description,
                    }
                        );
                }
            }

            return(devices.ToArray());
        }