本文介绍了改变频道音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个5.1声卡,可以通过系统托盘上的音量控制来更改每个输出声道的音量(后置,前置,低音炮等).

我正在用C ++开发一个声音应用程序,我想在我的应用程序中更改每个通道的音量,例如Winamp会更改波形音量,我可以在音量控制中看到它.我查看了waveout和Directsound记录,但找不到解决方案.你能帮我吗?谢谢.

I have a 5.1 sound card and can change each output channel volume (rear, front, subwoofer etc.) by volume control at system tray.

I''m developing a sound application in C++ and I want to change each channel volume inside my application like Winamp changes wave volume and I can see it at volume control. I looked at waveout and directsound documention but I couldn''t find the solution. Can you help me please? Thanks.

推荐答案

i solved the problem. Following code, changes each channel volume. The sound card has 8 channels.



<pre>MMRESULT                        mResult;
HMIXER                          mHMixer;
MIXERLINE                       mML;
MIXERLINECONTROLS               mMLC;
MIXERCONTROL                    mMC;
MIXERCONTROLDETAILS             mMCD;
MIXERCONTROLDETAILS_UNSIGNED    mChannelVolume[8];



//每个通道的音量值(0-65535)
mChannelVolume [0] .dwValue = 0;
mChannelVolume [1] .dwValue = 0;
mChannelVolume [2] .dwValue = 32000;
mChannelVolume [3] .dwValue = 0;
mChannelVolume [4] .dwValue = 0;
mChannelVolume [5] .dwValue = 0;
mChannelVolume [6] .dwValue = 65000;
mChannelVolume [7] .dwValue = 65000;

mResult = mixerOpen(& mHMixer,MIXER_OBJECTF_MIXER,0,0,0);

如果(MMSYSERR_NOERROR == mResult)
{
mML.cbStruct = sizeof(MIXERLINE);
mML.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;

//获取调音台设备的扬声器线
mResult = mixerGetLineInfo(((HMIXEROBJ)mHMixer,& mML,MIXER_GETLINEINFOF_COMPONENTTYPE);
如果(MMSYSERR_NOERROR == mResult)
{
mMLC.cbStruct = sizeof(MIXERLINECONTROLS);
mMLC.dwLineID = mML.dwLineID;
mMLC.dwControlType = MIXERC​​ONTROL_CONTROLTYPE_VOLUME;
mMLC.cControls = 1;
mMLC.pamxctrl =& mMC;
mMLC.cbmxctrl = sizeof(MIXERC​​ONTROL);

//获取与扬声器线路关联的音量控制
mResult = mixerGetLineControls(((HMIXEROBJ)mHMixer,& mMLC,MIXER_GETLINECONTROLSF_ONEBYTYPE);
如果(MMSYSERR_NOERROR == mResult)
{
mMCD.cbStruct = sizeof(MIXERC​​ONTROLDETAILS);
mMCD.hwndOwner = 0;
mMCD.dwControlID = mMC.dwControlID;
mMCD.paDetails =& mChannelVolume [0];
mMCD.cbDetails = sizeof(MIXERC​​ONTROLDETAILS_UNSIGNED);
mMCD.cChannels = 8;

//设置音量
mResult = mixerSetControlDetails(((HMIXEROBJ)mHMixer,& mMCD,MIXER_SETCONTROLDETAILSF_VALUE);
如果(MMSYSERR_NOERROR == mResult)
{
cout<<音量已更改!"<< endl;
}
其他
{
cout<<"mixerSetControlDetails()失败"<< endl;
}
}
其他
{
cout<<"mixerGetLineControls()失败"<< endl;
}
}
其他
{
cout<<"mixerGetLineInfo()失败"<< endl;
}
}
mixerClose(mHMixer);



//each channel volume values( 0-65535 )
mChannelVolume[0].dwValue = 0;
mChannelVolume[1].dwValue = 0;
mChannelVolume[2].dwValue = 32000;
mChannelVolume[3].dwValue = 0;
mChannelVolume[4].dwValue = 0;
mChannelVolume[5].dwValue = 0;
mChannelVolume[6].dwValue = 65000;
mChannelVolume[7].dwValue = 65000;

mResult = mixerOpen(&mHMixer, MIXER_OBJECTF_MIXER, 0, 0, 0);

if (MMSYSERR_NOERROR == mResult)
{
mML.cbStruct = sizeof(MIXERLINE);
mML.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;

// get the speaker line of the mixer device
mResult = mixerGetLineInfo((HMIXEROBJ) mHMixer, &mML, MIXER_GETLINEINFOF_COMPONENTTYPE);
if (MMSYSERR_NOERROR == mResult)
{
mMLC.cbStruct = sizeof(MIXERLINECONTROLS);
mMLC.dwLineID = mML.dwLineID;
mMLC.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mMLC.cControls = 1;
mMLC.pamxctrl = &mMC;
mMLC.cbmxctrl = sizeof(MIXERCONTROL);

// get the volume controls associated with the speaker line
mResult = mixerGetLineControls((HMIXEROBJ) mHMixer, &mMLC, MIXER_GETLINECONTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR == mResult)
{
mMCD.cbStruct = sizeof(MIXERCONTROLDETAILS);
mMCD.hwndOwner = 0;
mMCD.dwControlID = mMC.dwControlID;
mMCD.paDetails = &mChannelVolume[0];
mMCD.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mMCD.cChannels = 8;

// set the volume
mResult = mixerSetControlDetails((HMIXEROBJ) mHMixer, &mMCD, MIXER_SETCONTROLDETAILSF_VALUE);
if (MMSYSERR_NOERROR == mResult)
{
cout<<"Volume changed!"<<endl;
}
else
{
cout<<"mixerSetControlDetails() failed"<<endl;
}
}
else
{
cout<<"mixerGetLineControls() failed"<<endl;
}
}
else
{
cout<<"mixerGetLineInfo() failed"<<endl;
}
}
mixerClose(mHMixer);



这篇关于改变频道音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 19:27