Larry Osterman's WebLog

Confessions of an Old Fogey
Blog - Title

Setting volume on audio CDs with MCI

Setting volume on audio CDs with MCI

  • Comments 10

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.

 

  • Your /oldest/ source is win XP? Good Lord man, get a grip. Who'd need /that/ now? :-)
  • Well, since CD audio goes straight from the CD drive to the audio card with no CPU processing, it's not hard to imagine that there's no easy way to do it. Of course, it should really just be treated as another audio card input, the way a microphone or line-in would be. Thus it makes sense that the mixer APIs should control it, right?
  • 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.
  • 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.
  • Wrong thread, but for some reason, I totally missed noinline when I was looking for it earlier.
  • There is a cable running straight from the CD-ROM drive to the audio card. The only way the CPU could be involved is to have the audio card digitize it and suck in the bits from the card or suck the bits directly off the CD. Which option will Vista be using?
  • 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).
  • 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.

  • PingBack from http://outdoorceilingfansite.info/story.php?id=228

  • PingBack from http://outdoorceilingfansite.info/story.php?id=17864

Page 1 of 1 (10 items)