線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:4123
推到 Plurk!
推到 Facebook!

麥克風的輸入音量無法調

答題得分者是:allenchan
asvmfd
一般會員


發表:46
回覆:30
積分:15
註冊:2004-11-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-12-02 00:44:45 IP:61.219.xxx.xxx 未訂閱
請教各位, 做一個TrackBar來調,有看到Caption的值有變化,但是同時錄的聲音好像也沒變大聲... 是問題出在哪? Thanks 如下程式擷錄自http://delphi.ktop.com.tw/topic.php?TOPIC_ID=60600
 
//---------------------------------------------------------------------------    #ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include 
#include 
#include 
#include <Forms.hpp>
#include 
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:        // IDE-managed Components
        TTrackBar *TrackBar1;
        TTrackBar *TrackBar2;
        TLabel *Label1;            void __fastcall FormShow(TObject *Sender);
        void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
        void __fastcall TrackBar2Change(TObject *Sender);
private:        // User declarations    public:                // User declarations
        __fastcall TForm1(TComponent* Owner);
        bool TForm1::SetMicrophoneVolume( unsigned int bValue );
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif    void __fastcall TForm1::FormShow(TObject *Sender)
{
DWORD volume;
TrackBar1->Max = 0xFFFF;
TrackBar1->Frequency = 1000;
TrackBar2->Max = 0xFFFF;
TrackBar2->Frequency = 1000;    TrackBar1->Position = waveOutGetVolume(0, &volume);
TrackBar1->Position = 0xFFFF - LOWORD(volume);
volume_org=volume;
}    void __fastcall TForm1::TrackBar2Change(TObject *Sender)
{    int value = 0xFFFF - TrackBar2->Position;
//waveOutSetVolume(0, MAKELONG(0xFFFF - TrackBar1->Position, 0xFFFF - TrackBar1->Position));
//SetMicrophoneVolume(MAKELONG(0xFFFF - TrackBar2->Position);
SetMicrophoneVolume( value);
 Label1->Caption=IntToStr(value);
}    //設定 麥克風的音量 0 ~ 65535
bool TForm1::SetMicrophoneVolume(unsigned int bValue)
{
    HMIXER hMix;
    MIXERLINECONTROLS mxlc;
    MIXERCONTROLDETAILS mxcd;
    MIXERCONTROLDETAILS_UNSIGNED vol;
    MIXERCONTROL mxc;
    MIXERLINE mxl;
    int intRet;
    int nMixerDevs;        // Check if Mixer is available
    nMixerDevs = mixerGetNumDevs();
    if (nMixerDevs < 1) return false;        // open the mixer
    intRet = mixerOpen(&hMix, 0, 0, 0, 0);
    if (intRet != MMSYSERR_NOERROR) return false;        try {
        mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
        mxl.cbStruct = sizeof(mxl);            // get line info
        intRet = mixerGetLineInfo(hMix, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);            if (intRet == MMSYSERR_NOERROR) {
            memset(&mxlc, 0, sizeof(mxlc));
            mxlc.cbStruct = sizeof(mxlc);
            mxlc.dwLineID = mxl.dwLineID;
            mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
            mxlc.cControls = 1;
            mxlc.cbmxctrl = sizeof(mxc);                mxlc.pamxctrl = &mxc;
            intRet = mixerGetLineControls(hMix, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);                if (intRet == MMSYSERR_NOERROR) {
                memset(&mxcd, 0, sizeof(mxcd));
                mxcd.dwControlID = mxc.dwControlID;
                mxcd.cbStruct = sizeof(mxcd);
                mxcd.cMultipleItems = 0;
                mxcd.cbDetails = sizeof(vol);
                mxcd.paDetails = &vol;
                mxcd.cChannels = 1;                    // vol.dwValue = mxlc.pamxctrl.Bounds.lMinimum; Set min. Volume / Minimum setzen
                // vol.dwValue = mxlc.pamxctrl.Bounds.lMaximum; Set max. Volume / Maximum setzen
                vol.dwValue = bValue;                    intRet = mixerSetControlDetails(hMix, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
                if (intRet != MMSYSERR_NOERROR) {
                    intRet = mixerClose(hMix);
                    throw new Exception("SetControlDetails Error");
                }
            }
        }
        else {
            intRet = mixerClose(hMix);
            throw new Exception("SetControlDetails Error");
        }
    }
    catch (...) {
        return false;
    }        intRet = mixerClose(hMix);
    return true;
}     
allenchan
資深會員


發表:10
回覆:306
積分:283
註冊:2004-01-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-12-02 16:16:42 IP:61.230.xxx.xxx 未訂閱
以下這篇文章所調整的是播放的麥克風音量: http://delphi.ktop.com.tw/topic.php?TOPIC_ID=60600    我另外寫了一個調整錄音的,請試試看:
void SetMicVolume(unsigned int iValue)
{
   // Open the mixer device
   HMIXER hmx;
   mixerOpen(&hmx, 0, 0, 0, 0);       // Get the line info for the wave in destination line
   MIXERLINE mxl;
   mxl.cbStruct = sizeof(mxl);
   mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
   mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);       // Now find the microphone source line connected to this wave in destination
   DWORD cConnections = mxl.cConnections;
   for (DWORD j = 0; j < cConnections; j  )
   {
      mxl.dwSource = j;
      mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE);
      if (MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE == mxl.dwComponentType)
         break;
   }
   // Find a volume control, if any, of the microphone line
   MIXERCONTROL mxc;
   MIXERLINECONTROLS mxlc;
   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)){
      // Found!
      DWORD cChannels = mxl.cChannels;
      if (MIXERCONTROL_CONTROLF_UNIFORM & mxc.fdwControl)
         cChannels = 1;          MIXERCONTROLDETAILS_UNSIGNED vol;          MIXERCONTROLDETAILS mxcd;
      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);
}
asvmfd
一般會員


發表:46
回覆:30
積分:15
註冊:2004-11-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-12-03 18:12:47 IP:61.219.xxx.xxx 未訂閱
那我去試試先, 請問這對Line in 與 Microphone效果會一樣? 請高手指點. 謝謝
allenchan
資深會員


發表:10
回覆:306
積分:283
註冊:2004-01-06

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-12-03 20:36:45 IP:203.70.xxx.xxx 未訂閱
您好,這個 Function 是寫來調整錄音的麥克風音量用的 Sample,您的主題不是要問如何調整輸入的"麥克風音量"嗎? 發表人 - allenchan 於 2004/12/03 20:40:01
asvmfd
一般會員


發表:46
回覆:30
積分:15
註冊:2004-11-09

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-12-03 22:01:55 IP:61.219.xxx.xxx 未訂閱
不好意思,我的意思是說麥克風插在Mic的地方與麥克風插在Line in的地方是否都可用這支程式? 要找個有Lin in的板子來試試前先請教一番... 奇怪,這板子看不到Line in..
allenchan
資深會員


發表:10
回覆:306
積分:283
註冊:2004-01-06

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-12-03 22:15:19 IP:61.62.xxx.xxx 未訂閱
我想是不行,您試試看吧 ~~  你試試把右下角喇叭圖案點兩下,選項 -> 內容 -> 錄音,選擇
asvmfd
一般會員


發表:46
回覆:30
積分:15
註冊:2004-11-09

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-12-04 00:57:35 IP:61.219.xxx.xxx 未訂閱
選項 -> 內容 -> 錄音->看不到Line in. 會找個有Lin in的板子來試試... 謝謝先,
系統時間:2024-11-25 1:51:02
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!