Setting volume on audio CDs with MCI
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.
Comments
Anonymous
October 06, 2005
Your /oldest/ source is win XP? Good Lord man, get a grip. Who'd need /that/ now? :-)Anonymous
October 07, 2005
The comment has been removedAnonymous
October 08, 2005
Gabe, that's actually not true. At one point in the "audio in vista" series, I plan on talking about what we did with CD audio in XP and in Vista.Anonymous
October 10, 2005
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/msmod_26.asp
__declspec(noinline) would be your friend for this test.Anonymous
October 10, 2005
Wrong thread, but for some reason, I totally missed noinline when I was looking for it earlier.Anonymous
October 12, 2005
The comment has been removedAnonymous
October 13, 2005
Gabe, on almost every OEM machine manufactured in the past 6 years, the cable you mentioned doesn't exist (not providing it allows computer manufacturers to save something like $.25 on each computer).
Instead (on XP and below), there's a driver, redbook.sys that uses digital audio extraction to read the audio bits from the CD-ROM drive and write the data to sysaudio.sys (the Windows XP kernel mode audio driver).Anonymous
October 14, 2005
Where can I find out about compatability issues with the mixer API's for vista that you allude to? I did a search on MSDN but didn't find anything.Anonymous
May 31, 2009
PingBack from http://outdoorceilingfansite.info/story.php?id=228Anonymous
May 31, 2009
PingBack from http://outdoorceilingfansite.info/story.php?id=17864