|
Project-->Link:winmm.lib
#include "mmsystem.h"
BOOL GetRecordradio()
{
UINT m_uMxId2;
//HWND m_hWnd;//回调句柄
HMIXER m_hmx2;
MIXERCAPS mxcaps;
//返回系统中混音器数量(如:一块普通声卡提供一个混音器设备)
int devnum=mixerGetNumDevs();
int i=0;
for(i;i<devnum;i++)
{
m_uMxId2=i;
if (MMSYSERR_NOERROR !=
mixerOpen(&m_hmx2, m_uMxId2,NULL, 0, CALLBACK_WINDOW))
//使用dwCallback参数
return -1;
//得到相应设备标识号
//mixerGetID((HMIXEROBJ)m_hmx2,&m_uMxId,MIXER_OBJECTF_HMIXER);
//确定各混音器设备的能力:保存在mxcaps结构中(wMid,wPid,szname,cDestinations)
if (MMSYSERR_NOERROR !=
mixerGetDevCaps(m_uMxId2,&mxcaps,sizeof(MIXERCAPS)))
return FALSE;
//检索指定音频线路的信息,保存在MIXERLINE结构中,
//其中一些成员根据不同情况要初始化
MIXERLINE mxl;
mxl.cbStruct = sizeof(MIXERLINE); //必须赋值
//可以通过多种条件来检索:
//方式一:根据目标单元编号
//mxl.dwDestination=0;等同用mxl.dwComponentType=MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
//mxl.dwDestination=1;等同用mxl.dwComponentType=MIXERLINE_COMPONENTTYPE_DST_WAVEIN
//对应flag: MIXER_GETLINEINFOF_DESTINATION
//mxl.dwDestination=1;
//方式二:根据线路类型
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
//对应flag: MIXER_GETLINEINFOF_COMPONENTTYPE
if (::mixerGetLineInfo((HMIXEROBJ)m_hmx2,
&mxl,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINEINFOF_COMPONENTTYPE)
!= MMSYSERR_NOERROR) return -1;
//查询 录音控制面版中 麦克风线路的编号
MIXERLINE mxl_v;
UINT cConnections = (UINT)mxl.cConnections;
UINT dwSource_v=0;
do
{
mxl_v.cbStruct = sizeof(mxl_v);
mxl_v.dwDestination = mxl.dwDestination;
mxl_v.dwSource = dwSource_v;
dwSource_v++;
if (MMSYSERR_NOERROR !=
mixerGetLineInfo((HMIXEROBJ)m_hmx2,
&mxl_v,
MIXER_GETLINEINFOF_SOURCE))
return FALSE;
} while ((dwSource_v < cConnections) &&
(mxl_v.dwComponentType != MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE));
if((dwSource_v > cConnections) ||
(mxl_v.dwComponentType !=MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE))
return FALSE;
dwSource_v--;//得到编号
//下面这段文字说明在本例中已经没有什么实际意义,是以前调试时留下的,也不删除了,
//可以知道如何控制主音(Volume)线路的禁音状态:
//--可以利用得到的主音(Volume)线路的mxl.dwLineID,
//来查询Volume的禁音状态
//要想查询(或设置)可以混音到DST_SPEAKERS主音(Volume)中的
//相关音源线路(如:wave、micphone等)的禁音状态,还必须再使用
//一次 mixerGetLineInfo 进一步指定其dwLineID
//注意:不要简单的直接修改上面的:
//mxl.dwComponentType = 类型;
//虽然可能有时不会报错,但这成了我们程序中的隐患,
//因为有的线路在DST_SPEAKERS和DST_WAVEIN中均有,如:
//MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC
//下面实现了"强制"单选麦克风线路为录音源输入
MIXERCONTROL mxc;
MIXERLINECONTROLS mxlc;
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = mxl.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUX;
//MIXERCONTROL_CONTROLTYPE_MUTE;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc; //为了得到相应的mxc.dwControlID,
//锁定mxlc.dwLineID和mxlc.dwControlType指定的线路控制
//目前将对录音目标单元的录音音源线路做单选(多路复用)
if (::mixerGetLineControls((HMIXEROBJ)m_hmx2,
&mxlc,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINECONTROLSF_ONEBYTYPE)
!= MMSYSERR_NOERROR) return -1;
//根据mxc.dwControlID检索线路,
MIXERCONTROLDETAILS_BOOLEAN mxcdMute[8];
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc.dwControlID;//在上面的&mxc得到
mxcd.cChannels = 1;
mxcd.cMultipleItems =mxc.cMultipleItems;//多路因子数目
mxcd.cbDetails = sizeof(*mxcdMute);
mxcd.paDetails =&mxcdMute;//存放检索结果
if (::mixerGetControlDetails((HMIXEROBJ)m_hmx2,
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_GETCONTROLDETAILSF_VALUE)
!= MMSYSERR_NOERROR) return -1;
//做相应单选改变
int j;
for(j=0;j<(int)mxc.cMultipleItems;j++)
mxcdMute[j].fValue=false;
mxcdMute[dwSource_v].fValue=true;
//重新设置dwControlID锁定的线路控制
if (::mixerSetControlDetails((HMIXEROBJ)m_hmx2,
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_GETCONTROLDETAILSF_VALUE)
!= MMSYSERR_NOERROR) return -1;
}//for(i;i<devnum;i++)
return TRUE;
} |
|