Click here to Skip to main content
12,949,700 members (88,808 online)
Click here to Skip to main content
Add your own
alternative version


54 bookmarked
Posted 11 Aug 2003


, 19 Sep 2005
Rate this:
Please Sign up or sign in to vote.
How to set the master volume of the speakers


This article is a brief explanation of how to use the mixerSetControlDetails API for setting the master volume of the speakers. Sometimes it is not enough to merely set the volume of the waveform-audio (or MIDI) output device.

Setting the volume

MMRESULT result;
result = waveOutSetVolume(0, 0x48444844);

If only it was that easy! Sometimes, the easiest-sounding task does not always equate to the most straight-forward code. While this does alter the speaker's volume, it does so in the context of the waveform-audio output device. What we want is the ability to set the master volume regardless of the output device.

The first thing we need to do is obtain a handle to the mixer device.

MMRESULT result;
HMIXER hMixer;
result = mixerOpen(&hMixer, MIXER_OBJECTF_MIXER, 0, 0, 0);

Next, we need to get the speaker line of the mixer device.

MIXERLINE ml = {0};
ml.cbStruct = sizeof(MIXERLINE);
result = mixerGetLineInfo((HMIXEROBJ) hMixer, 

Next, we need to get the volume control of the speaker line.

mlc.cbStruct = sizeof(MIXERLINECONTROLS);
mlc.dwLineID = ml.dwLineID;
mlc.cControls = 1;
mlc.pamxctrl = &mc;
mlc.cbmxctrl = sizeof(MIXERCONTROL);
result = mixerGetLineControls((HMIXEROBJ) hMixer, 

We now have everything identified. All that's left is to actually set the volume level.

mcdu.dwValue = 18500; // the volume is a number between 0 and 65535
mcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mcd.hwndOwner = 0;
mcd.dwControlID = mc.dwControlID;
mcd.paDetails = &mcdu;
mcd.cChannels = 1;
result = mixerSetControlDetails((HMIXEROBJ) hMixer, 

That's it! If you want to mute the speakers, simply set the value to 0. If you want to test the elasticity of the speaker cones, set the value to 65535!

Obtaining the current speaker volume is just as easy, or at least it uses most of the same code! Simply call mixerGetControlDetails() instead and do not assign a value to the dwValue member of the MIXERCONTROLDETAILS_UNSIGNED structure. It will contain the current speaker volume upon successful return from mixerGetControlDetails().

Mute me, baby!

Using the above code, you can mute the master speakers by using a value of 0 for mcdu.dwValue. However, there is another method to do it correctly. The control type used is MIXERCONTROL_CONTROLTYPE_MUTE instead of MIXERCONTROL_CONTROLTYPE_VOLUME. The structure used will be MIXERCONTROLDETAILS_BOOLEAN instead of MIXERCONTROLDETAILS_UNSIGNED. The value of the fValue member is 1 to mute the speakers and 0 to unmute them. The code looks like:

result = mixerGetLineControls((HMIXEROBJ) hMixer, 

mcb.fValue    = true; 
mcd.paDetails = &mcb;
result = mixerSetControlDetails((HMIXEROBJ) hMixer, 


The code was not tested for all possible audio combinations, but is merely showing how to use a particular API. My development machine has only the default sound card, and some $19 speakers! Not exactly an audio mixer's dream!

There are a few other CP articles that attack this problem differently, or that provide different levels of detail. I was not aware of them when I wrote this article, and simply searched CP for mixerSetControlDetails only to find no matches.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior) Pinnacle Business Systems
United States United States

The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

HTTP 404 - File not found
Internet Information Services

You may also be interested in...

Comments and Discussions

QuestionDoes this work on Vista ? Pin
Jeffrey Buxton1-Apr-09 7:22
memberJeffrey Buxton1-Apr-09 7:22 
AnswerRe: Does this work on Vista ? Pin
DavidCrow1-Apr-09 7:24
mvpDavidCrow1-Apr-09 7:24 
GeneralRe: Does this work on Vista ? Pin
Jeffrey Buxton1-Apr-09 13:53
memberJeffrey Buxton1-Apr-09 13:53 
GeneralRe: Does this work on Vista ? Pin
DavidCrow2-Apr-09 2:54
mvpDavidCrow2-Apr-09 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170524.1 | Last Updated 19 Sep 2005
Article Copyright 2003 by DavidCrow
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid