public VolumeControl(int deviceNumber) { waveIn = new WaveIn(); waveIn.DeviceNumber = deviceNumber; // waveIn.DataAvailable += waveIn_DataAvailable; // waveIn.StartRecording(); int waveInDeviceNumber = waveIn.DeviceNumber; if (Environment.OSVersion.Version.Major >= 6) // Vista and over { var mixerLine = waveIn.GetMixerLine(); //new MixerLine((IntPtr)waveInDeviceNumber, 0, MixerFlags.WaveIn); foreach (var control in mixerLine.Controls.Where(control => control.ControlType == MixerControlType.Volume)) { this.volumeControl = control as UnsignedMixerControl; //Level = desiredVolume; break; } } else { var mixer = new Mixer(waveInDeviceNumber); foreach (var source in from destination in mixer.Destinations where destination.ComponentType == MixerLineComponentType.DestinationWaveIn from source in destination.Sources where source.ComponentType == MixerLineComponentType.SourceMicrophone select source) { foreach (var control in source.Controls.Where(control => control.ControlType == MixerControlType.Volume)) { volumeControl = control as UnsignedMixerControl; //Level = desiredVolume; break; } } } }
private static void ExploreMixerDevice(int deviceIndex) { Mixer mixer = new Mixer(deviceIndex); Debug.WriteLine(String.Format("Device {0}: {1}",deviceIndex,mixer.Name)); Debug.WriteLine("--------------------------------------------"); int destinations = mixer.DestinationCount; Assert.That(destinations > 0, "Expected at least one destination"); for (int destinationIndex = 0; destinationIndex < destinations; destinationIndex++) { ExploreMixerDestination(mixer, destinationIndex); } }
private static void ExploreMixerDestination(Mixer mixer, int destinationIndex) { var destination = mixer.GetDestination(destinationIndex); Debug.WriteLine(String.Format("Destination {0}: {1}", destinationIndex, destination)); int channels = destination.Channels; foreach (MixerControl control in destination.Controls) { Debug.WriteLine(String.Format("CONTROL: {0}", control)); } int sources = destination.SourceCount; for (int sourceIndex = 0; sourceIndex < sources; sourceIndex++) { ExploreMixerSource(destination, sourceIndex); } }
public void CanFindDefaultWaveIn() { int defaultWaveInMixerId = MixerLine.GetMixerIdForWaveIn(0); Mixer mixer = new Mixer(defaultWaveInMixerId); foreach (MixerLine destination in mixer.Destinations) { Debug.WriteLine(String.Format("DESTINATION: {0} {1} (Type: {2}, Target: {3})", destination.Name, destination.TypeDescription, destination.ComponentType, destination.TargetName)); if (destination.ComponentType == MixerLineComponentType.DestinationWaveIn) { foreach (MixerLine source in destination.Sources) { Debug.WriteLine(String.Format("{0} {1} (Source: {2}, Target: {3})", source.Name, source.TypeDescription, source.IsSource, source.TargetName)); if (source.ComponentType == MixerLineComponentType.SourceMicrophone) { Debug.WriteLine(String.Format("Found the microphone: {0}", source.Name)); foreach (MixerControl control in source.Controls) { if (control.ControlType == MixerControlType.Volume) { Debug.WriteLine(String.Format("Volume Found: {0}", control)); UnsignedMixerControl umc = (UnsignedMixerControl)control; uint originalValue = umc.Value; umc.Value = umc.MinValue; Assert.AreEqual(umc.MinValue, umc.Value, "Set Minimum Correctly"); umc.Value = umc.MaxValue; Assert.AreEqual(umc.MaxValue, umc.Value, "Set Maximum Correctly"); umc.Value = umc.MaxValue / 2; Assert.AreEqual(umc.MaxValue / 2, umc.Value, "Set MidPoint Correctly"); umc.Value = originalValue; Assert.AreEqual(originalValue, umc.Value, "Set Original Correctly"); } } } } } } }
private void TryGetVolumeControl() { int waveInDeviceNumber = _waveIn.DeviceNumber; if (Environment.OSVersion.Version.Major >= 6) { var mixerLine = _waveIn.GetMixerLine(); foreach (var control in mixerLine.Controls) { if (VolumeAndMicLevelAssigned(control)) break; } } else { var mixer = new Mixer(waveInDeviceNumber); foreach (var destination in mixer.Destinations) { if (destination.ComponentType == MixerLineComponentType.DestinationWaveIn) { foreach (var source in destination.Sources) { if (source.ComponentType == MixerLineComponentType.SourceMicrophone) { foreach (var control in source.Controls) { if (VolumeAndMicLevelAssigned(control)) break; } } } } } } }
private void TryGetVolumeControl() { int waveInDeviceNumber = waveIn.DeviceNumber; if (Environment.OSVersion.Version.Major >= 6) // Vista and over { var mixerLine = waveIn.GetMixerLine(); //new MixerLine((IntPtr)waveInDeviceNumber, 0, MixerFlags.WaveIn); foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { this.volumeControl = control as UnsignedMixerControl; MicrophoneLevel = desiredVolume; break; } } } else { var mixer = new Mixer(waveInDeviceNumber); foreach (var destination in mixer.Destinations) { if (destination.ComponentType == MixerLineComponentType.DestinationWaveIn) { foreach (var source in destination.Sources) { if (source.ComponentType == MixerLineComponentType.SourceMicrophone) { foreach (var control in source.Controls) { if (control.ControlType == MixerControlType.Volume) { volumeControl = control as UnsignedMixerControl; MicrophoneLevel = desiredVolume; break; } } } } } } } }
private void TryGetVolumeControl() { if (Wave == null) return; try { int waveInDeviceNumber = Wave.DeviceNumber; if (Environment.OSVersion.Version.Major >= 6) // Vista and over { var mixerLine = Wave.GetMixerLine(); foreach (var control in mixerLine.Controls) { Common.DebugHelper.WriteLine("{0} Mixer Line Control {1} [{2}]", mixerLine.Name, control.Name, control.ControlType); } foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { if (control.IsUnsigned) { try { this.volumeControl = control as UnsignedMixerControl; break; } catch { this.volumeControl = null; } } else if (control.IsSigned) { try { this.altVolumeControl = control as SignedMixerControl; } catch { this.altVolumeControl = null; } } } } } else { var mixer = new Mixer(waveInDeviceNumber); foreach (var destination in mixer.Destinations.Where(d => d.ComponentType == MixerLineComponentType.DestinationWaveIn)) { foreach (var source in destination.Sources .Where(source => source.ComponentType == MixerLineComponentType.SourceMicrophone)) { foreach (var control in source.Controls .Where(control => control.ControlType == MixerControlType.Volume)) { if (control.IsUnsigned) { try { volumeControl = control as UnsignedMixerControl; break; } catch { volumeControl = null; } } else if (control.IsSigned) { try { this.altVolumeControl = control as SignedMixerControl; } catch { this.altVolumeControl = null; } } } } } } } catch { volumeControl = null; altVolumeControl = null; } }
protected static UnsignedMixerControl GetVolumeMixerControlForOutputLine(Mixer mixer) { foreach (var mixerline in mixer.Destinations) { if (mixerline.ComponentType == MixerLineComponentType.DestinationSpeakers || mixerline.ComponentType == MixerLineComponentType.DestinationDigital || mixerline.ComponentType == MixerLineComponentType.DestinationHeadphones ) foreach (MixerLine source in mixerline.Sources) { if (source.ComponentType == MixerLineComponentType.SourceWaveOut) { foreach (MixerControl control in source.Controls) { if (control.ControlType == MixerControlType.Volume) return (UnsignedMixerControl)control; } } } } return null; }