blob: 98ed56026113c84ca200d13de6d888ec227c96d2 [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
Guido van Rossumd45c1561995-03-30 11:47:50 +000029Module \code{cd} defines the following functions and constants:
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000030
31\renewcommand{\indexsubitem}{(in module cd)}
Guido van Rossumd45c1561995-03-30 11:47:50 +000032
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000033\begin{funcdesc}{createparser}{}
34Create and return an opaque parser object. The methods of the parser
35object are described below.
36\end{funcdesc}
37
38\begin{funcdesc}{msftoframe}{min\, sec\, frame}
39Converts a \code{(minutes, seconds, frames)} triple representing time
40in absolute time code into the corresponding CD frame number.
41\end{funcdesc}
42
43\begin{funcdesc}{open}{\optional{device\optional{\, mode}}}
44Open the CD-ROM device. The return value is an opaque player object;
45methods of the player object are described below. The device is the
46name of the SCSI device file, e.g. /dev/scsi/sc0d4l0, or \code{None}.
47If omited or \code{None}, the hardware inventory is consulted to
48locate a CD-ROM drive. The \code{mode}, if not omited, should be the
49string 'r'.
50\end{funcdesc}
51
52The module defines the following variables:
53
54\begin{datadesc}{error}
55Exception raised on various errors.
56\end{datadesc}
57
58\begin{datadesc}{DATASIZE}
59The size of one frame's worth of audio data. This is the size of the
60audio data as passed to the callback of type \code{audio}.
61\end{datadesc}
62
63\begin{datadesc}{BLOCKSIZE}
64The size of one uninterpreted frame of audio data.
65\end{datadesc}
66
67The following variables are states as returned by \code{getstatus}:
68
69\begin{datadesc}{READY}
70The drive is ready for operation loaded with an audio CD.
71\end{datadesc}
72
73\begin{datadesc}{NODISC}
74The drive does not have a CD loaded.
75\end{datadesc}
76
77\begin{datadesc}{CDROM}
78The drive is loaded with a CD-ROM. Subsequent play or read operations
79will return I/O errors.
80\end{datadesc}
81
82\begin{datadesc}{ERROR}
83An error aoocurred while trying to read the disc or its table of
84contents.
85\end{datadesc}
86
87\begin{datadesc}{PLAYING}
88The drive is in CD player mode playing an audio CD through its audio
89jacks.
90\end{datadesc}
91
92\begin{datadesc}{PAUSED}
93The drive is in CD layer mode with play paused.
94\end{datadesc}
95
96\begin{datadesc}{STILL}
97The equivalent of \code{PAUSED} on older (non 3301) model Toshiba
98CD-ROM drives. Such drives have never been shipped by SGI.
99\end{datadesc}
100
Guido van Rossumd45c1561995-03-30 11:47:50 +0000101\begin{datadesc}{audio}
102\dataline{pnum}
103\dataline{index}
104\dataline{ptime}
105\dataline{atime}
106\dataline{catalog}
107\dataline{ident}
108\dataline{control}
109Integer constants describing the various types of parser callbacks
110that can be set by the \code{addcallback()} method of CD parser
111objects (see below).
112\end{datadesc}
113
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000114Player objects (returned by \code{cd.open()}) have the following
115methods:
116
117\renewcommand{\indexsubitem}{(CD player object method)}
Guido van Rossumd45c1561995-03-30 11:47:50 +0000118
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000119\begin{funcdesc}{allowremoval}{}
120Unlocks the eject button on the CD-ROM drive permitting the user to
121eject the caddy if desired.
122\end{funcdesc}
123
124\begin{funcdesc}{bestreadsize}{}
125Returns the best value to use for the \code{num_frames} parameter of
126the \code{readda} method. Best is defined as the value that permits a
127continuous flow of data from the CD-ROM drive.
128\end{funcdesc}
129
130\begin{funcdesc}{close}{}
131Frees the resources associated with the player object. After calling
132\code{close}, the methods of the object should no longer be used.
133\end{funcdesc}
134
135\begin{funcdesc}{eject}{}
136Ejects the caddy from the CD-ROM drive.
137\end{funcdesc}
138
139\begin{funcdesc}{getstatus}{}
140Returns information pertaining to the current state of the CD-ROM
141drive. The returned information is a tuple with the following values:
142\code{state}, \code{track}, \code{rtime}, \code{atime}, \code{ttime},
143\code{first}, \code{last}, \code{scsi_audio}, \code{cur_block}.
144\code{rtime} is the time relative to the start of the current track;
145\code{atime} is the time relative to the beginning of the disc;
146\code{ttime} is the total time on the disc. For more information on
147the meaning of the values, see the manual for CDgetstatus.
148The value of \code{state} is one of the following: \code{cd.ERROR},
149\code{cd.NODISC}, \code{cd.READY}, \code{cd.PLAYING},
150\code{cd.PAUSED}, \code{cd.STILL}, or \code{cd.CDROM}.
151\end{funcdesc}
152
153\begin{funcdesc}{gettrackinfo}{track}
154Returns information about the specified track. The returned
155information is a tuple consisting of two elements, the start time of
156the track and the duration of the track.
157\end{funcdesc}
158
159\begin{funcdesc}{msftoblock}{min\, sec\, frame}
160Converts a minutes, seconds, frames triple representing a time in
161absolute time code into the corresponding logical block number for the
162given CD-ROM drive. You should use \code{cd.msftoframe()} rather than
163\code{msftoblock()} for comparing times. The logical block number
164differs from the frame number by an offset required by certain CD-ROM
165drives.
166\end{funcdesc}
167
168\begin{funcdesc}{play}{start\, play}
169Starts playback of an audio CD in the CD-ROM drive at the specified
170track. The audio output appears on the CD-ROM drive's headphone and
171audio jacks (if fitted). Play stops at the end of the disc.
172\code{start} is the number of the track at which to start playing the
173CD; if \code{play} is 0, the CD will be set to an initial paused
174state. The method \code{togglepause()} can then be used to commence
175play.
176\end{funcdesc}
177
178\begin{funcdesc}{playabs}{min\, sec\, frame\, play}
179Like \code{play()}, except that the start is given in minutes,
180seconds, frames instead of a track number.
181\end{funcdesc}
182
183\begin{funcdesc}{playtrack}{start\, play}
184Like \code{play()}, except that playing stops at the end of the track.
185\end{funcdesc}
186
187\begin{funcdesc}{playtrackabs}{track\, min\, sec\, frame\, play}
188Like \code{play()}, except that playing begins at the spcified
189absolute time and ends at the end of the specified track.
190\end{funcdesc}
191
192\begin{funcdesc}{preventremoval}{}
193Locks the eject button on the CD-ROM drive thus preventing the user
194from arbitrarily ejecting the caddy.
195\end{funcdesc}
196
197\begin{funcdesc}{readda}{num_frames}
198Reads the specified number of frames from an audio CD mounted in the
199CD-ROM drive. The return value is a string representing the audio
200frames. This string can be passed unaltered to the \code{parseframe}
201method of the parser object.
202\end{funcdesc}
203
204\begin{funcdesc}{seek}{min\, sec\, frame}
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 an absolute
207time code location specified in minutes, seconds, and frames. The
208return value is the logical block number to which the pointer has been
209set.
210\end{funcdesc}
211
212\begin{funcdesc}{seekblock}{block}
213Sets the pointer that indicates the starting point of the next read of
214digital audio data from a CD-ROM. The pointer is set to the specified
215logical block number. The return value is the logical block number to
216which the pointer has been set.
217\end{funcdesc}
218
219\begin{funcdesc}{seektrack}{track}
220Sets the pointer that indicates the starting point of the next read of
221digital audio data from a CD-ROM. The pointer is set to the specified
222track. The return value is the logical block number to which the
223pointer has been set.
224\end{funcdesc}
225
226\begin{funcdesc}{stop}{}
227Stops the current playing operation.
228\end{funcdesc}
229
230\begin{funcdesc}{togglepause}{}
231Pauses the CD if it is playing, and makes it play if it is paused.
232\end{funcdesc}
233
234Parser objects (returned by \code{cd.createparser()}) have the
235following methods:
236
Guido van Rossumd45c1561995-03-30 11:47:50 +0000237\renewcommand{\indexsubitem}{(CD parser object method)}
238
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000239\begin{funcdesc}{addcallback}{type\, func\, arg}
240Adds a callback for the parser. The parser has callbacks for eight
Guido van Rossumd45c1561995-03-30 11:47:50 +0000241different types of data in the digital audio data stream. Constants
242for these types are defined at the \code{cd} module level (see above).
243The callback is called as follows: \code{func(arg, type, data)}, where
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000244\code{arg} is the user supplied argument, \code{type} is the
245particular type of callback, and \code{data} is the data returned for
246this \code{type} of callback. The type of the data depends on the
Guido van Rossumd45c1561995-03-30 11:47:50 +0000247\code{type} of callback as follows:
248\begin{description}
249\item[\code{cd.audio}: ]
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000250The argument is a string which can be passed unmodified to
Guido van Rossumd45c1561995-03-30 11:47:50 +0000251\code{al.writesamps()}.
252\item[\code{cd.pnum}: ]
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000253The argument is an integer giving the program (track) number.
Guido van Rossumd45c1561995-03-30 11:47:50 +0000254\item[\code{cd.index}: ]
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000255The argument is an integer giving the index number.
Guido van Rossumd45c1561995-03-30 11:47:50 +0000256\item[\code{cd.ptime}: ]
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000257The argument is a tuple consisting of the program time in minutes,
258seconds, and frames.
Guido van Rossumd45c1561995-03-30 11:47:50 +0000259\item[\code{cd.atime}: ]
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000260The argument is a tuple consisting of the absolute time in minutes,
261seconds, and frames.
Guido van Rossumd45c1561995-03-30 11:47:50 +0000262\item[\code{cd.catalog}: ]
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000263The argument is a string of 13 characters, giving the catalog number
264of the CD.
Guido van Rossumd45c1561995-03-30 11:47:50 +0000265\item[\code{cd.ident}: ]
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000266The argument is a string of 12 characters, giving the ISRC
267identification number of the recording. The string consists of two
268characters country code, three characters owner code, two characters
269giving the year, and five characters giving a serial number.
Guido van Rossumd45c1561995-03-30 11:47:50 +0000270\item[\code{cd.control}: ]
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000271The argument is an integer giving the control bits from the CD subcode
272data.
Guido van Rossumd45c1561995-03-30 11:47:50 +0000273\end{description}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000274\end{funcdesc}
275
276\begin{funcdesc}{deleteparser}{}
277Deletes the parser and frees the memory it was using. The object
278should not be used after this call. This call is done automatically
279when the last reference to the object is removed.
280\end{funcdesc}
281
282\begin{funcdesc}{parseframe}{frame}
283Parses one or more frames of digital audio data from a CD such as
284returned by \code{readda}. It determines which subcodes are present
285in the data. If these subcodes have changed since the last frame,
286then \code{parseframe} executes a callback of the appropriate type
287passing to it the subcode data found in the frame.
288Unlike the C function, more than one frame of digital audio data can
289be passed to this method.
290\end{funcdesc}
291
292\begin{funcdesc}{removecallback}{type}
293Removes the callback for the given \code{type}.
294\end{funcdesc}
295
296\begin{funcdesc}{resetparser}{}
297Resets the fields of the parser used for tracking subcodes to an
298initial state. \code{resetparser} should be called after the disc has
299been changed.
300\end{funcdesc}