Thread: How to mute microphone in mixer?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Here is a little function, assembled from code in a CodeProject article.
    Code:
    #include <windows.h>
    
    #if defined(_MSC_VER)
    #pragma comment(lib, "Winmm.lib")
    #endif
    
    /* 
     * Function to mute or unmute the system microphone.
     * Arg: fMute - TRUE to mute, FALSE to unmute.
     */
    BOOL MuteMicrophone(BOOL fMute)
    {
    	MMRESULT                    result   = 0;
    	HMIXER                      hMixer   = 0;
    	MIXERLINE                   ml       = { 0 };
    	MIXERLINECONTROLS           mlc      = { 0 };
    	MIXERCONTROL                mc       = { 0 };
    	MIXERCONTROLDETAILS_BOOLEAN mcb      = { 0 };
    	MIXERCONTROLDETAILS         mcd      = { 0 };
    
    	result = mixerOpen(&hMixer, MIXER_OBJECTF_MIXER, 0, 0, 0);
    
    	ml.cbStruct        = sizeof(MIXERLINE);
    	ml.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE ;
    	result = mixerGetLineInfo((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE);
    
    	mlc.cbStruct      = sizeof(MIXERLINECONTROLS);
    	mlc.dwLineID      = ml.dwLineID;
    	mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
    	mlc.cControls     = 1;
    	mlc.pamxctrl      = &mc;
    	mlc.cbmxctrl      = sizeof(MIXERCONTROL);
    	result = mixerGetLineControls((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
    
    	mcd.cbStruct    = sizeof(MIXERCONTROLDETAILS);
    	mcd.hwndOwner   = NULL;
    	mcd.dwControlID = mc.dwControlID;
    	mcb.fValue      = fMute;
    	mcd.paDetails   = &mcb;
    	mcd.cbDetails   = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
    	mcd.cChannels   = 1;
    	result = mixerSetControlDetails((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE);
    
    	mixerClose(hMixer);
    
    	return (result == MMSYSERR_NOERROR ? TRUE : FALSE);
    
    }
    
    int main(void)
    {
    	MuteMicrophone(TRUE);
    
    	return 0;
    }
    The Mixer API has got to be the messiest API in Win32. I can only assume that is was designed by the work experience kid while he was smoking some seriously good stuff.

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    265
    Its my understanding that SRC_MICROPHONE will only mute/unmute the ECHO of whats entered. Correct me if im wrong here. Im trying to shut off the microphones input to the system.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by DeepBlackMagic
    Its my understanding that SRC_MICROPHONE will only mute/unmute the ECHO of whats entered. Correct me if im wrong here. Im trying to shut off the microphones input to the system.
    I'm not sure. Can you try it? I don't have a microphone handy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Playback microphone through DBS
    By hdragon in forum Tech Board
    Replies: 0
    Last Post: 06-11-2007, 02:38 PM
  2. computer microphone?
    By Waldo2k2 in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-26-2002, 04:22 PM
  3. MFC/Win32 MicroPhone Mute
    By Moshe Bergman in forum Windows Programming
    Replies: 0
    Last Post: 10-28-2002, 02:50 PM
  4. Microphone recognition...
    By weraw in forum C Programming
    Replies: 2
    Last Post: 12-26-2001, 11:11 AM