|
Technote 1187Digital CD AudioBy Mark Cookson |
CONTENTSThe way it was |
Starting with Mac OS 9.0 there is a new way of playing CD audio— digitally. Pure digital data is read from the CD, played through the Sound Manager as a PCM (Pulse Code Modulation —standard uncompressed audio) data stream, and then sent out to the speakers (where your ears require that it be converted back to an analog signal). This Technote describes how an application uses the new digital CD audio support and what a CD or DVD driver needs to do to support playing audio digitally. |
The way it wasFor as long as the Macintosh has had a built-in CD-ROM, the audio has been played as an analog sound stream. The CD-ROM drive would output analog sound, just like a microphone, and the Mac would record that audio, optionally passing it through to the speakers (play through). A diagram of the flow of audio data (from the CD-ROM only for simplification) looks like this: ![]() The audio data was read by the CD-ROM drive and converted to analog audio inside the CD-ROM drive. From there the analog audio would go to the sound hardware on the Macintosh. It would then be converted back to digital data and given to the Sound Manager. The Sound Manager would then pass the audio to any application that was recording the CD audio input source. If play through was turned on, the sound hardware would automatically route the analog sound back out to the speakers (or headphones), requiring no CPU intervention or overhead to hear the audio. The multiple conversions of the audio introduced the possibility of noise and reduced sound quality, as well as making it difficult to precisely know, to a sample accuracy, what was being played. That has all changed with Mac OS 9.0. The way it is nowStarting with Mac OS 9.0, there is a new sound input device called “Internal CD.” When Internal CD is the selected input source, the Macintosh reads digital data directly from the CD and plays it as digital audio. This allows applications to record high-quality digital audio from CD using standard Sound Input Manager recording calls. However, the Internal CD input driver does not have to be selected to allow the user listen to the CD, it only has to be selected to perform recording. Instead of using the digital-to-analog converters built into the CD-ROM drive (which may be of questionable quality to audio purists), the audio is read as digital data, much like a normal file would be read off of a CD. This digital audio is then passed to the Sound Manager which plays it, as it would play any sound. This allows the sound to be played by the built-in sound hardware and the built-in speakers of the Macintosh, or out via some other hardware, such as USB speakers. Previously it was not possible for the internal audio CD to be played out via third-party hardware. The flow of audio data now looks like this: ![]() However, this also means that the CPU is now running code that plays the audio. A very minor performance penalty is extracted for this new functionality. The measured statistics are about 0.5% CPU usage on a PowerBook G3 300MHz when the sound output setting is set to 44.1 kHz. This number doesn’t include the cost of the Sound Manager sound channel which is needed for the sound output. How your application needs to changeThere is no longer an option of selecting the internal CD from the Built-in input driver. If the user’s CPU is able to support digital CD audio, the option of doing it the old analog way has been removed for a consistent user interface between different Macintoshes. If you would like to give the users of your application the ability to record digital CD audio using the new Internal CD input source, you will have to choose it as the recording source. It is a completely different sound input driver, not a different input source of the Built-in sound input device. You will need some method of selecting different input sources because you cannot assume that it will be the default input device. Apple does not recommend that you have the user use the Sound control panel to change the default input source unless the user wants a global change. Typically this is the not the case, as only one application wants to record from the Internal CD input source—most applications will want to record from the microphone or sound in input. Therefore, having the user change the system wide behavior is the wrong thing to do. Having your own interface element for this is the
preferred method for changing all sound settings in your
application. The proper way to choose the Internal CD input
source is to construct a list of all sound input drivers
(using repeated calls to There are a few key points that should be pointed out regarding the Internal CD input source:
|
How your CD/DVD driver needs to changeDevelopers of CD or DVD drivers may wish to support the new Internal CD input driver. To do this, the driver needs to be updated to call some functions in the Internal CD PPC code fragment. Calling these functions from 68K code is not supported. If you wish to do that, you are squarely in unsupported territory—watch your step. These functions are called by the CD/DVD driver and are
how digital audio is passed from the driver to the Internal
CD driver when the CD/DVD driver gets an
The exported functions of the DigitalCDSoundLib are: |
|
The usage, and general ordering, of these routines is as follows:
These functions are used to control how the audio plays or give you feedback about where in the audio stream you are.
There are a significant number of data structures and
memory allocations associated with digital CD audio. To
minimize the use of system resources that are not needed,
your driver should not call Additional Notes & CommentsThe Only WayThe only way that users will be able to hear their CDs through USB speakers is for the CD/DVD driver to support digital audio. If you are the author of a CD or DVD driver, you should work to add this functionality to your driver as quickly as possible. The Apple CD/DVD driver allows for digital CD audio only on Macintoshes which have ATAPI CD or DVD drives. It does not support SCSI CD drives. Macintoshes with SCSI CD drives using the Apple CD/DVD driver will behave as they always have. The iBook only does digital CD audio, as its sound chip does not have an analog to digital converter (remember, it doesn’t have a built-in microphone either). All iBooks will play audio CD using the above API. If a user installs a third-party CD driver on the iBook, it is imperative that it supports digital CD audio or the user will loose the ability to hear their audio CDs. 3D SoundThe 3D sound enhancement that is offered is a simple filter. It is one of a class of filters called ’stereo spreaders.” This type of enhancement works well with some types of music, and not so well with others, so make sure you allow the user to choose their personal preference of on or off. Because of the additional signal from the stereo spreader is being added back into the original signal, the overall signal is reduced to avoid the possibility of clipping. This has the effect of reducing the overall volume level of the sound when the 3D effect is turned on (and a raising of the volume when it is turned off). The user can compensate for this by turning up the volume on the Mac, the CD, or their speakers. The current implementation of the 3D-Stereo component takes about 1.4% of the CPU on a 300MHz PowerBook G3. |
SummaryAs you can see, applications do not have to do anything special and will just continue to work—assuming that they were properly coded with the correct error handling and user interface. If you do not have a user interface for sound preferences, but instead rely on the Sound control panel, please remedy this as soon as possible. Drivers have a bit more work to allow for digital CD audio, but the benefit of allowing the user to play their CDs through their USB speakers definitely makes this effort worthwhile. |
Thanks to Steven Swenson, Andy Stewart, Jeff Hoekman, and others.