/// <summary> /// Gets all the mixer controls /// </summary> /// <param name="mixerHandle"></param> /// <param name="mixerLine"></param> /// <param name="mixerHandleType"></param> /// <returns></returns> public static IList <MixerControl> GetMixerControls(IntPtr mixerHandle, MixerLine mixerLine, MixerFlags mixerHandleType) { List <MixerControl> controls = new List <MixerControl>(); if (mixerLine.ControlsCount > 0) { int mixerControlSize = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL)); MixerInterop.MIXERLINECONTROLS mlc = new MixerInterop.MIXERLINECONTROLS(); IntPtr pmc = Marshal.AllocHGlobal(mixerControlSize * mixerLine.ControlsCount); mlc.cbStruct = Marshal.SizeOf(mlc); mlc.dwLineID = mixerLine.LineId; mlc.cControls = mixerLine.ControlsCount; mlc.pamxctrl = pmc; mlc.cbmxctrl = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL)); MmResult err = MixerInterop.mixerGetLineControls(mixerHandle, ref mlc, MixerFlags.All | mixerHandleType); if (err != MmResult.NoError) { Marshal.FreeHGlobal(pmc); throw new MmException(err, "mixerGetLineControls"); } for (int i = 0; i < mlc.cControls; i++) { Int64 address = pmc.ToInt64() + mixerControlSize * i; MixerInterop.MIXERCONTROL mc = (MixerInterop.MIXERCONTROL)Marshal.PtrToStructure((IntPtr)address, typeof(MixerInterop.MIXERCONTROL)); MixerControl mixerControl = MixerControl.GetMixerControl(mixerHandle, mixerLine.LineId, mc.dwControlID, mixerLine.Channels, mixerHandleType); controls.Add(mixerControl); } } return(controls); }
/// <summary> /// Gets all the mixer controls /// </summary> /// <param name="mixerHandle"></param> /// <param name="mixerLine"></param> /// <param name="mixerHandleType"></param> /// <returns></returns> public static IList<MixerControl> GetMixerControls(IntPtr mixerHandle, MixerLine mixerLine, MixerFlags mixerHandleType) { List<MixerControl> controls = new List<MixerControl>(); if (mixerLine.ControlsCount > 0) { int mixerControlSize = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL)); MixerInterop.MIXERLINECONTROLS mlc = new MixerInterop.MIXERLINECONTROLS(); IntPtr pmc = Marshal.AllocHGlobal(mixerControlSize * mixerLine.ControlsCount); mlc.cbStruct = Marshal.SizeOf(mlc); mlc.dwLineID = mixerLine.LineId; mlc.cControls = mixerLine.ControlsCount; mlc.pamxctrl = pmc; mlc.cbmxctrl = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL)); MmResult err = MixerInterop.mixerGetLineControls(mixerHandle, ref mlc, MixerFlags.All | mixerHandleType); if (err != MmResult.NoError) { Marshal.FreeHGlobal(pmc); throw new MmException(err, "mixerGetLineControls"); } for (int i = 0; i < mlc.cControls; i++) { Int64 address = pmc.ToInt64() + mixerControlSize * i; MixerInterop.MIXERCONTROL mc = (MixerInterop.MIXERCONTROL)Marshal.PtrToStructure((IntPtr)address, typeof(MixerInterop.MIXERCONTROL)); MixerControl mixerControl = MixerControl.GetMixerControl(mixerHandle, mixerLine.LineId, mc.dwControlID, mixerLine.Channels, mixerHandleType); controls.Add(mixerControl); } } return controls; }
public static void TrySetVolumeControl(MixerLine mixerLine, int value) { foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { var volumeControl = control as UnsignedMixerControl; if (volumeControl != null) volumeControl.Percent = value; break; } } }
/// <summary> /// Gets all the mixer controls /// </summary> /// <param name="mixerHandle">Mixer Handle</param> /// <param name="mixerLine">Mixer Line</param> /// <param name="mixerHandleType">Mixer Handle Type</param> /// <returns></returns> // Token: 0x060005CB RID: 1483 RVA: 0x00012C9C File Offset: 0x00010E9C public static IList <MixerControl> GetMixerControls(IntPtr mixerHandle, MixerLine mixerLine, MixerFlags mixerHandleType) { List <MixerControl> list = new List <MixerControl>(); if (mixerLine.ControlsCount > 0) { int num = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL)); MixerInterop.MIXERLINECONTROLS mixerlinecontrols = default(MixerInterop.MIXERLINECONTROLS); IntPtr intPtr = Marshal.AllocHGlobal(num * mixerLine.ControlsCount); mixerlinecontrols.cbStruct = Marshal.SizeOf(mixerlinecontrols); mixerlinecontrols.dwLineID = mixerLine.LineId; mixerlinecontrols.cControls = mixerLine.ControlsCount; mixerlinecontrols.pamxctrl = intPtr; mixerlinecontrols.cbmxctrl = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL)); try { MmResult mmResult = MixerInterop.mixerGetLineControls(mixerHandle, ref mixerlinecontrols, mixerHandleType); if (mmResult != MmResult.NoError) { throw new MmException(mmResult, "mixerGetLineControls"); } for (int i = 0; i < mixerlinecontrols.cControls; i++) { long value = intPtr.ToInt64() + (long)(num * i); MixerInterop.MIXERCONTROL mixercontrol = (MixerInterop.MIXERCONTROL)Marshal.PtrToStructure((IntPtr)value, typeof(MixerInterop.MIXERCONTROL)); MixerControl item = MixerControl.GetMixerControl(mixerHandle, mixerLine.LineId, mixercontrol.dwControlID, mixerLine.Channels, mixerHandleType); list.Add(item); } } finally { Marshal.FreeHGlobal(intPtr); } } return(list); }
/// <summary> /// Microphone Level /// </summary> public MixerLine GetMixerLine() { // TODO use mixerGetID instead to see if this helps with XP MixerLine mixerLine; if (waveInHandle != IntPtr.Zero) { mixerLine = new MixerLine(this.waveInHandle, 0, MixerFlags.WaveInHandle); } else { mixerLine = new MixerLine((IntPtr)DeviceNumber, 0, MixerFlags.WaveIn); } return mixerLine; }
private void TryGetVolumeControl(int deviceNumber , int i) { int waveInDeviceNumber = deviceNumber; var mixerLine = new MixerLine((IntPtr)waveInDeviceNumber, 0, MixerFlags.WaveIn); foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { if(i == 1) volumeControl1 = control as UnsignedMixerControl; if(i == 2) volumeControl2 = control as UnsignedMixerControl; break; } } }
private static void ExploreMixerSource(MixerLine destinationLine, int sourceIndex) { var sourceLine = destinationLine.GetSource(sourceIndex); Debug.WriteLine(String.Format("Source {0}: {1}", sourceIndex, sourceLine)); foreach (MixerControl control in sourceLine.Controls) { Debug.WriteLine(String.Format("CONTROL: {0}", control)); } }
private void initializeMic(int deviceNumber) { var mic = WaveIn.GetCapabilities(deviceNumber); var mixerLine = new MixerLine((IntPtr)deviceNumber, 0, MixerFlags.WaveIn); foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { _micVolumeControl = control as UnsignedMixerControl; break; } } }
protected static UnsignedMixerControl GetVolumeMixerControlForInputLine(MixerLine destination) { if (destination.ComponentType == MixerLineComponentType.DestinationWaveIn) foreach (MixerLine source in destination.Sources) { if (source.ComponentType == MixerLineComponentType.SourceMicrophone) { foreach (MixerControl control in source.Controls) { if (control.ControlType == MixerControlType.Volume) return (UnsignedMixerControl)control; } } } return null; }