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