# 16.3 `cd` -- CD-ROM access on SGI systems

Availability: IRIX.

This module provides an interface to the Silicon Graphics CD library. It is available only on Silicon Graphics systems.

The way the library works is as follows. A program opens the CD-ROM device with `open()` and creates a parser to parse the data from the CD with `createparser()`. The object returned by `open()` can be used to read data from the CD, but also to get status information for the CD-ROM device, and to get information about the CD, such as the table of contents. Data from the CD is passed to the parser, which parses the frames, and calls any callback functions that have previously been added.

An audio CD is divided into tracks or programs (the terms are used interchangeably). Tracks can be subdivided into indices. An audio CD contains a table of contents which gives the starts of the tracks on the CD. Index 0 is usually the pause before the start of a track. The start of the track as given by the table of contents is normally the start of index 1.

Positions on a CD can be represented in two ways. Either a frame number or a tuple of three values, minutes, seconds and frames. Most functions use the latter representation. Positions can be both relative to the beginning of the CD, and to the beginning of the track.

Module `cd` defines the following functions and constants:

`createparser` ()
  Create and return an opaque parser object. The methods of the parser object are described below.

`msftoframe` (minutes, seconds, frames)
  Converts a `(minutes, seconds, frames)` triple representing time in absolute time code into the corresponding CD frame number.

`open` ([device[, mode]])
  Open the CD-ROM device. The return value is an opaque player object; methods of the player object are described below. The device is the name of the SCSI device file, e.g. `'/dev/scsi/sc0d4l0'`, or `None`. If omitted or `None`, the hardware inventory is consulted to locate a CD-ROM drive. The mode, if not omited, should be the string `'r'`.

The module defines the following variables:

`error`
  Exception raised on various errors.

`DATASIZE`
  The size of one frame's worth of audio data. This is the size of the audio data as passed to the callback of type `audio`.

`BLOCKSIZE`
  The size of one uninterpreted frame of audio data.

The following variables are states as returned by `getstatus()`:

`READY`
  The drive is ready for operation loaded with an audio CD.

`NODISC`
  The drive does not have a CD loaded.

`CDROM`
  The drive is loaded with a CD-ROM. Subsequent play or read operations will return I/O errors.

`ERROR`
  An error aoocurred while trying to read the disc or its table of contents.

`PLAYING`
  The drive is in CD player mode playing an audio CD through its audio jacks.

`PAUSED`
  The drive is in CD layer mode with play paused.

`STILL`
  The equivalent of `PAUSED` on older (non 3301) model Toshiba CD-ROM drives. Such drives have never been shipped by SGI.

`audio`
`pnum`
`index`
`ptime`
`atime`
`catalog`
`ident`
`control`
  Integer constants describing the various types of parser callbacks that can be set by the `addcallback()` method of CD parser objects (see below).

- 16.3.1 Player Objects
- 16.3.2 Parser Objects