#include "manager.h"
#pragma execution_character_set("utf-8")
bool CheckError1(int ret,QString msg){
bool Result = ret!=MMSYSERR_NOERROR;
if(Result)
qDebug()<<msg<<endl;
// QMessageBox::information(NULL,"出错",msg);//记录日志信息msg
return Result;
}
bool CheckDevices(manager* manager,QString &msg){
msg = "";
bool Result = manager->GetMicophone()&manager->GetSpeaker();
if(!manager->GetMicophone()&&!manager->GetSpeaker())
msg="你的电脑没有接入耳麦";
else if(!manager->GetMicophone())
msg="你的电脑没有接入麦克风";
else if(!manager->GetSpeaker())
msg="你的电脑没有接入扬声器或耳机";
return Result;
}
manager::manager(QObject *parent) : QObject(parent)
{
Speaker = new MixerDevice(ctWaveout,this);
SpeakerMute= new MixerDevice(ctWaveoutMute,this);
Mic= new MixerDevice(ctMic,this);
MicMute= new MixerDevice(ctMicMute,this);
}
Volume manager::GetMicVolumn()
{
Volume result;
result = this->Mic->volume;
result.Value = this->Speaker->getData();
return result;
}
Volume manager::GetSpeakerVolumn()
{
Volume result;
result = this->Speaker->volume;
result.Value = this->Speaker->getData();
return result;
}
void manager::SetMicVolumn(int Value)
{
Mic->setData(Value);
}
void manager::SetSpeakerVolumn(int Value)
{
Speaker->setData(Value);
}
bool manager::GetMicophone()
{
return 1;
}
bool manager::GetSpeaker()
{
return 1;
}
bool manager::GetMicMute()
{
return MicMute->getData()==1;
}
void manager::SetMicMute(const bool Value)
{
MicMute->setData(Value);
}
bool manager::GetSpeakerMute()
{
return SpeakerMute->getData()==1;
}
void manager::SetSpeakerMute(const bool Value)
{
SpeakerMute->setData(Value);
}
MixerDevice::MixerDevice(DeviceType type,QObject *parent)
{
this->type = type;
init();
}
void MixerDevice::setData(const int Value)
{
mxcdVolume_Set.dwValue = Value;
int ret = mixerSetControlDetails((HMIXEROBJ)m_hMixer, &mxcd_Set, MIXER_SETCONTROLDETAILSF_VALUE);
CheckError1(ret,"mixerSetControlDetails failed!");
}
void MixerDevice::init()
{
int mixerNum = (int)mixerGetNumDevs();
int DWComponentType;
int DWComponentType2;
int DWControlType;
int fdwInfo = MIXER_GETLINEINFOF_COMPONENTTYPE;
if(type==ctMic||type==ctMicMute)
{
DWComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
DWComponentType2 = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
if(type==ctMic)
DWControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
else
{
fdwInfo = MIXER_GETLINECONTROLSF_ONEBYTYPE;
DWControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
}
}
if(type==ctWaveout||type==ctWaveoutMute)
{
DWComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
DWComponentType2 = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
if(type==ctWaveout)
DWControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
else
{
fdwInfo = MIXER_GETLINECONTROLSF_ONEBYTYPE;
DWControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
}
}
for(int i = 0; i < mixerNum; i ++)
{
//打开Mixer设备
int ret = mixerOpen(&m_hMixer, i, 0, 0, MIXER_OBJECTF_MIXER);
if(CheckError1(ret,"mixerOpen failed! " + QString::number(i)))
return;
//结构体的大小
MixerLine.cbStruct = sizeof(MixerLine);
//录制设备总线
if(this->type==ctWaveout||this->type==ctWaveoutMute)
{
MixerLine.dwComponentType = DWComponentType;
ret = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &MixerLine,
MIXER_GETLINEINFOF_COMPONENTTYPE);
if(CheckError1(ret,"mixerOpen failed! " + QString::number(i)))
return;
}
else{
MixerLine.dwDestination = 0;
ret = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &MixerLine,MIXER_GETLINEINFOF_DESTINATION);
if(CheckError1(ret,"mixerOpen failed! " + QString::number(i)))
return;
}
if(MixerLine.dwComponentType!=DWComponentType)
continue;
//将连接数保存
DWORD dwConnections = MixerLine.cConnections;
//准备获取麦克风设备的ID
for(int j = 0; j < dwConnections; j++ )
{
//枚举每一个设备,当Source的ID等于当前的迭代记数
MixerLine.dwSource = j;
//根据SourceID获得连接的信息
ret = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &MixerLine,MIXER_GETLINEINFOF_SOURCE);
if(CheckError1(ret,"mixerOpen failed! " + QString::number(j)))
return;
//如果当前设备类型是指定类型,则跳出循环。
if(MixerLine.dwComponentType == DWComponentType2)
{
lineinfo_Connector = MixerLine;
dwLineID = lineinfo_Connector.dwLineID;
break;
}
}
//如果没有找到,返回失败。
// if(dwLineID == 0)
// continue;
::ZeroMemory(&lineinfo_Dest, sizeof(MIXERLINE));
lineinfo_Dest.cbStruct = sizeof(MIXERLINE);
lineinfo_Dest.dwComponentType = DWComponentType;
lineinfo_Dest.dwSource = 0;
if(this->type==ctWaveout||this->type==ctWaveoutMute)
{
ret = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &lineinfo_Dest,
MIXER_GETLINEINFOF_COMPONENTTYPE);
if(CheckError1(ret,"mixerOpen failed! " + QString::number(i)))
return;
}
else{
lineinfo_Dest.dwDestination = 0;
ret = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &lineinfo_Dest,MIXER_GETLINEINFOF_DESTINATION);
if(CheckError1(ret,"mixerOpen failed! " + QString::number(i)))
return;
}
MIXERCONTROL *tmp = new MIXERCONTROL[lineinfo_Connector.cControls];
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = lineinfo_Connector.dwLineID;
mxlc.dwControlType = DWControlType;
mxlc.cControls = lineinfo_Connector.cControls;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = tmp;
ret = mixerGetLineControls((HMIXEROBJ)m_hMixer, &mxlc,MIXER_GETLINECONTROLSF_ALL);
if(CheckError1(ret,QString("")))
continue;
for (int j = 0; j < lineinfo_Connector.cControls; ++j) {
if(tmp[j].dwControlType==DWControlType)
mxc =&tmp[j];
}
//get volume value range now
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = mxc->dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = 0;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mxcd.paDetails = &mxcdVolume;
ret = mixerGetControlDetails((HMIXEROBJ)m_hMixer, &mxcd, MIXER_GETCONTROLDETAILSF_VALUE);
if(CheckError1(ret,"mixerGetControlDetails failed!"))
continue;
volume.MaxValue = mxc->Bounds.dwMaximum;
volume.MinValue = mxc->Bounds.dwMinimum;
volume.Value = mxcdVolume.dwValue;
//set volume
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;
ret = mixerSetControlDetails((HMIXEROBJ)m_hMixer, &mxcd_Set, MIXER_SETCONTROLDETAILSF_VALUE);
CheckError1(ret,"mixerSetContr
qt creator项目使用原生Windows进行混声器音量设置(包括录音)
4星 · 超过85%的资源 需积分: 12 73 浏览量
2018-07-24
15:14:07
上传
评论 1
收藏 8KB RAR 举报
Rubber峰
- 粉丝: 14
- 资源: 5
最新资源
- Image_1713714819368.png
- 数据可视化 matplotlib 实例.docx
- Python 使用 Matplotlib 绘制甘特图的实践.docx
- matplotlib 中的 cmap 参数介绍.docx
- 基于matlab的毕业设计基于Matlab使用LQR实现车辆轨迹跟踪源码.zip
- 基于Matplotlib 的高互动性可视化系统设计与实现
- matplotlib 数据可视化报告.docx
- 传统网页UI设计在移动应用开发中的应用研究.pdf
- 基于pytorch实现BERT+BiLSTM+CRF实现中文命名实体识别源码.zip
- 校园帮项目,毕业设计/课程设计/javaWeb/SSM
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈