如何設置音效卡麥克風音量

有關於C/C++的語法, 程式等
回覆文章
頭像
tim
文章: 1318
註冊時間: 2008年 11月 26日, 00:49

如何設置音效卡麥克風音量

文章 tim » 2008年 11月 27日, 16:39

在 vc++ 中利用 mmsystem 的 mixer control 來進行設置, 程式碼如下,

代碼: 選擇全部

     
    // include Mmsystem.h, link winmm.lib 
     
    void setMicVolume(DWORD ivalue)  // ivalue between 0 ~ 65535 
    { 
      HMIXER hmx; 
      MIXERLINE mxl; 
      DWORD j, cConnections, cChannels; 
      MIXERCONTROL mxc; 
      MIXERLINECONTROLS mxlc; 
      MIXERCONTROLDETAILS_UNSIGNED vol; 
      MIXERCONTROLDETAILS mxcd;    
     
      mixerOpen(&hmx, 0, 0, 0, 0); 
     
      mxl.cbStruct = sizeof(mxl); 
      mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN; 
      mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE); 
      cConnections = mxl.cConnections; 
      for(j=0;j<cConnections;j++) 
      { 
        mxl.dwSource = j; 
        mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE); 
        if(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE == mxl.dwComponentType) 
          break; 
      } 
       
      memset(&mxlc, 0, sizeof(MIXERLINECONTROLS)); 
      mxlc.cbStruct = sizeof(MIXERLINECONTROLS); 
      mxlc.dwLineID = mxl.dwLineID; 
      mxlc.dwControlID = MIXERCONTROL_CONTROLTYPE_VOLUME; 
      mxlc.cControls = 1; 
      mxlc.cbmxctrl = sizeof(MIXERCONTROL); 
      mxlc.pamxctrl = &mxc; 
     
      if(mixerGetLineControls((HMIXEROBJ)hmx, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)==0) 
      { 
        // found! 
        cChannels = mxl.cChannels; 
        if((mxc.fdwControl && MIXERCONTROL_CONTROLF_UNIform)==1)     
          cChannels = 1; 
     
        memset(&mxcd, 0, sizeof(MIXERCONTROLDETAILS)); 
        mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS); 
        mxcd.dwControlID = mxc.dwControlID; 
        mxcd.cChannels = cChannels; 
        mxcd.cMultipleItems = 0; 
        mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);   
        mxcd.paDetails = &vol; 
        vol.dwvalue = ivalue;   
     
        mixerSetControlDetails((HMIXEROBJ)hmx, &mxcd, MIXER_SETCONTROLDETAILSF_value); 
      } 
     
      mixerClose(hmx); 
       
    } 
附加檔案
5_50.zip
(805 Bytes) 已下載 434 次
多多留言, 整理文章, 把經驗累積下來.....

回覆文章