确定麦克风的音量 [英] dectect microphone's volume
本文介绍了确定麦克风的音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
他,有人可以教我如何解决我遇到的问题,仍然有2错误和其他链接错误.
我是编程初学者
在此先感谢:) :)
He,can anyone teach me how to sovle the problem which when i complie, there are still get 2 error and other link error.
And i am a programming beginner
Thanks in advance:):)
#include < windows.h >
#include < mmsystem.h >
#include < iostream >
#pragma comment (lib,"winmm.lib")
using namespace std;
int DeviceManager::getAudioInputVolumn( const std::string &deviceName )
{
MMRESULT rc;
HMIXER hMixer;
MIXERLINE mxl;
MIXERLINECONTROLS mxlc;
MIXERCONTROL mxc;
for( int deviceID =0 ; true ; deviceID++ )
{
rc = mixerOpen(&hMixer,deviceID,0,0,MIXER_OBJECTF_MIXER);
if( MMSYSERR_NOERROR!=rc )
{
break;
}
ZeroMemory(&mxl, sizeof(MIXERLINE));
mxl.cbStruct = sizeof(MIXERLINE);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
rc = mixerGetLineInfo((HMIXEROBJ)hMixer,
&mxl,MIXER_OBJECTF_HMIXER|MIXER_GETLINEINFOF_COMPONENTTYPE);
if( rc!=MMSYSERR_NOERROR )
{
continue;
}
DWORD dwConnections = mxl.cConnections;
DWORD dwLineID = -1;
for( DWORD i=0 ; i<dwconnections;> {
mxl.dwSource = i;
rc = mixerGetLineInfo((HMIXEROBJ)hMixer,&mxl,MIXER_OBJECTF_HMIXER|MIXER_GETLINEINFOF_SOURCE);
if( MMSYSERR_NOERROR==rc )
{
if( mxl.dwComponentType==MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE )
{
dwLineID = mxl.dwLineID;
break;
}
}
}
if( dwLineID==-1 )
{
continue;
}
ZeroMemory(&mxc, sizeof(MIXERCONTROL));
mxc.cbStruct = sizeof(mxc);
ZeroMemory(&mxlc, sizeof(MIXERLINECONTROLS));
mxlc.cbStruct = sizeof(mxlc);
mxlc.dwLineID = dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlc.cControls = 1;
mxlc.pamxctrl = &mxc;
mxlc.cbmxctrl = sizeof(mxc);
rc = mixerGetLineControls((HMIXEROBJ)hMixer,&mxlc,MIXER_GETLINECONTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR == rc)
{
MIXERCONTROLDETAILS mxcd;
MIXERCONTROLDETAILS_SIGNED volStruct;
ZeroMemory(&mxcd, sizeof(mxcd));
mxcd.cbStruct = sizeof(mxcd);
mxcd.dwControlID = mxc.dwControlID;
mxcd.paDetails = &volStruct;
mxcd.cbDetails = sizeof(volStruct);
mxcd.cChannels = 1;
rc = mixerGetControlDetails((HMIXEROBJ)hMixer,&mxcd,MIXER_GETCONTROLDETAILSF_VALUE);
if (MMSYSERR_NOERROR == rc)
{
long step = ( mxc.Bounds.lMaximum - mxc.Bounds.lMinimum ) /100;
int index = ( volStruct.lValue - mxc.Bounds.lMinimum) /step ;
printf("volume:%X", volStruct.lValue);
return index;
}
}
}
return -1;
}
推荐答案
1.
将#include <stdio.h>
添加到文件的顶部
2.
更改
1.
Add#include <stdio.h>
to the top of the file
2.
Change
int DeviceManager::getAudioInputVolumn( const std::string &deviceName )
到
to
int getAudioInputVolumn( const std::string &deviceName )
3.
将
3.
Change
for( DWORD i=0 ; i<dwconnections;>
到
to
for( DWORD i=0 ; i<dwConnections; )
现在它将编译,尽管由于程序没有入口点而不会链接.
4.
在代码中添加main或winMain函数.
It will now compile, though won''t link because the program has no entry point.
4.
Add either a main or a winMain function to the code.
您好,抱歉打扰您了,
我只是按照您的说明进行操作,现在它可以成功编译,但是当我单击调试"时,该窗口将立即关闭而不显示任何内容.
在此先感谢:)
然后按照您的指示更改代码,如下所示:
#include< stdio.h>
#include< windows.h>
#include< mmsystem.h>
#include< iostream>
#pragma评论(lib,"winmm.lib")
使用名称空间std;
int main()
{
}
int getAudioInputVolumn(const std :: string&deviceName)
{
MMRESULT rc;
HMIXER hMixer;
MIXERLINE MXL;
MIXERLINECONTROLS mxlc;
MIXERCONTROL mxc;
for(int deviceID = 0; true; deviceID ++)
{
rc = mixerOpen(&hMixer,deviceID,0,0,MIXER_OBJECTF_MIXER);
if(MMSYSERR_NOERROR!= rc)
{
休息;
}
ZeroMemory(&mxl,sizeof(MIXERLINE));
mxl.cbStruct = sizeof(MIXERLINE);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
rc = mixerGetLineInfo((HMIXEROBJ)hMixer,
&mxl,MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE);
if(rc!= MMSYSERR_NOERROR)
{
继续;
}
DWORD dwConnections = mxl.cConnections;
DWORD dwLineID = -1;
for(DWORD i = 0; i< dwconnections;)>
mxl.dwSource = i;
rc = mixerGetLineInfo((HMIXEROBJ)hMixer,&mxl,MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_SOURCE);
if(MMSYSERR_NOERROR == rc)
{
if(mxl.dwComponentType == MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE)
{
dwLineID = mxl.dwLineID;
休息;
}
}
}
if(dwLineID ==-1)
{
继续;
}
ZeroMemory(&mxc,sizeof(MIXERCONTROL));
mxc.cbStruct = sizeof(mxc);
ZeroMemory(&mxlc,sizeof(MIXERLINECONTROLS));
mxlc.cbStruct = sizeof(mxlc);
mxlc.dwLineID = dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlc.cControls = 1;
mxlc.pamxctrl =&mxc;
mxlc.cbmxctrl = sizeof(mxc);
rc = mixerGetLineControls(((HMIXEROBJ)hMixer,&mxlc,MIXER_GETLINECONTROLSF_ONEBYTYPE);
如果(MMSYSERR_NOERROR == rc)
{
MIXERCONTROLDETAILS mxcd;
MIXERCONTROLDETAILS_SIGNED volStruct;
ZeroMemory(&mxcd,sizeof(mxcd));
mxcd.cbStruct = sizeof(mxcd);
mxcd.dwControlID = mxc.dwControlID;
mxcd.paDetails =&volStruct;
mxcd.cbDetails = sizeof(volStruct);
mxcd.cChannels = 1;
rc = mixerGetControlDetails((HMIXEROBJ)hMixer,&mxcd,MIXER_GETCONTROLDETAILSF_VALUE);
如果(MMSYSERR_NOERROR == rc)
{
长步长=(mxc.Bounds.lMaximum-mxc.Bounds.lMinimum)/100;
int索引=(volStruct.lValue-mxc.Bounds.lMinimum)/step;
printf("volume:%X",volStruct.lValue);
返回索引;
}
}
}
返回-1;
}
Hi, sorry for disturbing you,
I just follow your instructions, now it can comile successful but when I click Debug, the window will be closed immediately without displaying anything.
thanks in advance :)
and after your instructions, I chang my code like that:
#include < stdio.h >
#include < windows.h >
#include < mmsystem.h >
#include < iostream >
#pragma comment (lib,"winmm.lib")
using namespace std;
int main()
{
}
int getAudioInputVolumn( const std::string &deviceName )
{
MMRESULT rc;
HMIXER hMixer;
MIXERLINE mxl;
MIXERLINECONTROLS mxlc;
MIXERCONTROL mxc;
for( int deviceID =0 ; true ; deviceID++ )
{
rc = mixerOpen(&hMixer,deviceID,0,0,MIXER_OBJECTF_MIXER);
if( MMSYSERR_NOERROR!=rc )
{
break;
}
ZeroMemory(&mxl, sizeof(MIXERLINE));
mxl.cbStruct = sizeof(MIXERLINE);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
rc = mixerGetLineInfo((HMIXEROBJ)hMixer,
&mxl,MIXER_OBJECTF_HMIXER|MIXER_GETLINEINFOF_COMPONENTTYPE);
if( rc!=MMSYSERR_NOERROR )
{
continue;
}
DWORD dwConnections = mxl.cConnections;
DWORD dwLineID = -1;
for( DWORD i=0 ; i<dwconnections;)>
mxl.dwSource = i;
rc = mixerGetLineInfo((HMIXEROBJ)hMixer,&mxl,MIXER_OBJECTF_HMIXER|MIXER_GETLINEINFOF_SOURCE);
if( MMSYSERR_NOERROR==rc )
{
if( mxl.dwComponentType==MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE )
{
dwLineID = mxl.dwLineID;
break;
}
}
}
if( dwLineID==-1 )
{
continue;
}
ZeroMemory(&mxc, sizeof(MIXERCONTROL));
mxc.cbStruct = sizeof(mxc);
ZeroMemory(&mxlc, sizeof(MIXERLINECONTROLS));
mxlc.cbStruct = sizeof(mxlc);
mxlc.dwLineID = dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlc.cControls = 1;
mxlc.pamxctrl = &mxc;
mxlc.cbmxctrl = sizeof(mxc);
rc = mixerGetLineControls((HMIXEROBJ)hMixer,&mxlc,MIXER_GETLINECONTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR == rc)
{
MIXERCONTROLDETAILS mxcd;
MIXERCONTROLDETAILS_SIGNED volStruct;
ZeroMemory(&mxcd, sizeof(mxcd));
mxcd.cbStruct = sizeof(mxcd);
mxcd.dwControlID = mxc.dwControlID;
mxcd.paDetails = &volStruct;
mxcd.cbDetails = sizeof(volStruct);
mxcd.cChannels = 1;
rc = mixerGetControlDetails((HMIXEROBJ)hMixer,&mxcd,MIXER_GETCONTROLDETAILSF_VALUE);
if (MMSYSERR_NOERROR == rc)
{
long step = ( mxc.Bounds.lMaximum - mxc.Bounds.lMinimum ) /100;
int index = ( volStruct.lValue - mxc.Bounds.lMinimum) /step ;
printf("volume:%X", volStruct.lValue);
return index;
}
}
}
return -1;
}
一个真正的恐怖,但是它确实产生了准确的输出.
A true horror, however it does produce an accurate output..
#include <windows.h>
#include <mmsystem.h>
#include <iostream>
// EDITED s.b
#include <stdio.h>
using namespace std;
// CHANGED s.b int DeviceManager::getAudioInputVolumn( const std::string &deviceName)
int getAudioInputVolumn()
{
MMRESULT rc;
HMIXER hMixer;
MIXERLINE mxl;
MIXERLINECONTROLS mxlc;
MIXERCONTROL mxc;
for( int deviceID =0 ; true ; deviceID++ )
{
rc = mixerOpen(&hMixer,deviceID,0,0,MIXER_OBJECTF_MIXER);
if( MMSYSERR_NOERROR!=rc )
{
break;
}
ZeroMemory(&mxl, sizeof(MIXERLINE));
mxl.cbStruct = sizeof(MIXERLINE);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
rc = mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl,MIXER_OBJECTF_HMIXER|MIXER_GETLINEINFOF_COMPONENTTYPE);
if( rc!=MMSYSERR_NOERROR )
{
continue;
}
DWORD dwConnections = mxl.cConnections;
DWORD dwLineID = -1;
// EDITED s.b for( DWORD i=0 ; i<dwconnections;> {
for( DWORD i=0 ; i<dwConnections;)
{
mxl.dwSource = i;
rc = mixerGetLineInfo((HMIXEROBJ)hMixer,&mxl,MIXER_OBJECTF_HMIXER|MIXER_GETLINEINFOF_SOURCE);
if( MMSYSERR_NOERROR==rc )
{
if( mxl.dwComponentType==MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE )
{
dwLineID = mxl.dwLineID;
break;
}
}
}
if( dwLineID==-1 )
{
continue;
}
ZeroMemory(&mxc, sizeof(MIXERCONTROL));
mxc.cbStruct = sizeof(mxc);
ZeroMemory(&mxlc, sizeof(MIXERLINECONTROLS));
mxlc.cbStruct = sizeof(mxlc);
mxlc.dwLineID = dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlc.cControls = 1;
mxlc.pamxctrl = &mxc;
mxlc.cbmxctrl = sizeof(mxc);
rc = mixerGetLineControls((HMIXEROBJ)hMixer,&mxlc,MIXER_GETLINECONTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR == rc)
{
MIXERCONTROLDETAILS mxcd;
MIXERCONTROLDETAILS_SIGNED volStruct;
ZeroMemory(&mxcd, sizeof(mxcd));
mxcd.cbStruct = sizeof(mxcd);
mxcd.dwControlID = mxc.dwControlID;
mxcd.paDetails = &volStruct;
mxcd.cbDetails = sizeof(volStruct);
mxcd.cChannels = 1;
rc = mixerGetControlDetails((HMIXEROBJ)hMixer,&mxcd,MIXER_GETCONTROLDETAILSF_VALUE);
if (MMSYSERR_NOERROR == rc)
{
long step = ( mxc.Bounds.lMaximum - mxc.Bounds.lMinimum ) /100;
int index = ( volStruct.lValue - mxc.Bounds.lMinimum) /step ;
// printf("volume:%X", volStruct.lValue);
return index;
}
}
}
return -1;
}
int main()
{
printf("Mic volume: %d\n", getAudioInputVolumn());
}
这篇关于确定麦克风的音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文