MMAPG - CD Audio Device
Reprint Courtesy of International Business Machines Corporation, © International Business Machines Corporation
The CD audio media device provides access to devices that read compact discs for the purpose of playing CD audio. A typical use for CD audio is to provide high quality audio for use in a presentation. Another use of CD audio would be to provide detailed audio help for an application user. Instead of the usual hyperlinked text and graphics, an entire step by step audio tutorial might be stored on a compact disc in several different languages.
Compact Disc Formats
A compact disc can contain several different kinds of information. Many compact discs appear to be very similar to other forms of permanent storage such as hard or floppy disks. CD-ROM (Compact Disc - Read Only Memory) refers to a file format used for compact discs containing data that can be read by a computer's file system. This format is also known as Yellow Book. Yellow Book refers to the specification published by Philips Consumer Electronics Company and Sony Corporation that describes the physical layout of the CD-ROM disc format. This document evolved into the ISO (International Organization for Standardization) 9660 standard.
Another form of compact disc data is Compact Disc Digital Audio (CD-DA) and is also known as Red Book. This format is used for compact discs containing digital audio. CD-DA discs are encoded as 16-bit stereo PCM (Pulse Code Modulation) at 44.1 kHz.
For every second of CD-DA audio data, 172KB of disc storage is required. Therefore, the sustained data rate required to play back a selection from a CD-DA track is 172KB per second. The CD-DA track format typically has an error recovery rate of 90 percent. A 10 percent error rate is acceptable for audio discs, because errors that escape the correction mechanism are usually compensated for by audio filters in the CD player hardware.
Unlike CD-DA data, information stored in a CD-ROM file system cannot tolerate such a relatively high error rate. As a result, CD-ROM format data is transferred to an application at an apparent data rate of 150KB per second. The lower data rate results from the additional error correction bits utilized by the file system to produce an acceptable error rate.
Mixed Format Compact Discs
A mixed format compact disc holds CD-ROM file system data as well as CD-DA track format data. An example of the use of a mixed format disc is an application that contains several symphonies by a famous composer. The actual audio is stored as a series of CD-DA tracks. Also stored on the disc (but in CD-ROM file format) is a program, the actual music score, and perhaps a data base on the composer's life. When the application is started, the audio from a symphony can be played using the CD audio media driver, while the user is allowed to study the music score. Additionally, the user might retrieve facts on the composer, such as how old the composer was when the symphony was written.
By issuing the MCI_GETTOC message with mciSendCommand, an application can retrieve a table of contents (TOC) for a disc. This function is particularly useful for a mixed format disc. The starting and ending addresses (time) of each audio track are listed as well as the type of track. Using the table of contents, an application can immediately determine which tracks can be played using the CD audio device. Additionally, an application can determine the track type by issuing the status command to determine the type of any individual track.
open cdaudio alias mycd shareable status mycd type track 1 wait
Note: The CD audio device processes only CD-DA tracks.
CD-ROM Drives and Streaming
Depending on the type of CD-ROM drive installed, the audio data on a CD-DA disc is either processed by a Digital-to-Analog Converter (DAC) that is built into the drive, or it is moved through the system to a Digital Signal Processor (DSP) on an audio adapter. Some CD-ROM drives can only play CD-DA audio data through the built-in DAC. Others, like the IBM Personal System/2 (PS/2) CD-ROM-II Drive, can play through the DAC, or they can stream data through the audio adapter DSP.
The advantage offered by playing CD-DA through the DAC is that it is a simple operation that greatly reduces system and resource overhead. The advantage gained by streaming data through an audio adapter DSP is that you can potentially enhance the signal beyond the capabilities of the DAC by adding special effects such as reverberation and tremolo, or by modifying treble and bass—capabilities the DAC cannot provide.
The default mode for the CD audio device is playback processed by the DAC through the internal headphones connector. To switch to playback through the audio adapter DSP, the application sends the connector command enabling the cd stream connector.
connector mycd enable type cd stream wait
To resume playback through the internal CD DAC, the application should re-enable the headphones connector. This will automatically disable the streaming connector.
connector mycd enable type headphones wait
Contention for the Amplifier-Mixer Device
Because the audio adapter is modeled as an amplifier-mixer (ampmix) device, the CD audio device will automatically open and connect to its default amplifier-mixer when streaming CD-DA data. If the amplifier-mixer device is currently opened exclusively by another application, enabling the cd stream connector will fail. If the amplifier-mixer is available, then other applications using the same ampmix device might temporarily lose use of the device if the audio adapter cannot simultaneously process all requests. The Media Device Manager (MDM) will handle all resource allocation automatically, however it should be realized that streaming CD-DA data using the CD audio device can effect applications using the waveaudio and sequencer devices as these devices also use the ampmix device. Conversely, a waveaudio device could cause the loss of a streaming CD audio device if the waveaudio device requires the use of the same shared ampmix device.
Using the CD Audio Device
The CD audio device is a dynamic single context device and is serially shareable.
open cdaudio alias mycd shareable wait
By setting the shareable flag, an application allows other applications to share the device. When the device context is about to become active, the multimedia system posts an MM_MCIPASSDEVICE message with an event of MCI_GAINING_USE to your application.
Another common aspect of using the CD audio device is controlling the volume. Volume is controlled by indicating a percentage of the maximum achievable effect. Like all other devices in OS/2 multimedia, this volume level is automatically tempered by the master volume level that was set using the Volume Control application.
Volume Control Using the Internal DAC
By default the CD audio device utilizes the internal DAC on the CD drive which is represented by an enabled headphones connector. When the internal DAC is being used to process the CD audio data, requests to set the volume should be sent directly to the CD device.
set mycd audio volume 50 all wait
Depending on the capabilities of the actual CD-ROM drive, the degree of volume control might vary from on or off, to a reasonably linear range of settings. For example, the IBM PS/2 CD-ROM-II Drive supports 16 different levels of volume. An application might want to display either a simple two state mute button or a volume slider or dial depending on the degree of volume control provided by the CD drive. If a CD audio device can set the volume to some value other than 0 or 100, then it is likely the device supports several volume levels.
Volume Control Using the Ampmix Device
As stated previously, some CD audio devices have the capability to stream the audio data to a connected amplifier-mixer device. To determine if a particular CD audio device can stream CD audio data the device capabilities command can be used. If TRUE is returned, then the cd stream connector can subsequently be enabled.
capability mycd can stream wait /* If this CD audio device can stream: */ connector mycd enable type cd stream wait
After enabling the cd stream, the CD audio device is utilizing the amplifier-mixer device to convert the audio data into sound. As such, the application must now send all volume commands to the connected ampmix device. Before a command can be sent to the ampmix device, the application must obtain the device ID of the amplifier-mixer device using the MCI_CONNECTION message. If using the string interface, an alias can be assigned to the connected ampmix device as follows:
connection mycd query type cd stream alias amp wait
In the previous example, the alias 'amp' is assigned to the connected ampmix device. To set the volume or to control other audio attributes, the application can now send messages directly to the ampmix device.
set amp audio volume 25 over 2000 all wait set amp audio treble 50 wait
Playing a Compact Disc
Before issuing a play command, suitable media should be present in the CD drive. The following status command will return TRUE if the disc contains CD-DA tracks that can be played by the CD audio device:
status mycd media present wait
The CD audio device operates only on discs that contain CD-DA tracks. If a disc contains no CD-DA tracks, then the MCIERR_INVALID_MEDIA error can be returned on any command that requires a CD-DA track format in order to complete. Example commands include play, seek, and the media present function of the status command.
Other pertinent information regarding the CD audio device can be obtained using the status command:
| Query | Response |
|---|---|
| ready | TRUE or FALSE |
| mode | not ready, open, paused, playing, seeking, or stopped |
| time format | milliseconds, MMTIME, MSF, TMSF |
| volume | Current volume setting |
The status command will also return the following information about the currently inserted media:
| Query | Response |
|---|---|
| current track | Number of current track |
| position in track | Current position relative to track start |
| length track n | Length of track n |
| position track n | Starting position of track n |
| type track n | Audio or data |
| copypermitted track n | TRUE, if digital copying permitted |
| channels track n | Number of audio channels on track |
| preemphasis | TRUE, if track was recorded with preemphasis |
| start position | Starting position of the disc |
| position | Position in current time format |
| number of tracks | Number of audio tracks on the disc |
| length | Total length of tracks on the disc |
Changing the Media
It is the responsibility of the application to ensure that the appropriate compact disc is in the CD drive if having a particular disc is essential to the application. An application can choose to disable the manual eject button on the physical CD drive to prevent the disc from being changed.
capability mycd can lockeject wait /* If the door can be locked, lock it! */ set mycd door locked wait
If the drive does not support disabling the manual eject, then the application can check the disc identity by obtaining the UPC code (serial number) or the more general CD ID. The CD ID is an 8-byte identifier which can be obtained using the info command and is constructed from the starting track address, ending track number, and lead-out track address.
info mycd ID wait info mycd UPC wait
If a play is in progress and the manual eject button is pressed on the CD drive, the application will receive the MCIERR_DEVICE_NOT_READY error when the play command is aborted.
Unique Considerations for Streaming
When the OS/2 multimedia system is streaming multimedia information from a CD-ROM drive, attempts by other applications to access and control the CD drive for normal file system operations can be suspended until the streaming operation is ended. The stream can be interrupted by a pause or a stop command, the completion of playback, or the ejection of the disc. Once the stream is interrupted, any applications that were waiting can resume their attempts to gain control of the device.
If the CD audio device is being shared and the disc is changed on an application which had lost use of the device, any active play command may be aborted with an error of MCIERR_MEDIA_CHANGED when use of the device is subsequently regained.
CD-DA Command Messages
| Message | Description |
|---|---|
| MCI_OPEN | Initializes the CD-DA device. |
| MCI_GETDEVCAPS | Gets device capabilities. |
| MCI_GETTOC | Gets a table of contents structure for the currently loaded disc. |
| MCI_CUE | Cues the device for minimum delay in playback. |
| MCI_PLAY | Starts playing audio data from the disc. |
| MCI_PAUSE | Suspends the current playback action. |
| MCI_RESUME | Resumes playing from a paused state. |
| MCI_SEEK | Moves to the specified position on the disc. |
| MCI_SET | Sets audio attributes (volume, channels, door lock, time format). |
| MCI_SET_SYNC_OFFSET | Specifies positional offsets. |
| MCI_STATUS | Receives status on items (volume, length, media present, mode, position). |
| MCI_INFO | Fills a buffer with product name, model, UPC, and Disc ID. |
| MCI_STOP | Stops playing the CD-DA device. |
| MCI_SET_CUEPOINT | Sets a cue point. |
| MCI_SET_POSITION_ADVISE | Sets a position change notification request. |
| MCI_CLOSE | Closes the CD-DA device. |
| MCI_CONNECTOR | Enables or disables a connector, queries its state or identifies its type. |
CD Audio Connectors
The number and type of connectors can vary by manufacturer. To determine which connectors are supported, an application can issue the MCI_CONNECTORINFO message. Also, the device capabilities command can be issued to determine if the CD drive can stream audio to an amplifier-mixer device. The following are typical of the connectors supported by CD audio devices:
- Headphones
- CD stream