Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 1 | \section{Built-in Module \sectcode{cd}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 2 | \label{module-cd} |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 3 | \bimodindex{cd} |
| 4 | |
| 5 | This module provides an interface to the Silicon Graphics CD library. |
| 6 | It is available only on Silicon Graphics systems. |
| 7 | |
| 8 | The way the library works is as follows. A program opens the CD-ROM |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 9 | device with \function{open()} and creates a parser to parse the data |
| 10 | from the CD with \function{createparser()}. The object returned by |
| 11 | \function{open()} can be used to read data from the CD, but also to get |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 12 | status information for the CD-ROM device, and to get information about |
| 13 | the CD, such as the table of contents. Data from the CD is passed to |
| 14 | the parser, which parses the frames, and calls any callback |
| 15 | functions that have previously been added. |
| 16 | |
| 17 | An audio CD is divided into \dfn{tracks} or \dfn{programs} (the terms |
| 18 | are used interchangeably). Tracks can be subdivided into |
| 19 | \dfn{indices}. An audio CD contains a \dfn{table of contents} which |
| 20 | gives the starts of the tracks on the CD. Index 0 is usually the |
| 21 | pause before the start of a track. The start of the track as given by |
| 22 | the table of contents is normally the start of index 1. |
| 23 | |
| 24 | Positions on a CD can be represented in two ways. Either a frame |
| 25 | number or a tuple of three values, minutes, seconds and frames. Most |
| 26 | functions use the latter representation. Positions can be both |
| 27 | relative to the beginning of the CD, and to the beginning of the |
| 28 | track. |
| 29 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 30 | Module \module{cd} defines the following functions and constants: |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 31 | |
Guido van Rossum | d45c156 | 1995-03-30 11:47:50 +0000 | [diff] [blame] | 32 | |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 33 | \begin{funcdesc}{createparser}{} |
| 34 | Create and return an opaque parser object. The methods of the parser |
| 35 | object are described below. |
| 36 | \end{funcdesc} |
| 37 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 38 | \begin{funcdesc}{msftoframe}{minutes, seconds, frames} |
| 39 | Converts a \code{(\var{minutes}, \var{seconds}, \var{frames})} triple |
| 40 | representing time in absolute time code into the corresponding CD |
| 41 | frame number. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 42 | \end{funcdesc} |
| 43 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 44 | \begin{funcdesc}{open}{\optional{device\optional{, mode}}} |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 45 | Open the CD-ROM device. The return value is an opaque player object; |
| 46 | methods of the player object are described below. The device is the |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 47 | name of the SCSI device file, e.g. \code{'/dev/scsi/sc0d4l0'}, or |
| 48 | \code{None}. If omitted or \code{None}, the hardware inventory is |
| 49 | consulted to locate a CD-ROM drive. The \var{mode}, if not omited, |
| 50 | should be the string \code{'r'}. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 51 | \end{funcdesc} |
| 52 | |
| 53 | The module defines the following variables: |
| 54 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 55 | \begin{excdesc}{error} |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 56 | Exception raised on various errors. |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 57 | \end{excdesc} |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 58 | |
| 59 | \begin{datadesc}{DATASIZE} |
| 60 | The size of one frame's worth of audio data. This is the size of the |
| 61 | audio data as passed to the callback of type \code{audio}. |
| 62 | \end{datadesc} |
| 63 | |
| 64 | \begin{datadesc}{BLOCKSIZE} |
| 65 | The size of one uninterpreted frame of audio data. |
| 66 | \end{datadesc} |
| 67 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 68 | The following variables are states as returned by |
| 69 | \function{getstatus()}: |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 70 | |
| 71 | \begin{datadesc}{READY} |
| 72 | The drive is ready for operation loaded with an audio CD. |
| 73 | \end{datadesc} |
| 74 | |
| 75 | \begin{datadesc}{NODISC} |
| 76 | The drive does not have a CD loaded. |
| 77 | \end{datadesc} |
| 78 | |
| 79 | \begin{datadesc}{CDROM} |
| 80 | The drive is loaded with a CD-ROM. Subsequent play or read operations |
| 81 | will return I/O errors. |
| 82 | \end{datadesc} |
| 83 | |
| 84 | \begin{datadesc}{ERROR} |
| 85 | An error aoocurred while trying to read the disc or its table of |
| 86 | contents. |
| 87 | \end{datadesc} |
| 88 | |
| 89 | \begin{datadesc}{PLAYING} |
| 90 | The drive is in CD player mode playing an audio CD through its audio |
| 91 | jacks. |
| 92 | \end{datadesc} |
| 93 | |
| 94 | \begin{datadesc}{PAUSED} |
| 95 | The drive is in CD layer mode with play paused. |
| 96 | \end{datadesc} |
| 97 | |
| 98 | \begin{datadesc}{STILL} |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 99 | The equivalent of \constant{PAUSED} on older (non 3301) model Toshiba |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 100 | CD-ROM drives. Such drives have never been shipped by SGI. |
| 101 | \end{datadesc} |
| 102 | |
Guido van Rossum | d45c156 | 1995-03-30 11:47:50 +0000 | [diff] [blame] | 103 | \begin{datadesc}{audio} |
| 104 | \dataline{pnum} |
| 105 | \dataline{index} |
| 106 | \dataline{ptime} |
| 107 | \dataline{atime} |
| 108 | \dataline{catalog} |
| 109 | \dataline{ident} |
| 110 | \dataline{control} |
| 111 | Integer constants describing the various types of parser callbacks |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 112 | that can be set by the \method{addcallback()} method of CD parser |
Guido van Rossum | d45c156 | 1995-03-30 11:47:50 +0000 | [diff] [blame] | 113 | objects (see below). |
| 114 | \end{datadesc} |
| 115 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 116 | Player objects (returned by \function{open()}) have the following |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 117 | methods: |
| 118 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 119 | \setindexsubitem{(CD player method)} |
Guido van Rossum | d45c156 | 1995-03-30 11:47:50 +0000 | [diff] [blame] | 120 | |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 121 | \begin{funcdesc}{allowremoval}{} |
| 122 | Unlocks the eject button on the CD-ROM drive permitting the user to |
| 123 | eject the caddy if desired. |
| 124 | \end{funcdesc} |
| 125 | |
| 126 | \begin{funcdesc}{bestreadsize}{} |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 127 | Returns the best value to use for the \var{num_frames} parameter of |
| 128 | the \method{readda()} method. Best is defined as the value that |
| 129 | permits a continuous flow of data from the CD-ROM drive. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 130 | \end{funcdesc} |
| 131 | |
| 132 | \begin{funcdesc}{close}{} |
| 133 | Frees the resources associated with the player object. After calling |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 134 | \method{close()}, the methods of the object should no longer be used. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 135 | \end{funcdesc} |
| 136 | |
| 137 | \begin{funcdesc}{eject}{} |
| 138 | Ejects the caddy from the CD-ROM drive. |
| 139 | \end{funcdesc} |
| 140 | |
| 141 | \begin{funcdesc}{getstatus}{} |
| 142 | Returns information pertaining to the current state of the CD-ROM |
| 143 | drive. The returned information is a tuple with the following values: |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 144 | \var{state}, \var{track}, \var{rtime}, \var{atime}, \var{ttime}, |
| 145 | \var{first}, \var{last}, \var{scsi_audio}, \var{cur_block}. |
| 146 | \var{rtime} is the time relative to the start of the current track; |
| 147 | \var{atime} is the time relative to the beginning of the disc; |
| 148 | \var{ttime} is the total time on the disc. For more information on |
| 149 | the meaning of the values, see the man page \manpage{CDgetstatus}{3dm}. |
| 150 | The value of \var{state} is one of the following: \constant{ERROR}, |
| 151 | \constant{NODISC}, \constant{READY}, \constant{PLAYING}, |
| 152 | \constant{PAUSED}, \constant{STILL}, or \constant{CDROM}. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 153 | \end{funcdesc} |
| 154 | |
| 155 | \begin{funcdesc}{gettrackinfo}{track} |
| 156 | Returns information about the specified track. The returned |
| 157 | information is a tuple consisting of two elements, the start time of |
| 158 | the track and the duration of the track. |
| 159 | \end{funcdesc} |
| 160 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 161 | \begin{funcdesc}{msftoblock}{min, sec, frame} |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 162 | Converts a minutes, seconds, frames triple representing a time in |
| 163 | absolute time code into the corresponding logical block number for the |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 164 | given CD-ROM drive. You should use \function{msftoframe()} rather than |
| 165 | \method{msftoblock()} for comparing times. The logical block number |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 166 | differs from the frame number by an offset required by certain CD-ROM |
| 167 | drives. |
| 168 | \end{funcdesc} |
| 169 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 170 | \begin{funcdesc}{play}{start, play} |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 171 | Starts playback of an audio CD in the CD-ROM drive at the specified |
| 172 | track. The audio output appears on the CD-ROM drive's headphone and |
| 173 | audio jacks (if fitted). Play stops at the end of the disc. |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 174 | \var{start} is the number of the track at which to start playing the |
| 175 | CD; if \var{play} is 0, the CD will be set to an initial paused |
| 176 | state. The method \method{togglepause()} can then be used to commence |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 177 | play. |
| 178 | \end{funcdesc} |
| 179 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 180 | \begin{funcdesc}{playabs}{minutes, seconds, frames, play} |
| 181 | Like \method{play()}, except that the start is given in minutes, |
| 182 | seconds, and frames instead of a track number. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 183 | \end{funcdesc} |
| 184 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 185 | \begin{funcdesc}{playtrack}{start, play} |
| 186 | Like \method{play()}, except that playing stops at the end of the |
| 187 | track. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 188 | \end{funcdesc} |
| 189 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 190 | \begin{funcdesc}{playtrackabs}{track, minutes, seconds, frames, play} |
| 191 | Like \method{play()}, except that playing begins at the spcified |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 192 | absolute time and ends at the end of the specified track. |
| 193 | \end{funcdesc} |
| 194 | |
| 195 | \begin{funcdesc}{preventremoval}{} |
| 196 | Locks the eject button on the CD-ROM drive thus preventing the user |
| 197 | from arbitrarily ejecting the caddy. |
| 198 | \end{funcdesc} |
| 199 | |
| 200 | \begin{funcdesc}{readda}{num_frames} |
| 201 | Reads the specified number of frames from an audio CD mounted in the |
| 202 | CD-ROM drive. The return value is a string representing the audio |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 203 | frames. This string can be passed unaltered to the |
| 204 | \method{parseframe()} method of the parser object. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 205 | \end{funcdesc} |
| 206 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 207 | \begin{funcdesc}{seek}{minutes, seconds, frames} |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 208 | Sets the pointer that indicates the starting point of the next read of |
| 209 | digital audio data from a CD-ROM. The pointer is set to an absolute |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 210 | time code location specified in \var{minutes}, \var{seconds}, and |
| 211 | \var{frames}. The return value is the logical block number to which |
| 212 | the pointer has been set. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 213 | \end{funcdesc} |
| 214 | |
| 215 | \begin{funcdesc}{seekblock}{block} |
| 216 | Sets the pointer that indicates the starting point of the next read of |
| 217 | digital audio data from a CD-ROM. The pointer is set to the specified |
| 218 | logical block number. The return value is the logical block number to |
| 219 | which the pointer has been set. |
| 220 | \end{funcdesc} |
| 221 | |
| 222 | \begin{funcdesc}{seektrack}{track} |
| 223 | Sets the pointer that indicates the starting point of the next read of |
| 224 | digital audio data from a CD-ROM. The pointer is set to the specified |
| 225 | track. The return value is the logical block number to which the |
| 226 | pointer has been set. |
| 227 | \end{funcdesc} |
| 228 | |
| 229 | \begin{funcdesc}{stop}{} |
| 230 | Stops the current playing operation. |
| 231 | \end{funcdesc} |
| 232 | |
| 233 | \begin{funcdesc}{togglepause}{} |
| 234 | Pauses the CD if it is playing, and makes it play if it is paused. |
| 235 | \end{funcdesc} |
| 236 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 237 | Parser objects (returned by \function{createparser()}) have the |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 238 | following methods: |
| 239 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 240 | \setindexsubitem{(CD parser method)} |
Guido van Rossum | d45c156 | 1995-03-30 11:47:50 +0000 | [diff] [blame] | 241 | |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 242 | \begin{funcdesc}{addcallback}{type, func, arg} |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 243 | Adds a callback for the parser. The parser has callbacks for eight |
Guido van Rossum | d45c156 | 1995-03-30 11:47:50 +0000 | [diff] [blame] | 244 | different types of data in the digital audio data stream. Constants |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 245 | for these types are defined at the \module{cd} module level (see above). |
| 246 | The callback is called as follows: \code{\var{func}(\var{arg}, type, |
| 247 | data)}, where \var{arg} is the user supplied argument, \var{type} is |
| 248 | the particular type of callback, and \var{data} is the data returned |
| 249 | for this \var{type} of callback. The type of the data depends on the |
| 250 | \var{type} of callback as follows: |
| 251 | |
| 252 | \begin{tableii}{|l|l|}{code}{Type}{Value} |
| 253 | \lineii{audio}{String which can be passed unmodified to |
| 254 | \function{al.writesamps()}.} |
| 255 | \lineii{pnum}{Integer giving the program (track) number.} |
| 256 | \lineii{index}{Integer giving the index number.} |
| 257 | \lineii{ptime}{Tuple consisting of the program time in minutes, |
| 258 | seconds, and frames.} |
| 259 | \lineii{atime}{Tuple consisting of the absolute time in minutes, |
| 260 | seconds, and frames.} |
| 261 | \lineii{catalog}{String of 13 characters, giving the catalog number |
| 262 | of the CD.} |
| 263 | \lineii{ident}{String of 12 characters, giving the ISRC |
| 264 | identification number of the recording. \\ |
| 265 | &The string consists of two characters country code, three characters |
| 266 | owner code, \\ |
| 267 | &two characters giving the year, and five characters giving a serial number.} |
| 268 | \lineii{control}{Integer giving the control bits from the CD |
| 269 | subcode data} |
| 270 | \end{tableii} |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 271 | \end{funcdesc} |
| 272 | |
| 273 | \begin{funcdesc}{deleteparser}{} |
| 274 | Deletes the parser and frees the memory it was using. The object |
| 275 | should not be used after this call. This call is done automatically |
| 276 | when the last reference to the object is removed. |
| 277 | \end{funcdesc} |
| 278 | |
| 279 | \begin{funcdesc}{parseframe}{frame} |
| 280 | Parses one or more frames of digital audio data from a CD such as |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 281 | returned by \method{readda()}. It determines which subcodes are |
| 282 | present in the data. If these subcodes have changed since the last |
| 283 | frame, then \method{parseframe()} executes a callback of the |
| 284 | appropriate type passing to it the subcode data found in the frame. |
| 285 | Unlike the \C{} function, more than one frame of digital audio data |
| 286 | can be passed to this method. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 287 | \end{funcdesc} |
| 288 | |
| 289 | \begin{funcdesc}{removecallback}{type} |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 290 | Removes the callback for the given \var{type}. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 291 | \end{funcdesc} |
| 292 | |
| 293 | \begin{funcdesc}{resetparser}{} |
| 294 | Resets the fields of the parser used for tracking subcodes to an |
Fred Drake | d98329c | 1998-03-16 06:38:42 +0000 | [diff] [blame^] | 295 | initial state. \method{resetparser()} should be called after the disc |
| 296 | has been changed. |
Sjoerd Mullender | ffd6de1 | 1995-03-28 11:56:52 +0000 | [diff] [blame] | 297 | \end{funcdesc} |