Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 5-Jun-10 9:50am
v2

C#
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];


//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);
 
Share this answer
 
v2
Hi
This link may be usefull
http://msdn.microsoft.com/en-us/library/dd756706%28v=VS.85%29.aspx[^]

Regards
Radhakrishnan G.
 
Share this answer
 
Comments
yales 8-Jun-10 8:53am    
thanks for your answer.
i loooked at the link but i couldn't find the solution.
i can change "Master Volume" by WaveOutSetVolume function but i want to change each channel volume(left,right,rear,front,subwoofer etc.) separately. Can i do that with Audio Mixer structures and functions?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900