Changing Waveform Playback Volume

The Multimedia extensions provide the following functions to query and set the volume level of waveform output devices:

waveOutGetVolume

Gets the volume level of the specified waveform device.

waveOutSetVolume

Sets the volume level of the specified waveform device.

Not all waveform devices support volume changes. Some devices support individual volume control on both the left and right channels. See “Determining Capabilities of Waveform Output Devices,” earlier in this chapter, for information on how to determine the volume-control capabilities of waveform devices.

Note:

Unless your application is designed to be a master volume-control application providing the user with volume control for all audio devices in a system, you should open an audio device before changing its volume. You should also query the volume level before changing it and restore the volume level to its previous level as soon as possible.

Volume is specified in a DWORD; the upper 16 bits specify the relative volume of the right channel, and the lower 16 bits specify the relative volume of the left channel, as shown in the following illustration:

For devices that don't support left- and right-channel volume control, the lower 16 bits specify the volume level, and the upper 16 bits are ignored. Volume-level values range from 0x0 (silence) to 0xFFFF (maximum volume) and are interpreted logarithmically. The perceived volume increase is the same when increasing the volume level from 0x5000 to 0x6000 as it is from 0x4000 to 0x5000.

When querying with waveOutGetVolume, the volume is returned in a DWORD location specified by a far pointer parameter.