映射 ISpMMSysAudio::SetLineId 和 MixerLineId
我想通过调用 ISpMMSysAudio::SetLineId 来设置 SAPI 的 lineId。 我从我拥有的搅拌机手柄中找到了我想要设置的线。 然而,我从混音器获得的线路 ID 并不是 SAPI 所假设的。 它 导致 SAPI 监听麦克风的错误输入线,从而得到 没有输入。
我正在为混音器手柄获取“DST_WAVEIN”的多路复用器控制, 然后检查麦克风的哪条源线处于活动状态。 我希望 将活动线路设置为 SAPI 的“输入”。
我通过枚举 MUX 控制从混频器获取线路 ID,如下所示:
int GetSelectedWaveInLine(UINT uMixrId) { int iRetVal = -1; MMRESULT 毫米结果; HMIXER dwMixerHandle;
mmResult = mixerOpen( (LPHMIXER)&dwMixerHandle, uMixrId, 0L, 0L, 0L);
if (MMSYSERR_NOERROR != mmResult)
{
LOG_ERROR("FAILURE: Could not Open mixer, with id: %d. mmResult=%d",uMixrId, mmResult );
return -1;
}
MIXERLINE MixerLine;
memset( &MixerLine, 0, sizeof(MIXERLINE) );
MixerLine.cbStruct = sizeof(MIXERLINE);
MixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
mmResult = mixerGetLineInfo( (HMIXEROBJ)dwMixerHandle, &MixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE );
if (MMSYSERR_NOERROR != mmResult)
{
mixerClose( (HMIXER)dwMixerHandle );
LOG_ERROR("FAILURE: Could not get WaveIn Destionation Line for the requested source while enumerating. mmResult=%d", mmResult );
return -1;
}
// get the MUX
MIXERCONTROL mxc;
MIXERLINECONTROLS mxlc;
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = MixerLine.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUX;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
mmResult = ::mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(uMixrId),
&mxlc,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINECONTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR != mmResult)
{
LOG_INFO0("Could not get Mux control for waveIn line. Get selected id");
mixerClose( (HMIXER)dwMixerHandle );
return -1;
}
LOG_INFO("Got mux controls. Total lines associated with mux = %d", mxc.cMultipleItems);
// from the MUX get as many lines for "MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE" {from dwParam1/dwParam2 }
// then get the boolean control for the line and return the one currently selected
MIXERCONTROLDETAILS_LISTTEXT *pmxcdSelectText = new MIXERCONTROLDETAILS_LISTTEXT[mxc.cMultipleItems];
if (pmxcdSelectText != NULL)
{
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc.dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = mxc.cMultipleItems;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXT);
mxcd.paDetails = pmxcdSelectText;
if (::mixerGetControlDetails(reinterpret_cast<HMIXEROBJ>(uMixrId),
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_GETCONTROLDETAILSF_LISTTEXT)
!= MMSYSERR_NOERROR)
{
delete []pmxcdSelectText;
mixerClose( (HMIXER)dwMixerHandle );
return -1;
}
}
//get all the boolean values for the mux
MIXERCONTROLDETAILS_BOOLEAN *pmxcdSelectValue = new MIXERCONTROLDETAILS_BOOLEAN[mxc.cMultipleItems];
if (pmxcdSelectValue != NULL)
{
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc.dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = mxc.cMultipleItems;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails = pmxcdSelectValue;
if (::mixerGetControlDetails(reinterpret_cast<HMIXEROBJ>(uMixrId),
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_GETCONTROLDETAILSF_VALUE)
!= MMSYSERR_NOERROR)
{
delete []pmxcdSelectValue;
mixerClose( (HMIXER)dwMixerHandle );
return -1;
}
}
for (int i = 0; i < mxc.cMultipleItems; i++)
{
if(/*(pmxcdSelectText[i].dwParam2 == MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE) && */pmxcdSelectValue[i].fValue)
{
LOG_INFO("Got SELECTED microphone source line. Line index = %d, Line name = %s",i,pmxcdSelectText[i].szName);
iRetVal = i;
break;
}
}
//LOG_INFO("Got mux controls. Total lines associated with mux = %d", mxc.cMultipleItems);
delete []pmxcdSelectText;
delete []pmxcdSelectValue;
mixerClose( (HMIXER)dwMixerHandle );
return iRetVal;
Mixer 返回的索引与
ISpMMSysAudio 使用的索引不匹配。 我的语音引擎选择不同的线路 ID。
谢谢
I want to set the lineId for SAPI by calling ISpMMSysAudio::SetLineId.
I find out the line which I wish to set from the mixer handle I have.
However the line id I get from the mixer is not what SAPI assumes. It
results in SAPI listening to the wrong input line for mic thus getting
no input.
I'm getting the mux control for "DST_WAVEIN" for the mixer handle and
then checking which source line for microphone is active. I wish to
set the active line as "input" to the SAPI.
I am getting Line Id from mixer by enumerating MUX control as follows:
int GetSelectedWaveInLine(UINT uMixrId)
{
int iRetVal = -1;
MMRESULT mmResult;
HMIXER dwMixerHandle;
mmResult = mixerOpen( (LPHMIXER)&dwMixerHandle, uMixrId, 0L, 0L, 0L);
if (MMSYSERR_NOERROR != mmResult)
{
LOG_ERROR("FAILURE: Could not Open mixer, with id: %d. mmResult=%d",uMixrId, mmResult );
return -1;
}
MIXERLINE MixerLine;
memset( &MixerLine, 0, sizeof(MIXERLINE) );
MixerLine.cbStruct = sizeof(MIXERLINE);
MixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
mmResult = mixerGetLineInfo( (HMIXEROBJ)dwMixerHandle, &MixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE );
if (MMSYSERR_NOERROR != mmResult)
{
mixerClose( (HMIXER)dwMixerHandle );
LOG_ERROR("FAILURE: Could not get WaveIn Destionation Line for the requested source while enumerating. mmResult=%d", mmResult );
return -1;
}
// get the MUX
MIXERCONTROL mxc;
MIXERLINECONTROLS mxlc;
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = MixerLine.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUX;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
mmResult = ::mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(uMixrId),
&mxlc,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINECONTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR != mmResult)
{
LOG_INFO0("Could not get Mux control for waveIn line. Get selected id");
mixerClose( (HMIXER)dwMixerHandle );
return -1;
}
LOG_INFO("Got mux controls. Total lines associated with mux = %d", mxc.cMultipleItems);
// from the MUX get as many lines for "MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE" {from dwParam1/dwParam2 }
// then get the boolean control for the line and return the one currently selected
MIXERCONTROLDETAILS_LISTTEXT *pmxcdSelectText = new MIXERCONTROLDETAILS_LISTTEXT[mxc.cMultipleItems];
if (pmxcdSelectText != NULL)
{
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc.dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = mxc.cMultipleItems;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXT);
mxcd.paDetails = pmxcdSelectText;
if (::mixerGetControlDetails(reinterpret_cast<HMIXEROBJ>(uMixrId),
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_GETCONTROLDETAILSF_LISTTEXT)
!= MMSYSERR_NOERROR)
{
delete []pmxcdSelectText;
mixerClose( (HMIXER)dwMixerHandle );
return -1;
}
}
//get all the boolean values for the mux
MIXERCONTROLDETAILS_BOOLEAN *pmxcdSelectValue = new MIXERCONTROLDETAILS_BOOLEAN[mxc.cMultipleItems];
if (pmxcdSelectValue != NULL)
{
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc.dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = mxc.cMultipleItems;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails = pmxcdSelectValue;
if (::mixerGetControlDetails(reinterpret_cast<HMIXEROBJ>(uMixrId),
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_GETCONTROLDETAILSF_VALUE)
!= MMSYSERR_NOERROR)
{
delete []pmxcdSelectValue;
mixerClose( (HMIXER)dwMixerHandle );
return -1;
}
}
for (int i = 0; i < mxc.cMultipleItems; i++)
{
if(/*(pmxcdSelectText[i].dwParam2 == MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE) && */pmxcdSelectValue[i].fValue)
{
LOG_INFO("Got SELECTED microphone source line. Line index = %d, Line name = %s",i,pmxcdSelectText[i].szName);
iRetVal = i;
break;
}
}
//LOG_INFO("Got mux controls. Total lines associated with mux = %d", mxc.cMultipleItems);
delete []pmxcdSelectText;
delete []pmxcdSelectValue;
mixerClose( (HMIXER)dwMixerHandle );
return iRetVal;
}
The index returned by Mixer does not match the index used by ISpMMSysAudio. And my speech engine picks different line ID.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ISpMMSysAudio::SetLineId 实际上指定混频器索引,而不是线路 ID。 (我知道这很令人困惑。)因此,您要做的就是枚举混频器行以查找与行 ID 对应的索引,并返回该索引。
ISpMMSysAudio::SetLineId actually specifies the mixer index, not the line ID. (Confusing, I know.) So what you want to do is to enumerate the mixer lines to find the index that corresponds to the line ID, and return the index.