コード例 #1
0
        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());
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
ファイル: MixerNative.cs プロジェクト: fbarresi/antiblues
 internal static extern int mixerGetLineInfo(IntPtr hmxobj, ref MIXERLINE pmxl, MIXER_GETLINEINFOF fdwInfo);