• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
Visual C++ Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
Visual C++ Developer Center > Visual C++ Forums > Visual C++ General > problem on recording sound
Ask a questionAsk a question
Search Forums:
  • Search Visual C++ General Forum Search Visual C++ General Forum
  • Search All Visual C++ Forums Search All Visual C++ Forums
  • Search All MSDN Forums Search All MSDN Forums
 

Answerproblem on recording sound

  • Wednesday, February 13, 2008 6:10 AMbertpu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Hello,
    My application needs to record the sound of the microphone. But, I am
    worrying the user may set the microphone input volume mute by accident. So I
    want to use some codes to check it and set the volume of microphone input
    maximum.
    Is there any API to do this?

    Thanks

    • ReplyReply
    • QuoteQuote
     

Answers

  • Wednesday, February 13, 2008 5:42 PMAliRafieeMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0

    You will need to use the Mixer functions, MixerGetControlDetail and MixerSetControlDetail.

     

    See if this helps.

    http://www.codeguru.com/cpp/g-m/multimedia/audio/article.php/c1561/

     

    AliR.

     

     

    • ReplyReply
    • QuoteQuote
     

All Replies

  • Thursday, February 14, 2008 1:13 AMbertpu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    When I build the project, an error occured:

    c:\program files\microsoft visual studio\vc98\include\mmsystem.h(113) : error C2146: syntax error : missing ';' before identifier 'MMVERSION'
    c:\program files\microsoft visual studio\vc98\include\mmsystem.h(113) : fatal error C1004: unexpected end of file found

     

    What is the problem?

    Thanks
    • ReplyReply
    • QuoteQuote
     
  • Thursday, February 14, 2008 12:27 PMbertpu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Hello,

     

    Now, I have solved the above problem by some other articles, but I have a new problem.

     

    I can control the output volume with the codes provided by the above article, but I still can't change the input volume. How can I change the input volume?

     

    Thanks.

    • ReplyReply
    • QuoteQuote
     
  • Thursday, February 14, 2008 4:09 PMAliRafieeMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Pass MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE to these functions for the microphone volume.  See the help for MIXERLINE struct for other possible values.  The dwVolume range is from 0 to 0xFFFF

     

     

    Code Snippet

    void SetVolume(DWORD OfWhichDevice, DWORD dwVolume )

    {

    MMRESULT result;

    HMIXER hMixer;

    MIXERLINE ml = {0};

    MIXERLINECONTROLS mlc = {0};

    MIXERCONTROL mc = {0};

    MIXERCONTROLDETAILS mcd = {0};

    MIXERCONTROLDETAILS_UNSIGNED mcdu = {0};

     

    // get a handle to the mixer device

    result = mixerOpen(&hMixer, MIXER_OBJECTF_MIXER, 0, 0, 0);

    if (MMSYSERR_NOERROR == result)

    {

    ml.cbStruct = sizeof(MIXERLINE);

    ml.dwComponentType = OfWhichDevice;

    // get the speaker line of the mixer device

    result = mixerGetLineInfo((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE);

    if (MMSYSERR_NOERROR == result)

    {

    mlc.cbStruct = sizeof(MIXERLINECONTROLS);

    mlc.dwLineID = ml.dwLineID;

    mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;

    mlc.cControls = 1;

    mlc.pamxctrl = &mc;

    mlc.cbmxctrl = sizeof(MIXERCONTROL);

    // get the volume controls associated with the speaker line

    result = mixerGetLineControls((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);

    if (MMSYSERR_NOERROR == result)

    {

    mcdu.dwValue = dwVolume;

    mcd.cbStruct = sizeof(MIXERCONTROLDETAILS);

    mcd.hwndOwner = 0;

    mcd.dwControlID = mc.dwControlID;

    mcd.paDetails = &mcdu;

    mcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);

    mcd.cChannels = 1;

    // set the volume

    result = mixerSetControlDetails((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE);

    if (MMSYSERR_NOERROR == result)

    AfxMessageBox("Volume changed!");

    else

    AfxMessageBox("mixerSetControlDetails() failed");

    }

    else

    AfxMessageBox("mixerGetLineControls() failed");

    }

    else

    AfxMessageBox("mixerGetLineInfo() failed");

    mixerClose(hMixer);

    }

    else

    AfxMessageBox("mixerOpen() failed");

    }

    //====================================================================

    DWORD GetVolume( DWORD OfWhichDevice)

    {

    DWORD dwVolume = -1;

    MMRESULT result;

    HMIXER hMixer;

    MIXERLINE ml = {0};

    MIXERLINECONTROLS mlc = {0};

    MIXERCONTROL mc = {0};

    MIXERCONTROLDETAILS mcd = {0};

    MIXERCONTROLDETAILS_UNSIGNED mcdu = {0};

     

    // get a handle to the mixer device

    result = mixerOpen(&hMixer, 0, 0, 0, MIXER_OBJECTF_HMIXER);

    if (MMSYSERR_NOERROR == result)

    {

    ml.cbStruct = sizeof(MIXERLINE);

    ml.dwComponentType = OfWhichDevice;

    // get the speaker line of the mixer device

    result = mixerGetLineInfo((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE);

    if (MMSYSERR_NOERROR == result)

    {

    mlc.cbStruct = sizeof(MIXERLINECONTROLS);

    mlc.dwLineID = ml.dwLineID;

    mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;

    mlc.cControls = 1;

    mlc.pamxctrl = &mc;

    mlc.cbmxctrl = sizeof(MIXERCONTROL);

    // get the volume controls associated with the speaker line

    result = mixerGetLineControls((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);

    if (MMSYSERR_NOERROR == result)

    {

    mcd.cbStruct = sizeof(MIXERCONTROLDETAILS);

    mcd.hwndOwner = 0;

    mcd.dwControlID = mc.dwControlID;

    mcd.paDetails = &mcdu;

    mcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);

    mcd.cChannels = 1;

    // get the volume

    result = mixerGetControlDetails((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE);

    if (MMSYSERR_NOERROR == result)

    dwVolume = mcdu.dwValue;

    else

    AfxMessageBox("mixerGetControlDetails() failed");

    }

    else

    AfxMessageBox("mixerGetLineControls() failed");

    }

    else

    AfxMessageBox("mixerGetLineInfo() failed");

    mixerClose(hMixer);

    }

    else

    AfxMessageBox("mixerOpen() failed");

    return (dwVolume);

    }

     

    • ReplyReply
    • QuoteQuote
     
  • Friday, February 15, 2008 3:27 AMbertpu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

     

    Thanks.

    But when I invoked SetVolume(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE,0);, it told me mixerGetLineInfo() failed.

     

    And because of the restriction of my sound card, I can't change the microphone input volume in the control panel neither. I can only change the leftmost volume in the "Realtek HD Audio Input", maybe it is called "Recording Control" in English.(My OS is not a english version). How can I change the "recording control" volume? What argument should I pass to the SetVolume method?
    • ReplyReply
    • QuoteQuote
     
  • Friday, February 15, 2008 3:30 PMAliRafieeMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Look at the help for MIXERLINE, try passing in different values of dwComponentType to Get/SetVolume and see if any of them help.  Otherwise I am out of suggestions.

     

    mabye MIXERLINE_COMPONENTTYPE_DST_DIGITAL or MIXERLINE_COMPONENTTYPE_DST_LINE

     

    AliR.

     

    • ReplyReply
    • QuoteQuote
     
  • Saturday, February 16, 2008 12:50 AMbertpu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Unfortunately, I have tried all the values and they all didn't work

    • ReplyReply
    • QuoteQuote
     
  • Friday, May 16, 2008 6:03 PMCord02 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Was anyone able to resolve this? This is the exact same problem I am experiencing.

     

    I can control all the audio sources and destination on the Volume Control except for the "Line Volume" and "Mic Volume" when selecting the Realtek HD Audio Input as the Mixer device.

     

    http://www.teamsoftwaresolutions.com/picts/realtek.gif

     

    Any information would be appreciated.

     

    • ReplyReply
    • QuoteQuote
     
  • Tuesday, March 03, 2009 9:58 PMcoachjack Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    Hi, I am having same Error using the MMSystem.   

    mmsystem.h(113) : error C2146: syntax error : missing ';'

    What did you do to resolve your compiler error?

    Thanks
    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement