Thread: How to mute microphone in mixer?

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    265

    How to mute microphone in mixer?

    Hey guys,

    Im looking for a quick way to send a message to the windows audio mixer instructing it to either mute or unmute the microphone (This is for a push-to-talk button)

    Thanks for your time, any help would be greatly appreciated.


    P.S. Im not using any .NETrash.

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    265
    Im trying to edit some existing code, however im having troubles finding the right control.

    Controls like: MIXERLINE_COMPONENTTYPE_DST_WAVEIN and MIXERLINE_COMPONENTTYPE_DST_MICROPHONE come back as non-existant. (Code compiles fine, runs fine, etc. Just cant find the control i want)

    If you know how to get a handle on the microphones input mute please let me know.

  3. #3
    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.

  4. #4
    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.

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    265
    I guess i should clarify where im at right now: I cant get a working MIXERCONTROL_CONTROLTYPE_MUTE of my MIXERLINE_COMPONENTTYPE_DST_WAVEIN. I dont know how to mute that componenttype. I think im close but im probablly doing something wrong. I can get a mixercontrol_controltype_mux but not mute =*(

  6. #6
    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.

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by DeepBlackMagic
    I guess i should clarify where im at right now: I cant get a working MIXERCONTROL_CONTROLTYPE_MUTE of my MIXERLINE_COMPONENTTYPE_DST_WAVEIN. I dont know how to mute that componenttype. I think im close but im probablly doing something wrong. I can get a mixercontrol_controltype_mux but not mute =*(
    Have you tried using my code, just with MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE changed to MIXERLINE_COMPONENTTYPE_DST_WAVEIN?

  8. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    265
    Yes i have changed SRC_MIC to DST_WAVEIN, doesnt mute the mic at all.

    I cant seem to get a MUTE control on the DST_WAVEIN. I have tried it on both your code and mine now. There has to be some sort of trick to this, maybe one of the day people see what im missing? Idk, my 4am code is never very good =P

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