private static unsafe bool getMuteStatus(IntPtr mHMixer, uint controlId) { MMErrors errorCode = 0; IntPtr pUnsigned = IntPtr.Zero; bool status = false; try { // find the microphone source line connected to this wave in destination IntPtr pmxcdSelectValue = Marshal.AllocHGlobal((int)(1 * sizeof(MIXERCONTROLDETAILS_BOOLEAN))); MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS(); mxcd.cbStruct = (uint)sizeof(MIXERCONTROLDETAILS); mxcd.dwControlID = controlId; mxcd.cChannels = 1; mxcd.hwndOwner = IntPtr.Zero; mxcd.cbDetails = (uint)sizeof(MIXERCONTROLDETAILS_BOOLEAN); mxcd.paDetails = pmxcdSelectValue; unchecked { errorCode = (MMErrors)MixerNative.mixerGetControlDetails(mHMixer, ref mxcd, (MIXER_GETCONTROLDETAILSFLAG)(int)((uint)MIXER_OBJECTFLAG.HMIXER | (int)MIXER_GETCONTROLDETAILSFLAG.VALUE)); } if (errorCode != MMErrors.MMSYSERR_NOERROR) { throw new MixerException(errorCode, MicInterface.GetErrorDescription(FuncName.fnMixerGetControlDetails, errorCode)); } status = *((uint *)pmxcdSelectValue) != 0U; errorCode = (MMErrors)MixerNative.mixerSetControlDetails(mHMixer, ref mxcd, MIXER_SETCONTROLDETAILSFLAG.VALUE); if (errorCode != MMErrors.MMSYSERR_NOERROR) { throw new MixerException(errorCode, MicInterface.GetErrorDescription(FuncName.fnMixerSetControlDetails, errorCode)); } } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { if (pUnsigned != IntPtr.Zero) { Marshal.FreeHGlobal(pUnsigned); } } return(status); }
public static unsafe void MuteOrUnMuteAllMics(bool mute) { IntPtr mHMixer = IntPtr.Zero; try { uint dwDestination; unchecked { dwDestination = (uint)-1; } int iNumDevs = MixerNative.mixerGetNumDevs(); for (int i = 0; i < iNumDevs; i++) { MixerNative.mixerOpen(out mHMixer, i, IntPtr.Zero /*mCallbackWindow.Handle*/, IntPtr.Zero, MixerNative.CALLBACK_WINDOW); // Get the line info for the wave in destination line MIXERLINE mxl = new MIXERLINE(); // find the microphone source line connected to this wave in destination IntPtr pmc = IntPtr.Zero; MMErrors errorCode = 0; mxl.cbStruct = (uint)Marshal.SizeOf(mxl); mxl.dwComponentType = MIXERLINE_COMPONENTTYPE.DST_SPEAKERS; if (MixerNative.mixerGetLineInfo(mHMixer, ref mxl, MIXER_GETLINEINFOF.COMPONENTTYPE) == 0) { dwDestination = mxl.dwDestination; int cConnections = (int)mxl.cConnections; for (uint j = 0; j < cConnections; j++) { mxl.cbStruct = (uint)Marshal.SizeOf(mxl); mxl.dwDestination = dwDestination; mxl.dwSource = (uint)j; mxl.dwComponentType = MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE; if (MixerNative.mixerGetLineInfo(mHMixer, ref mxl, MIXER_GETLINEINFOF.SOURCE) == 0) { if (mxl.dwComponentType == MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE) { //it is a microphone pmc = Marshal.AllocHGlobal((int)(Marshal.SizeOf(typeof(MIXERCONTROL)) * mxl.cControls)); MIXERLINECONTROLS mlc = new MIXERLINECONTROLS(); mlc.cbStruct = (uint)sizeof(MIXERLINECONTROLS); mlc.dwLineID = mxl.dwLineID; mlc.cControls = mxl.cControls; mlc.pamxctrl = pmc; mlc.cbmxctrl = (uint)(Marshal.SizeOf(typeof(MIXERCONTROL))); mlc.dwControlType = MIXERCONTROL_CONTROLTYPE.MUTE; errorCode = (MMErrors)MixerNative.mixerGetLineControls(mHMixer, ref mlc, MIXER_GETLINECONTROLSFLAG.ALL); for (int k = 0; k < mlc.cControls; k++) { MIXERCONTROL mc = (MIXERCONTROL)Marshal.PtrToStructure((IntPtr)(((byte *)pmc) + (Marshal.SizeOf(typeof(MIXERCONTROL)) * k)), typeof(MIXERCONTROL)); if (mc.dwControlType == (uint)MIXERCONTROL_CONTROLTYPE.MUTE) { MicInterface.muteOrUnMuteMixerControl(mute, mHMixer, mc.dwControlID); } } } } } } } } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { if (mHMixer != IntPtr.Zero) { MixerNative.mixerClose(mHMixer); } } }
public static unsafe String[] SearchDevices() { List <String> devices = new List <string>(); IntPtr mHMixer = IntPtr.Zero; try { uint dwDestination; unchecked { dwDestination = (uint)-1; } int iNumDevs = MixerNative.mixerGetNumDevs(); for (int i = 0; i < iNumDevs; i++) { MixerNative.mixerOpen(out mHMixer, i, IntPtr.Zero /*mCallbackWindow.Handle*/, IntPtr.Zero, MixerNative.CALLBACK_WINDOW); // Get the line info for the wave in destination line MIXERLINE mxl = new MIXERLINE(); // find the microphone source line connected to this wave in destination IntPtr pmc = IntPtr.Zero; mxl.cbStruct = (uint)Marshal.SizeOf(mxl); mxl.dwComponentType = MIXERLINE_COMPONENTTYPE.DST_SPEAKERS; if (MixerNative.mixerGetLineInfo(mHMixer, ref mxl, MIXER_GETLINEINFOF.COMPONENTTYPE) == 0) { dwDestination = mxl.dwDestination; int cConnections = (int)mxl.cConnections; for (uint j = 0; j < cConnections; j++) { mxl.cbStruct = (uint)Marshal.SizeOf(mxl); mxl.dwDestination = dwDestination; mxl.dwSource = (uint)j; mxl.dwComponentType = MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE; if (MixerNative.mixerGetLineInfo(mHMixer, ref mxl, MIXER_GETLINEINFOF.SOURCE) == 0) { if (mxl.dwComponentType == MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE) { //it is a microphone devices.Add(mxl.dwLineID.ToString()); } } } } } } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { if (mHMixer != IntPtr.Zero) { MixerNative.mixerClose(mHMixer); } } return(devices.ToArray()); }