请问怎样控制系统录音的音量?(注意!是录音的音量,不是放音的音量!)

fireseed 2005-06-06 10:55:02
双击系统右下角的小喇叭,弹出播放控制,然后点“选项”菜单,点击“属性”。在“调节音量”栏中选中“录音”,然后确定。这里就是调节录音音量的地方。

请问我想调节麦克风的录音音量,该怎么做?

我已经查过以前的贴子,所有的代码都只能调节放音的音量,而不是录音。

所以我重申一遍,只能调节放音音量的代码就不要再贴了,我问的是如何调节录音音量。

使用别的控件的方法不予考虑,只能用API。
...全文
845 11 打赏 收藏 举报
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zijida 2005-06-08
谢谢楼主兄弟提点.偶是发错了.嘿嘿...


int CHMixerManager::Set_WaveInConnectionLevel(UINT rMixerID, DWORD rLineIndex, DWORD *rLevelPercent, BOOL *rSelected)
{
// open mixer by id
HMIXER mixer = NULL;
HRESULT hr = ::mixerOpen(
&mixer,
rMixerID,
NULL,
NULL,
MIXER_OBJECTF_MIXER);
if (FAILED(hr))
return ERR_BASE_MIM_FailedToOpenMixer;

// get line id of destination line
MIXERLINE lineinfo_Dest;
::ZeroMemory(&lineinfo_Dest, sizeof(MIXERLINE));
lineinfo_Dest.cbStruct = sizeof(MIXERLINE);
lineinfo_Dest.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
hr = ::mixerGetLineInfo(
(HMIXEROBJ)mixer,
&lineinfo_Dest,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINEINFOF_COMPONENTTYPE);

// get id of specified connector
MIXERLINE lineinfo_Connector;
::ZeroMemory(&lineinfo_Connector, sizeof(MIXERLINE));

lineinfo_Connector.cbStruct = sizeof(MIXERLINE);
lineinfo_Connector.dwDestination = lineinfo_Dest.dwLineID;
lineinfo_Connector.dwSource = rLineIndex;
hr = ::mixerGetLineInfo(
(HMIXEROBJ)mixer,
&lineinfo_Connector,
MIXER_GETLINEINFOF_SOURCE);


if (rLevelPercent)
{

// get volume control ID
MIXERCONTROL mxc;
MIXERLINECONTROLS mxlc;
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = lineinfo_Connector.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
::mixerGetLineControls(
reinterpret_cast<HMIXEROBJ>(mixer),
&mxlc,
MIXER_OBJECTF_HMIXER|MIXER_GETLINECONTROLSF_ONEBYTYPE);

// get volume value range now
MIXERCONTROLDETAILS_UNSIGNED mxcdVolume;
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc.dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = 0;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mxcd.paDetails = &mxcdVolume;
mixerGetControlDetails(
reinterpret_cast<HMIXEROBJ>(mixer),
&mxcd,
MIXER_GETCONTROLDETAILSF_VALUE);

// set volume
MIXERCONTROLDETAILS_UNSIGNED mxcdVolume_Set = {
mxc.Bounds.dwMaximum * (*rLevelPercent) / 100 };
MIXERCONTROLDETAILS mxcd_Set;
mxcd_Set.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd_Set.dwControlID = mxc.dwControlID;
mxcd_Set.cChannels = 1;
mxcd_Set.cMultipleItems = 0;
mxcd_Set.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mxcd_Set.paDetails = &mxcdVolume_Set;
mixerSetControlDetails(reinterpret_cast<HMIXEROBJ>(mixer),
&mxcd_Set,
MIXER_OBJECTF_HMIXER |
MIXER_SETCONTROLDETAILSF_VALUE);
}



//////////////////////
// selected control

if (rSelected)
{
// get dwControlID
MIXERCONTROL mxc;
MIXERLINECONTROLS mxlc;
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = lineinfo_Dest.dwLineID;
DWORD m_dwControlType = MIXERCONTROL_CONTROLTYPE_MIXER;
mxlc.dwControlType = m_dwControlType;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
if (::mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(mixer),
&mxlc,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINECONTROLSF_ONEBYTYPE)
!= MMSYSERR_NOERROR)
{
// no mixer, try MUX
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = lineinfo_Dest.dwLineID;
m_dwControlType = MIXERCONTROL_CONTROLTYPE_MUX;
mxlc.dwControlType = m_dwControlType;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
if (::mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(mixer),
&mxlc,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINECONTROLSF_ONEBYTYPE)
!= MMSYSERR_NOERROR)
{
return FALSE;
}
}

// store dwControlID, cMultipleItems
//m_dwSelectControlID = mxc.dwControlID;
//m_dwMultipleItems = mxc.cMultipleItems;

if (mxc.cMultipleItems == 0)
{
return -1;
}

// get all the values first
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>(mixer),
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_GETCONTROLDETAILSF_VALUE)
== MMSYSERR_NOERROR)
{
// MUX restricts the line selection to one source line at a time.
if (m_dwControlType == MIXERCONTROL_CONTROLTYPE_MUX)
{
::ZeroMemory(pmxcdSelectValue,
mxc.cMultipleItems * sizeof(MIXERCONTROLDETAILS_BOOLEAN));
}

// set the want line value
pmxcdSelectValue[mxc.cMultipleItems -1 - rLineIndex].fValue = TRUE;

mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc.dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = mxc.cMultipleItems;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails = pmxcdSelectValue;
if (::mixerSetControlDetails(reinterpret_cast<HMIXEROBJ>(mixer),
&mxcd,
MIXER_OBJECTF_HMIXER | MIXER_SETCONTROLDETAILSF_VALUE)
!= MMSYSERR_NOERROR)
{
delete []pmxcdSelectValue;
::mixerClose(mixer);
return -2;
}
}

delete []pmxcdSelectValue;
}


}


// close mixer
::mixerClose(mixer);

return 0;
}
  • 打赏
  • 举报
回复
boreboluomi 2005-06-06
学习
  • 打赏
  • 举报
回复
vcmute 2005-06-06
long int max_vol;
HMIXER hmx;
mixerOpen(&hmx, 0, 0, 0, 0);

用MIXERLINE_COMPONENTTYPE_DST_WAVEIN 作参数可得到所有录音的Connection
MIXERLINE mxl;
mxl.cbStruct = sizeof(mxl);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN ;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl,MIXER_GETLINEINFOF_COMPONENTTYPE);

DWORD cConnections = mxl.cConnections;
for(DWORD j=0; j<cConnections; j++)
{
mxl.dwSource = j;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE);
AfxMessageBox(mxl.szName);
}

录音一般修改的是MIC的输入
  • 打赏
  • 举报
回复
fireseed 2005-06-06
这样的问题怎么没有人会啊!!!!

研究了一下,发现调用mixerSetControlDetails的时候,dwControlID参数从1开始, 一直到n是播放控制的音量,从n开始到m是录制控制的音量。(n是机器上所有播放音量的总数,不是定数)

可是我得到的dwControlID都是小于n的呀?怎样才能得到录音的dwControlID??
  • 打赏
  • 举报
回复
fireseed 2005-06-06
to zijida:

您怎么回贴不看贴呢?都说了只要能调节录音音量的!

可您的代码只能调节放音音调!!!
  • 打赏
  • 举报
回复
vcmute 2005-06-06
使用Mixer 控制 MIC
http://community.csdn.net/Expert/topic/4006/4006308.xml?temp=.3474542

http://www.cmaniacs.com/v1/index.php?path=Sorgenti%2FAudio%2FVari&text=SetRecordingDevice.cpp
  • 打赏
  • 举报
回复
bohut 2005-06-06
mark
  • 打赏
  • 举报
回复
zijida 2005-06-06
一段代码供参考:


int CHMixerManager::Set_SpeakerConnectionVolume(UINT rMixerID, DWORD rLineIndex, DWORD *rVolumePercent, BOOL *rMuteNow)
{
// open mixer by id
HMIXER mixer = NULL;
HRESULT hr = ::mixerOpen(
&mixer,
rMixerID,
NULL,
NULL,
MIXER_OBJECTF_MIXER);
if (FAILED(hr))
return ERR_BASE_MIM_FailedToOpenMixer;

// get line count of destination line
MIXERLINE lineinfo;
::ZeroMemory(&lineinfo, sizeof(MIXERLINE));

lineinfo.cbStruct = sizeof(MIXERLINE);

lineinfo.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;

hr = ::mixerGetLineInfo(
(HMIXEROBJ)mixer,
&lineinfo,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINEINFOF_COMPONENTTYPE);

// get info of specified connector
DWORD lineID = lineinfo.dwDestination;
::ZeroMemory(&lineinfo, sizeof(MIXERLINE));

lineinfo.cbStruct = sizeof(MIXERLINE);
lineinfo.dwDestination = lineID;
lineinfo.dwSource = rLineIndex;
hr = ::mixerGetLineInfo(
(HMIXEROBJ)mixer,
&lineinfo,
MIXER_GETLINEINFOF_SOURCE);

if (rVolumePercent)
{

// get volume control ID
MIXERCONTROL mxc;
MIXERLINECONTROLS mxlc;
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = lineinfo.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
::mixerGetLineControls(
reinterpret_cast<HMIXEROBJ>(mixer),
&mxlc,
MIXER_OBJECTF_HMIXER|MIXER_GETLINECONTROLSF_ONEBYTYPE);

// get volume value range now
MIXERCONTROLDETAILS_UNSIGNED mxcdVolume;
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc.dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = 0;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mxcd.paDetails = &mxcdVolume;
mixerGetControlDetails(
reinterpret_cast<HMIXEROBJ>(mixer),
&mxcd,
MIXER_GETCONTROLDETAILSF_VALUE);

// set volume
MIXERCONTROLDETAILS_UNSIGNED mxcdVolume_Set = {
mxc.Bounds.dwMaximum * (*rVolumePercent) / 100 };
MIXERCONTROLDETAILS mxcd_Set;
mxcd_Set.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd_Set.dwControlID = mxc.dwControlID;
mxcd_Set.cChannels = 1;
mxcd_Set.cMultipleItems = 0;
mxcd_Set.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mxcd_Set.paDetails = &mxcdVolume_Set;
mixerSetControlDetails(reinterpret_cast<HMIXEROBJ>(mixer),
&mxcd_Set,
MIXER_OBJECTF_HMIXER |
MIXER_SETCONTROLDETAILSF_VALUE);
}

if (rMuteNow)
{

// get mute control id
MIXERCONTROL mxc;
MIXERLINECONTROLS mxlc;
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = lineinfo.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
hr = ::mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(mixer),
&mxlc,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINECONTROLSF_ONEBYTYPE);

// set mute value now
MIXERCONTROLDETAILS_BOOLEAN mxcdMute = { *rMuteNow };
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc.dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = 0;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails = &mxcdMute;
hr = ::mixerSetControlDetails(reinterpret_cast<HMIXEROBJ>(mixer),
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_SETCONTROLDETAILSF_VALUE);

}

// close mixer
::mixerClose(mixer);

return 0;
}
  • 打赏
  • 举报
回复
fireseed 2005-06-06
算了算了,以后以问题还是自己解决吧。算你们狠,把我这二百分骗到手了!

找到录音设备的正确在下面,请您更新一下您的“答案库”,以便下回到别人同样的贴子中去骗分。

// 打开Mixer设备
mixerOpen( &m_hMixer, 0, 0, 0, MIXER_OBJECTF_MIXER );
MIXERLINE MixerLine;
// 结构体的大小
MixerLine.cbStruct = sizeof(MixerLine);
// 录制设备总线
MixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
// 得到录制总线中的连接数
mixerGetLineInfo( (HMIXEROBJ)m_hMixer, &MixerLine,
MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE );
// 将连接数保存
DWORD dwConnections = MixerLine.cConnections;
// 准备获取麦克风设备的ID
DWORD dwLineID = 0;
for ( DWORD i = 0; i < dwConnections; i++ )
{
// 枚举每一个设备,当Source的ID等于当前的迭代记数
MixerLine.dwSource = i;
// 根据SourceID获得连接的信息
mr = mixerGetLineInfo( (HMIXEROBJ)m_hMixer, &MixerLine,
MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_SOURCE );
// 判断函数执行错误
if ( mr != 0 )
{
break;
}
// 如果当前设备类型是麦克风,则跳出循环。
if ( MixerLine.dwComponentType ==
MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE )
{
dwLineID = MixerLine.dwLineID;
break;
}
}
// 如果没有找到,返回失败。
if ( dwLineID == 0 )
{
return FALSE;
}
  • 打赏
  • 举报
回复
fireseed 2005-06-06
to vcmute:

我原封不动的将你写的代码运行起来,结果修改的还是播放的音量,而不是录音的音量!
  • 打赏
  • 举报
回复
whoo 2005-06-06
走mixer思路是对了。
我以前在 codeproject 上发布过一个类,就是专门调节录音音量的。 时间长乐有点记不大清楚,应该是在多媒体、音频分类下。
  • 打赏
  • 举报
回复
相关推荐
发帖
VC/MFC
加入

1.6w+

社区成员

VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
申请成为版主
帖子事件
创建了帖子
2005-06-06 10:55
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……