So I got an email from a reader yesterday asking:
How do you set the volume of an audio stream coming from a CD? I found an old piece of code that used mciSendCommand with some parameters to do so, but my compiler cannot find the “MCI_SET_VOLUME” constant. Has this been completely depreciated? If so, how can I control the volume of CD output?
It surprised me, I thought you could set the volume on audio playback, so I dug a bit deeper.
My first thought was the MCI “SET” verb – MCI_SET_AUDIO allows you to control audio channels during playback.
The reader responded that the MCI_SET_PARMS doesn’t have a lVolume member like you’d think it should. So I dug deeper, and discovered that you can’t set the volume of CD playback via MCI. Your only option (using MCI only) is to mute either the left, right, or both channels (using MCI_SET_AUDIO with the MCI_SET_AUDIO_ALL/MCI_SET_AUDIO_LEFT/MCI_SET_AUDIO_RIGHT dwAudio fields, and a MCI_SET_ON or MCI_SET_OFF flag.
Very strange, I don’t know why this is. But that’s the way it’s been since at least windows XP (the oldest source I have available).
If you REALLY must control the output volume, then you’ve only got a couple of options. First off, you can use the mixer APIs and search for a CD source line, the volume control on the CD source will control the volume of the CD output. I also believe that that the aux APIs can be used to control the CD audio volume (auxGetDevCaps will let you know if an aux device is a CD audio device).
Having said that, there may be compatibility issues using these techniques when run on Windows Vista.
The good news is that for new code, it’s actually pretty easy to write code to read the data from the CD directly and play it back, I wrote a sample version of such code here. And if you’re using the wave APIs to render audio, the wave audio playback APIs should work perfectly.