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