/// <summary> /// Returns a list of the system's enabled audio input devices. Returns null if no enabled audio input devices are present. See also: Player.AudioInput.DeviceCount and Player.AudioInput.GetDefaultDevice. /// </summary> public AudioInputDevice[] GetDevices() { AudioInputDevice[] audioDevices = null; _base._lastError = HResult.MF_E_NO_AUDIO_RECORDING_DEVICE; IMMDeviceEnumerator deviceEnumerator = (IMMDeviceEnumerator) new MMDeviceEnumerator(); deviceEnumerator.EnumAudioEndpoints(EDataFlow.eCapture, (uint)DeviceState.Active, out IMMDeviceCollection deviceCollection); Marshal.ReleaseComObject(deviceEnumerator); if (deviceCollection != null) { deviceCollection.GetCount(out uint count); if (count > 0) { audioDevices = new AudioInputDevice[count]; for (int i = 0; i < count; i++) { audioDevices[i] = new AudioInputDevice(); deviceCollection.Item((uint)i, out IMMDevice device); Player.GetDeviceInfo(device, audioDevices[i]); Marshal.ReleaseComObject(device); } _base._lastError = Player.NO_ERROR; } Marshal.ReleaseComObject(deviceCollection); } return(audioDevices); }
// ******************************** Audio Devices - Audio Input Peak Meter - Open / Close / GetValues #region Audio Devices - Audio Input Peak Meter - Open / Close / GetValues internal bool InputMeter_Open(AudioInputDevice device, bool change) { // tested for null at event subscription if (!pm_HasInputMeter || change) { IMMDeviceEnumerator deviceEnumerator = null; IMMDevice levelDevice = null; if (pm_HasInputMeter) { InputMeter_Close(); } try { deviceEnumerator = (IMMDeviceEnumerator) new MMDeviceEnumerator(); deviceEnumerator.GetDevice(device._id, out levelDevice); if (levelDevice != null) { levelDevice.Activate(ref IID_IAudioMeterInformation, 3, IntPtr.Zero, out object levelDeviceInfo); pm_InputMeterInfo = (IAudioMeterInformation)levelDeviceInfo; pm_InputMeterInfo.GetMeteringChannelCount(out pm_InputMeterChannelCount); if (pm_InputMeterChannelCount > MAX_AUDIO_CHANNELS) { pm_InputMeterChannelCount = MAX_AUDIO_CHANNELS; } if (pm_InputMeterValues == null) { pm_InputMeterValues = new float[MAX_AUDIO_CHANNELS]; pm_InputMeterValuesStop = new float[MAX_AUDIO_CHANNELS]; for (int i = 0; i < MAX_AUDIO_CHANNELS; i++) { pm_InputMeterValuesStop[i] = STOP_VALUE; } } pm_HasInputMeter = true; //StartSystemDevicesChangedHandlerCheck(); } } catch { /* ignore */ } if (levelDevice != null) { Marshal.ReleaseComObject(levelDevice); } if (deviceEnumerator != null) { Marshal.ReleaseComObject(deviceEnumerator); } } return(pm_HasInputMeter); }
/// <summary> /// Returns the system's default audio input device. Returns null if no default audio input device is present. See also: Player.AudioInput.GetDevices. /// </summary> public AudioInputDevice GetDefaultDevice() { AudioInputDevice audioDevice = null; IMMDeviceEnumerator deviceEnumerator = (IMMDeviceEnumerator) new MMDeviceEnumerator(); deviceEnumerator.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia, out IMMDevice device); Marshal.ReleaseComObject(deviceEnumerator); if (device != null) { audioDevice = new AudioInputDevice(); Player.GetDeviceInfo(device, audioDevice); Marshal.ReleaseComObject(device); _base._lastError = Player.NO_ERROR; } else { _base._lastError = HResult.MF_E_NO_AUDIO_RECORDING_DEVICE; } return(audioDevice); }