예제 #1
0
        public void TestAudioDevicesOperator(AudioDeviceType deviceType)
        {
            var devices1 = AudioDevice.GetAudioDevices(AudioDataFlow.Render, deviceType);
            var devices2 = AudioDevice.GetAudioDevices(AudioDataFlow.Render, deviceType);

            for (int i = 0; i < devices1.Length; i++)
            {
                Assert.False(Object.ReferenceEquals(devices1[i], devices2[i]));
                Assert.True(devices1[i] == devices2[i]);
                Assert.False(devices1[i] != devices2[i]);
                Assert.True(devices1[i].GetHashCode() == devices2[i].GetHashCode());

                Assert.False(devices1[i] == null);
                Assert.False(null == devices1[i]);

                Assert.True(devices1[i] != null);
                Assert.True(null != devices1[i]);


                if (i >= 1)
                {
                    Assert.False(devices1[i] == devices2[i - 1]);
                    Assert.True(devices1[i] != devices2[i - 1]);
                    Assert.False(devices1[i].GetHashCode() == devices2[i - 1].GetHashCode());
                }
            }
        }
예제 #2
0
        public void TestAudioDevices(AudioDeviceType deviceType)
        {
            var devices = AudioDevice.GetAudioDevices(AudioDataFlow.Render, deviceType);

            Assert.NotNull(devices);

            foreach (var item in devices)
            {
                Assert.NotNull(item.Id);
                Assert.NotNull(item.Guid.ToString());
                Assert.Equal(deviceType, item.DeviceType);
                Assert.Equal(AudioDataFlow.Render, item.DataFlow);
                Assert.NotNull(item.Name);
                Assert.NotNull(item.FriendlyName);

                output.WriteLine("Id: {0}", item.Id);
                output.WriteLine("Guid: {0}", item.Guid);
                output.WriteLine("Number: {0}", item.Number);
                output.WriteLine("DeviceType: {0}", item.DeviceType);
                output.WriteLine("DataFlow: {0}", item.DataFlow);
                output.WriteLine("Name: {0}", item.Name);
                output.WriteLine("FriendlyName: {0}", item.FriendlyName);
                output.WriteLine("MMDevice: {0}", (item.MMDevice != null));
                output.WriteLine("----");
            }
        }
예제 #3
0
 public AudioDevice(AudioDeviceType _audioDeviceType, int _index, string _name, int _channels)
 {
     name            = _name;
     index           = _index;
     audioDeviceType = _audioDeviceType;
     channels        = _channels;
 }
예제 #4
0
        /// <summary>
        ///     Cycle the audio device for the given type
        /// </summary>
        /// <param name="type"></param>
        public override bool CycleAudioDevice(AudioDeviceType type)
        {
            ICollection <IAudioDevice> audioDevices;

            switch (type)
            {
            case AudioDeviceType.Playback:
                audioDevices = AppModel.Instance.AvailablePlaybackDevices;
                break;

            case AudioDeviceType.Recording:
                audioDevices = AppModel.Instance.AvailableRecordingDevices;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            switch (audioDevices.Count)
            {
            case 0:
                throw new AppModel.NoDevicesException();

            case 1:
                return(false);
            }

            return(SetActiveDevice(GetNextDevice(audioDevices, type)));
        }
예제 #5
0
 public PlayerConfiguration()
 {
     CacheBeforePlaying  = true;  // temporarily make this the default - remove this feature altogether of url streaming proves to be working via the FilePlayer
     WasapiExclusiveMode = false; // exclusive mode simply does not work reliably ...
     WasapiLatency       = 20;
     EnabledAudioTypes   = new AudioDeviceType[] { AudioDeviceType.Wasapi };
 }
예제 #6
0
        public void SetSelectedAudioDevices(AudioDeviceType audioDeviceType)
        {
            try
            {
                switch (audioDeviceType)
                {
                case AudioDeviceType.Capture:
                    using (AudioCaptureDeviceDialog audioCaptureDeviceDialog = new AudioCaptureDeviceDialog(SelectedCaptureDevicesCollection))
                    {
                        if (audioCaptureDeviceDialog.ShowDialog().Value)
                        {
                            SelectedCaptureDevicesCollection = new ObservableCollection <AudioCaptureDevice>(audioCaptureDeviceDialog.SelectedAudioCaptureDevices);
                        }
                    }
                    break;

                case AudioDeviceType.Render:
                    using (AudioOutputDeviceDialog audioOutputDeviceDialog = new AudioOutputDeviceDialog(SelectedOutputDevicesCollection))
                    {
                        if (audioOutputDeviceDialog.ShowDialog().Value)
                        {
                            SelectedOutputDevicesCollection = new ObservableCollection <AudioOutputDevice>(audioOutputDeviceDialog.SelectedAudioOutputDevices);
                        }
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                ApplicationLogger.Log(ex.Message, ex.StackTrace);
            }
        }
예제 #7
0
        /// <summary>
        /// Gets Audio devices.
        /// </summary>
        /// <param name="dataFlow">Audio data flow. In current version, only <see cref="AudioDataFlow.Render"/> is supported.</param>
        /// <param name="deviceType">Audio device type.</param>
        /// <param name="deviceRole">Audio device role.</param>
        /// <returns>Audio device list.</returns>
        public static AudioDevice[] GetAudioDevices(AudioDataFlow dataFlow, AudioDeviceType deviceType = AudioDeviceType.WASAPI, AudioDeviceRole deviceRole = AudioDeviceRole.Multimedia)
        {
            AudioDevice[] result;

            if (deviceType == AudioDeviceType.WASAPI)
            {
                result = GetWASAPIAudioDevices(dataFlow, deviceRole);
            }
            else if (deviceType == AudioDeviceType.Wave)
            {
                result = GetWaveAudioDevices(dataFlow);
            }
            else if (deviceType == AudioDeviceType.DirectSound)
            {
                result = GetDirectSoundAudioDevices(dataFlow);
            }
            else if (deviceType == AudioDeviceType.ASIO)
            {
                result = GetASIOAudioDevices(dataFlow);
            }
            else
            {
                throw new ArgumentException(String.Format("Invalid device type: {0}", deviceType), nameof(deviceType));
            }

            return(result);
        }
예제 #8
0
 public AudioOutputDevice(string name, string id, AudioDeviceType deviceType, bool defaultDevice)
 {
     Name          = name;
     Id            = id;
     DeviceType    = deviceType;
     DefaultDevice = defaultDevice;
 }
예제 #9
0
        public bool DeviceExists(string deviceName, AudioDeviceType deviceType = AudioDeviceType.Both)
        {
            bool hasDevice           = false;
            HotkeyAudioDevice device = null;

            if ((deviceType == AudioDeviceType.Output || deviceType == AudioDeviceType.Both) && !hasDevice)
            {
                device = GetDevice(deviceName, AudioDeviceType.Output);
                if (device != null)
                {
                    hasDevice = true;
                }
            }


            if ((deviceType == AudioDeviceType.Input || deviceType == AudioDeviceType.Both) && !hasDevice)
            {
                device = GetDevice(deviceName, AudioDeviceType.Input);
                if (device != null)
                {
                    hasDevice = true;
                }
            }

            return(hasDevice);
        }
        public AudioDeviceWatcher(AudioDeviceType ioType, CoreDispatcher dispatcher)
        {
            this.DeviceInformationList = new ObservableCollection <DeviceInformation>();

            m_coreDispatcher = dispatcher;

            switch (ioType)
            {
            case AudioDeviceType.Input:
            {
                m_deviceSelectorString = MediaDevice.GetAudioCaptureSelector();
                break;
            }

            case AudioDeviceType.Output:
            {
                m_deviceSelectorString = MediaDevice.GetAudioRenderSelector();
                break;
            }

            default:
            {
                break;
            }
            }

            m_deviceWatcher          = DeviceInformation.CreateWatcher(m_deviceSelectorString);
            m_deviceWatcher.Added   += DeviceWatcher_Added;
            m_deviceWatcher.Removed += DeviceWatcher_Removed;
            m_deviceWatcher.Updated += DeviceWatcher_Updated;
            m_deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;

            m_deviceType = ioType;
        }
 public IAudioDevice CreateDevice(AudioDeviceType audioDeviceType)
 {
     switch (audioDeviceType)
     {
         case AudioDeviceType.Silent:
             return new SilentAudioDevice();
         case AudioDeviceType.Bass:
             return new BassAudioDevice();
         default:
             throw new AudioDeviceException("unknown audio device type");
     }
 }
예제 #12
0
        public bool SetHotkeyCombination(HotKeys hotkeys, AudioDeviceType deviceType)
        {
            using (AppLogger.Log.InfoCall())
            {
                HotKeys confHotKeys = null;
                switch (deviceType)
                {
                case AudioDeviceType.Playback:
                    confHotKeys = AppConfigs.Configuration.PlaybackHotKeys;
                    break;

                case AudioDeviceType.Recording:
                    confHotKeys = AppConfigs.Configuration.RecordingHotKeys;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null);
                }
                using (AppLogger.Log.InfoCall())
                {
                    AppLogger.Log.Info("Unregister previous hotkeys", confHotKeys);
                    WindowsAPIAdapter.UnRegisterHotKey(confHotKeys);
                    AppLogger.Log.Info("Unregistered previous hotkeys", confHotKeys);

                    if (hotkeys.Enabled && !WindowsAPIAdapter.RegisterHotKey(hotkeys))
                    {
                        AppLogger.Log.Warn("Can't register new hotkeys", hotkeys);
                        ErrorTriggered?.Invoke(this,
                                               new ExceptionEvent(new Exception("Impossible to register HotKey: " + hotkeys)));
                        return(false);
                    }

                    AppLogger.Log.Info("New Hotkeys registered", hotkeys);
                }
                switch (deviceType)
                {
                case AudioDeviceType.Playback:
                    AppConfigs.Configuration.PlaybackHotKeys = hotkeys;
                    break;

                case AudioDeviceType.Recording:
                    AppConfigs.Configuration.RecordingHotKeys = hotkeys;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null);
                }
                AppConfigs.Configuration.Save();
                return(true);
            }
        }
예제 #13
0
 /// <summary>
 ///     Cycles the active device to the next device. Returns true if succesfully switched (at least
 ///     as far as we can tell), returns false if could not successfully switch. Throws NoDevicesException
 ///     if there are no devices configured.
 /// </summary>
 public bool CycleActiveDevice(AudioDeviceType type)
 {
     using (AppLogger.Log.InfoCall())
     {
         try
         {
             return(_deviceCyclerManager.CycleDevice(type));
         }
         catch (Exception exception)
         {
             ErrorTriggered?.Invoke(this, new ExceptionEvent(exception));
         }
         return(false);
     }
 }
예제 #14
0
 public HotkeyAudioDevice GetDevice(string deviceName, AudioDeviceType deviceType = AudioDeviceType.Output)
 {
     if (deviceType == AudioDeviceType.Output)
     {
         return(AudioOutputDevices.FirstOrDefault(audioDevice => audioDevice.AudioDeviceName.Equals(deviceName)));
     }
     else if (deviceType == AudioDeviceType.Input)
     {
         return(AudioInputDevices.FirstOrDefault(audioDevice => audioDevice.AudioDeviceName.Equals(deviceName)));
     }
     else if (deviceType == AudioDeviceType.Both)
     {
         throw new Exception("Cannot use device type of both to get one device");
     }
     return(null);
 }
예제 #15
0
        private void UpdateImageContextMenu(AudioDeviceType audioDeviceType, DeviceDefaultChangedEvent audioChangeEvent)
        {
            if (audioChangeEvent.role != Role.Console)
            {
                return;
            }

            foreach (
                var toolStripDevItem in
                _selectionMenu.Items.OfType <ToolStripDeviceItem>().Where(item => item.AudioDevice.Type == audioDeviceType))
            {
                toolStripDevItem.Image = toolStripDevItem.AudioDevice.FriendlyName == audioChangeEvent.device.FriendlyName
                    ? Resources.Check
                    : null;
            }
        }
예제 #16
0
        /// <summary>
        /// Creates a new <see cref="AudioDeviceCapabilities"/> object.
        /// </summary>
        /// <param name="devType">The device type.</param>
        /// <param name="outputConfigurations">The available output configurations.</param>
        /// <param name="inputConfigurations">The available input configurations.</param>
        public AudioDeviceCapabilities(AudioDeviceType devType, IAudioConfiguration[] outputConfigurations, IAudioConfiguration[] inputConfigurations)
        {
            Type = devType;
            if (outputConfigurations == null)
            {
                outputConfigurations = new IAudioConfiguration[0];
            }

            if (inputConfigurations == null)
            {
                inputConfigurations = new IAudioConfiguration[0];
            }

            m_OutputConfigurations = outputConfigurations;
            m_InputConfigurations  = inputConfigurations;
        }
예제 #17
0
        /// <summary>
        /// Creates a new <see cref="AudioDeviceCapabilities"/> object.
        /// </summary>
        /// <param name="devType"></param>
        /// <param name="configurations"></param>
        public AudioDeviceCapabilities(AudioDeviceType devType, params IAudioConfiguration[] configurations)
        {
            Type = devType;
            if (configurations == null)
            {
                configurations = new IAudioConfiguration[0];
            }

            if ((Type & AudioDeviceType.Input) != 0)
            {
                m_InputConfigurations = configurations;
            }
            if ((Type & AudioDeviceType.Output) != 0)
            {
                m_OutputConfigurations = configurations;
            }
        }
예제 #18
0
        /// <summary>
        ///     Cycles the active device to the next device. Returns true if succesfully switched (at least
        ///     as far as we can tell), returns false if could not successfully switch. Throws NoDevicesException
        ///     if there are no devices configured.
        /// </summary>
        public bool CycleActiveDevice(AudioDeviceType type)
        {
            using (AppLogger.Log.InfoCall())
            {
                ICollection <IAudioDevice> list = null;
                string lastActive = null;
                switch (type)
                {
                case AudioDeviceType.Playback:
                    list       = AvailablePlaybackDevices;
                    lastActive = AppConfigs.Configuration.LastPlaybackActive;
                    break;

                case AudioDeviceType.Recording:
                    list       = AvailableRecordingDevices;
                    lastActive = AppConfigs.Configuration.LastRecordingActive;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }

                switch (list.Count)
                {
                case 0:
                    ErrorTriggered?.Invoke(this, new ExceptionEvent(new NoDevicesException()));
                    return(false);

                case 1:
                    return(false);
                }
                AppLogger.Log.Info("Cycle Audio Devices", list);
                var defaultDev = list.FirstOrDefault(device => device.FriendlyName == lastActive) ?? list.FirstOrDefault(device => device.IsDefault(Role.Console)) ?? list.ElementAt(0);
                var next       = list.SkipWhile((device, i) => device != defaultDev).Skip(1).FirstOrDefault() ?? list.ElementAt(0);
                AppLogger.Log.Info("Select AudioDevice", next);
                return(SetActiveDevice(next));
            }
        }
예제 #19
0
        public static AudioDevice[] GetAudioDevices(AudioDeviceType audioDeviceType)
        {
            AudioDevice[] audioDevices = null;
            unsafe
            {
                TestStruct** structs;
                int devicesCount;

                GetAudioDevices(audioDeviceType, out structs, out devicesCount);
                audioDevices = new AudioDevice[devicesCount];
                for (int i = 0; i < devicesCount; ++i)
                {
                    AudioDevice audioDevice = new AudioDevice
                                                  {
                                                      Id = Marshal.PtrToStringUni(structs[i]->Id),
                                                      Description = Marshal.PtrToStringUni(structs[i]->Description)
                                                  };
                    audioDevices[i] = audioDevice;
                }
                DisposeAudioDevices(structs, devicesCount);
            }
            return audioDevices;
        }
 public void SetAudioDeviceType(AudioDeviceType devicetype)
 {
     OutputMedia.AudioDeviceType = devicetype;
 }
예제 #21
0
 /// <summary>
 /// Gets Audio render devices.
 /// </summary>
 /// <param name="deviceType">Audio device type.</param>
 /// <param name="deviceRole">Audio device role.</param>
 /// <returns>Audio device list.</returns>
 public static AudioDevice[] GetAudioRenderDevices(AudioDeviceType deviceType = AudioDeviceType.WASAPI, AudioDeviceRole deviceRole = AudioDeviceRole.Multimedia)
 {
     return(GetAudioDevices(AudioDataFlow.Render, deviceType, deviceRole));
 }
 public void SetAudioDeviceType(AudioDeviceType devicetype)
 {
     OutputMedia.AudioDeviceType = devicetype;
 }
예제 #23
0
 public DeviceListChanged(IEnumerable <string> seletedDevicesList, AudioDeviceType type)
 {
     SeletedDevicesList = seletedDevicesList;
     Type = type;
 }
예제 #24
0
 private unsafe static extern void GetAudioDevices(AudioDeviceType audioDeviceType, out TestStruct** structs, out int deviceType);
예제 #25
0
 public static extern int GetAudioDevice(
     [InAttribute()][MarshalAsAttribute(UnmanagedType.LPStr)] string device, AudioDeviceType deviceType, [In, Out, MarshalAsAttribute(UnmanagedType.LPStr)] System.Text.StringBuilder audioDevice, int length);
예제 #26
0
 public static extern int SetAudioDevice(
     [InAttribute()][MarshalAsAttribute(UnmanagedType.LPStr)] string device, AudioDeviceType deviceType, [InAttribute()][MarshalAsAttribute(UnmanagedType.LPStr)] string audioDevice);
 public AudioDeviceWatcher(AudioDeviceType ioType, Windows.UI.Core.CoreDispatcher dispatcher)
 {
     m_deviceType     = ioType;
     m_coreDispatcher = dispatcher;
     StartWatcher();
 }
예제 #28
0
 internal static extern int GetDeviceType(IntPtr device, out AudioDeviceType type);
예제 #29
0
        /// <summary>
        ///     Get the next device that need to be set as Default
        /// </summary>
        /// <param name="audioDevices"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        protected IAudioDevice GetNextDevice(ICollection <IAudioDevice> audioDevices, AudioDeviceType type)
        {
            IAudioDevice lastDevice;

            _lastDevices.TryGetValue(type, out lastDevice);

            var defaultDev = lastDevice ??
                             audioDevices.FirstOrDefault(device => device.IsDefault(Role.Console)) ??
                             audioDevices.Last();
            var next = audioDevices.SkipWhile((device, i) => !Equals(device, defaultDev)).Skip(1).FirstOrDefault() ??
                       audioDevices.ElementAt(0);

            return(next);
        }
예제 #30
0
        /// <summary>
        ///     Cycles the active device to the next device. Returns true if succesfully switched (at least
        ///     as far as we can tell), returns false if could not successfully switch. Throws NoDevicesException
        ///     if there are no devices configured.
        /// </summary>
        public bool CycleActiveDevice(AudioDeviceType type)
        {
            using (AppLogger.Log.InfoCall())
            {
                ICollection<IAudioDevice> list = null;
                string lastActive = null;
                switch (type)
                {
                    case AudioDeviceType.Playback:
                        list = AvailablePlaybackDevices;
                        lastActive = AppConfigs.Configuration.LastPlaybackActive;
                        break;
                    case AudioDeviceType.Recording:
                        list = AvailableRecordingDevices;
                        lastActive = AppConfigs.Configuration.LastRecordingActive;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }

                switch (list.Count)
                {
                    case 0:
                        ErrorTriggered?.Invoke(this, new ExceptionEvent(new NoDevicesException()));
                        return false;
                    case 1:
                        return false;
                }
                AppLogger.Log.Info("Cycle Audio Devices", list);
                var defaultDev = list.FirstOrDefault(device => device.FriendlyName == lastActive) ?? list.FirstOrDefault(device => device.IsDefault(Role.Console)) ?? list.ElementAt(0);
                var next = list.SkipWhile((device, i) => device != defaultDev).Skip(1).FirstOrDefault() ?? list.ElementAt(0);
                AppLogger.Log.Info("Select AudioDevice", next);
                return SetActiveDevice(next);
            }
        }
예제 #31
0
 public AudioOutputDevice(string name, string id, AudioDeviceType type)
 {
     Name       = name;
     Id         = id;
     DeviceType = type;
 }
예제 #32
0
        public bool SetHotkeyCombination(HotKeys hotkeys, AudioDeviceType deviceType)
        {
            using (AppLogger.Log.InfoCall())
            {
                HotKeys confHotKeys = null;
                switch (deviceType)
                {
                    case AudioDeviceType.Playback:
                        confHotKeys = AppConfigs.Configuration.PlaybackHotKeys;
                        break;
                    case AudioDeviceType.Recording:
                        confHotKeys = AppConfigs.Configuration.RecordingHotKeys;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null);
                }
                AppLogger.Log.Info("Unregister previous hotkeys", confHotKeys);
                WindowsAPIAdapter.UnRegisterHotKey(confHotKeys);

                if (!WindowsAPIAdapter.RegisterHotKey(hotkeys))
                {
                    AppLogger.Log.Warn("Can't register new hotkeys", hotkeys);
                    ErrorTriggered?.Invoke(this, new ExceptionEvent(new Exception("Impossible to register HotKey: " + hotkeys)));
                    return false;
                }

                AppLogger.Log.Info("New Hotkeys registered", hotkeys);
                switch (deviceType)
                {
                    case AudioDeviceType.Playback:
                        AppConfigs.Configuration.PlaybackHotKeys = hotkeys;
                        break;
                    case AudioDeviceType.Recording:
                        AppConfigs.Configuration.RecordingHotKeys = hotkeys;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null);
                }
                AppConfigs.Configuration.Save();
                return true;
            }
        }
예제 #33
0
        private void UpdateImageContextMenu(AudioDeviceType audioDeviceType, DeviceDefaultChangedEvent audioChangeEvent)
        {
            if (audioChangeEvent.role != Role.Console)
                return;

            foreach (
                var toolStripDevItem in
                    _selectionMenu.Items.OfType<ToolStripDeviceItem>().Where(item => item.AudioDevice.Type == audioDeviceType))
            {
                toolStripDevItem.Image = toolStripDevItem.AudioDevice.FriendlyName == audioChangeEvent.device.FriendlyName
                    ? Resources.Check
                    : null;
            }
        }
예제 #34
0
 /// <summary>
 ///     Cycle the audio device for the given type
 /// </summary>
 /// <param name="type"></param>
 public abstract bool CycleAudioDevice(AudioDeviceType type);
예제 #35
0
 public DeviceListChanged(IEnumerable<string> seletedDevicesList, AudioDeviceType type)
 {
     SeletedDevicesList = seletedDevicesList;
     Type = type;
 }
예제 #36
0
 /// <summary>
 ///     Cycles the active device to the next device. Returns true if succesfully switched (at least
 ///     as far as we can tell), returns false if could not successfully switch. Throws NoDevicesException
 ///     if there are no devices configured.
 /// </summary>
 public bool CycleActiveDevice(AudioDeviceType type)
 {
     using (AppLogger.Log.InfoCall())
     {
         try
         {
             return _deviceCyclerManager.CycleDevice(type);
         }
         catch (Exception exception)
         {
             ErrorTriggered?.Invoke(this, new ExceptionEvent(exception));
         }
         return false;
     }
 }
예제 #37
0
 /// <summary>
 /// Cycle the audio device
 /// </summary>
 /// <param name="type"></param>
 public bool CycleDevice(AudioDeviceType type)
 {
     return(_deviceCyclerFactory.Get(CurrentCycler).CycleAudioDevice(type));
 }
예제 #38
0
        private void ValidateStringIsDeviceName(string deviceName, ValidationResult result, AudioDeviceType deviceType = AudioDeviceType.Both)
        {
            bool deviceExists = MainAudio.Instance.DeviceExists(deviceName, deviceType);

            if (!deviceExists)
            {
                result.Errors.Add(new ValidationException("This selected device does not exist"));
                result.Status = ValidationResultStatus.Error;
            }
        }