📄 可选择声卡录音通道的类.txt
字号:
// WaveInSel.h: interface for the CWaveInSel class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_WAVEINSEL_H__A18231B1_27E4_4687_862A_9068AF3FF0CD__INCLUDED_)
#define AFX_WAVEINSEL_H__A18231B1_27E4_4687_862A_9068AF3FF0CD__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "mmsystem.h"
class CWaveInSel : public CObject
{
private:
DWORD m_dwLineID;
HMIXER m_hMixer;
UINT m_nMic,m_nLineIn;
public:
void Close();
void Open();
void WaveInSel_LINE();
void WaveInSel_MIC();
CWaveInSel();
virtual ~CWaveInSel();
};
#endif // !defined(AFX_WAVEINSEL_H__A18231B1_27E4_4687_862A_9068AF3FF0CD__INCLUDED_)
// WaveInSel.cpp: implementation of the CWaveInSel class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "WaveInSel.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CWaveInSel::CWaveInSel()
{
m_hMixer = NULL;
m_nLineIn = 0;
m_nMic = 0;
}
CWaveInSel::~CWaveInSel()
{
}
void CWaveInSel::WaveInSel_MIC()
{
if (m_hMixer==NULL)
return;
MIXERLINECONTROLS mxlc;
MIXERCONTROL mxc;
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = m_dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUX;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
MMRESULT r = ::mixerGetLineControls((HMIXEROBJ)m_hMixer,
&mxlc,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINECONTROLSF_ONEBYTYPE );
if (r != MMSYSERR_NOERROR)
return;
DWORD nCount = mxc.cMultipleItems;
MIXERCONTROLDETAILS_BOOLEAN *pSel =
new MIXERCONTROLDETAILS_BOOLEAN[nCount];
for(DWORD i=0;i<nCount;i++)
{
pSel[i].fValue = FALSE;
}
pSel[m_nMic].fValue = TRUE;
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc.dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = nCount;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails = pSel;
if (::mixerSetControlDetails((HMIXEROBJ)m_hMixer,
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_SETCONTROLDETAILSF_VALUE)
!= MMSYSERR_NOERROR)
{
if (pSel)
{
delete pSel;
pSel = NULL;
}
return;
}
if (pSel)
{
delete pSel;
pSel = NULL;
}
}
void CWaveInSel::WaveInSel_LINE()
{
if (m_hMixer==NULL)
return;
MIXERLINECONTROLS mxlc;
MIXERCONTROL mxc;
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = m_dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUX;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
MMRESULT r = ::mixerGetLineControls((HMIXEROBJ)m_hMixer,
&mxlc,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINECONTROLSF_ONEBYTYPE );
if (r != MMSYSERR_NOERROR)
return;
DWORD nCount = mxc.cMultipleItems;
MIXERCONTROLDETAILS_BOOLEAN *pSel =
new MIXERCONTROLDETAILS_BOOLEAN[nCount];
for(DWORD i=0;i<nCount;i++)
{
pSel[i].fValue = FALSE;
}
pSel[m_nLineIn].fValue = TRUE;
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc.dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = nCount;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails = pSel;
if (::mixerSetControlDetails((HMIXEROBJ)m_hMixer,
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_SETCONTROLDETAILSF_VALUE)
!= MMSYSERR_NOERROR)
{
if (pSel)
{
delete pSel;
pSel = NULL;
}
return;
}
if (pSel)
{
delete pSel;
pSel = NULL;
}
}
void CWaveInSel::Open()
{
MIXERCAPS m_mxcaps;
::ZeroMemory(&m_mxcaps, sizeof(MIXERCAPS));
UINT nNum;
nNum = waveInGetNumDevs();
if (nNum==0)
return;
if (::mixerOpen(&m_hMixer,0,NULL,NULL,MIXER_OBJECTF_WAVEIN)
!= MMSYSERR_NOERROR)
return;
if (::mixerGetDevCaps((UINT)m_hMixer, &m_mxcaps, sizeof(MIXERCAPS))
!= MMSYSERR_NOERROR)
return ;
if (m_hMixer == NULL)
return ;
MIXERLINE mxl;
mxl.cbStruct = sizeof(MIXERLINE);
if (::mixerGetLineInfo(0,
&mxl,
MIXER_OBJECTF_WAVEIN)
!= MMSYSERR_NOERROR)
return;
m_dwLineID = mxl.dwLineID;
DWORD num=mxl.cConnections;
DWORD type=mxl.dwDestination;
for( DWORD i=0;i<num;i++)
{
mxl.cbStruct = sizeof(mxl);
mxl.dwDestination = type;
mxl.dwSource = i;
if(mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxl, MIXER_GETLINEINFOF_SOURCE|MIXER_OBJECTF_HMIXER)!= MMSYSERR_NOERROR)
{
AfxMessageBox("GetLinInfo Resource faile!");
continue;
}
if(mxl.dwComponentType
==MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE)
m_nMic = i;
if(mxl.dwComponentType
==MIXERLINE_COMPONENTTYPE_SRC_LINE)
m_nLineIn = i;
}
}
void CWaveInSel::Close()
{
if (m_hMixer!=NULL)
{
mixerClose(m_hMixer);
m_hMixer = NULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -