blob: 656d1569eaa3101de847e8932a2bb3df7a2f3c3d [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{cd} ---
2 Interface to the CD-ROM on Silicon Graphics systems.}
Fred Drakeb91e9341998-07-23 17:59:49 +00003\declaremodule{builtin}{cd}
4
5\modulesynopsis{Interface to the CD-ROM on Silicon Graphics systems.}
6
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +00007
8This module provides an interface to the Silicon Graphics CD library.
9It is available only on Silicon Graphics systems.
10
11The way the library works is as follows. A program opens the CD-ROM
Fred Draked98329c1998-03-16 06:38:42 +000012device with \function{open()} and creates a parser to parse the data
13from the CD with \function{createparser()}. The object returned by
14\function{open()} can be used to read data from the CD, but also to get
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000015status information for the CD-ROM device, and to get information about
16the CD, such as the table of contents. Data from the CD is passed to
17the parser, which parses the frames, and calls any callback
18functions that have previously been added.
19
20An audio CD is divided into \dfn{tracks} or \dfn{programs} (the terms
21are used interchangeably). Tracks can be subdivided into
22\dfn{indices}. An audio CD contains a \dfn{table of contents} which
23gives the starts of the tracks on the CD. Index 0 is usually the
24pause before the start of a track. The start of the track as given by
25the table of contents is normally the start of index 1.
26
27Positions on a CD can be represented in two ways. Either a frame
28number or a tuple of three values, minutes, seconds and frames. Most
29functions use the latter representation. Positions can be both
30relative to the beginning of the CD, and to the beginning of the
31track.
32
Fred Draked98329c1998-03-16 06:38:42 +000033Module \module{cd} defines the following functions and constants:
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000034
Guido van Rossumd45c1561995-03-30 11:47:50 +000035
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000036\begin{funcdesc}{createparser}{}
37Create and return an opaque parser object. The methods of the parser
38object are described below.
39\end{funcdesc}
40
Fred Draked98329c1998-03-16 06:38:42 +000041\begin{funcdesc}{msftoframe}{minutes, seconds, frames}
42Converts a \code{(\var{minutes}, \var{seconds}, \var{frames})} triple
43representing time in absolute time code into the corresponding CD
44frame number.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000045\end{funcdesc}
46
Fred Draked98329c1998-03-16 06:38:42 +000047\begin{funcdesc}{open}{\optional{device\optional{, mode}}}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000048Open the CD-ROM device. The return value is an opaque player object;
49methods of the player object are described below. The device is the
Fred Draked98329c1998-03-16 06:38:42 +000050name of the SCSI device file, e.g. \code{'/dev/scsi/sc0d4l0'}, or
51\code{None}. If omitted or \code{None}, the hardware inventory is
52consulted to locate a CD-ROM drive. The \var{mode}, if not omited,
53should be the string \code{'r'}.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000054\end{funcdesc}
55
56The module defines the following variables:
57
Fred Draked98329c1998-03-16 06:38:42 +000058\begin{excdesc}{error}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000059Exception raised on various errors.
Fred Draked98329c1998-03-16 06:38:42 +000060\end{excdesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000061
62\begin{datadesc}{DATASIZE}
63The size of one frame's worth of audio data. This is the size of the
64audio data as passed to the callback of type \code{audio}.
65\end{datadesc}
66
67\begin{datadesc}{BLOCKSIZE}
68The size of one uninterpreted frame of audio data.
69\end{datadesc}
70
Fred Draked98329c1998-03-16 06:38:42 +000071The following variables are states as returned by
72\function{getstatus()}:
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000073
74\begin{datadesc}{READY}
75The drive is ready for operation loaded with an audio CD.
76\end{datadesc}
77
78\begin{datadesc}{NODISC}
79The drive does not have a CD loaded.
80\end{datadesc}
81
82\begin{datadesc}{CDROM}
83The drive is loaded with a CD-ROM. Subsequent play or read operations
84will return I/O errors.
85\end{datadesc}
86
87\begin{datadesc}{ERROR}
88An error aoocurred while trying to read the disc or its table of
89contents.
90\end{datadesc}
91
92\begin{datadesc}{PLAYING}
93The drive is in CD player mode playing an audio CD through its audio
94jacks.
95\end{datadesc}
96
97\begin{datadesc}{PAUSED}
98The drive is in CD layer mode with play paused.
99\end{datadesc}
100
101\begin{datadesc}{STILL}
Fred Draked98329c1998-03-16 06:38:42 +0000102The equivalent of \constant{PAUSED} on older (non 3301) model Toshiba
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000103CD-ROM drives. Such drives have never been shipped by SGI.
104\end{datadesc}
105
Guido van Rossumd45c1561995-03-30 11:47:50 +0000106\begin{datadesc}{audio}
107\dataline{pnum}
108\dataline{index}
109\dataline{ptime}
110\dataline{atime}
111\dataline{catalog}
112\dataline{ident}
113\dataline{control}
114Integer constants describing the various types of parser callbacks
Fred Draked98329c1998-03-16 06:38:42 +0000115that can be set by the \method{addcallback()} method of CD parser
Guido van Rossumd45c1561995-03-30 11:47:50 +0000116objects (see below).
117\end{datadesc}
118
Fred Drakefc576191998-04-04 07:15:02 +0000119
120\subsection{Player Objects}
121\label{player-objects}
122
Fred Draked98329c1998-03-16 06:38:42 +0000123Player objects (returned by \function{open()}) have the following
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000124methods:
125
Fred Drakefc576191998-04-04 07:15:02 +0000126\begin{methoddesc}[CD player]{allowremoval}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000127Unlocks the eject button on the CD-ROM drive permitting the user to
128eject the caddy if desired.
Fred Drakefc576191998-04-04 07:15:02 +0000129\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000130
Fred Drakefc576191998-04-04 07:15:02 +0000131\begin{methoddesc}[CD player]{bestreadsize}{}
Fred Draked98329c1998-03-16 06:38:42 +0000132Returns the best value to use for the \var{num_frames} parameter of
133the \method{readda()} method. Best is defined as the value that
134permits a continuous flow of data from the CD-ROM drive.
Fred Drakefc576191998-04-04 07:15:02 +0000135\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000136
Fred Drakefc576191998-04-04 07:15:02 +0000137\begin{methoddesc}[CD player]{close}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000138Frees the resources associated with the player object. After calling
Fred Draked98329c1998-03-16 06:38:42 +0000139\method{close()}, the methods of the object should no longer be used.
Fred Drakefc576191998-04-04 07:15:02 +0000140\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000141
Fred Drakefc576191998-04-04 07:15:02 +0000142\begin{methoddesc}[CD player]{eject}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000143Ejects the caddy from the CD-ROM drive.
Fred Drakefc576191998-04-04 07:15:02 +0000144\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000145
Fred Drakefc576191998-04-04 07:15:02 +0000146\begin{methoddesc}[CD player]{getstatus}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000147Returns information pertaining to the current state of the CD-ROM
148drive. The returned information is a tuple with the following values:
Fred Draked98329c1998-03-16 06:38:42 +0000149\var{state}, \var{track}, \var{rtime}, \var{atime}, \var{ttime},
150\var{first}, \var{last}, \var{scsi_audio}, \var{cur_block}.
151\var{rtime} is the time relative to the start of the current track;
152\var{atime} is the time relative to the beginning of the disc;
153\var{ttime} is the total time on the disc. For more information on
154the meaning of the values, see the man page \manpage{CDgetstatus}{3dm}.
155The value of \var{state} is one of the following: \constant{ERROR},
156\constant{NODISC}, \constant{READY}, \constant{PLAYING},
157\constant{PAUSED}, \constant{STILL}, or \constant{CDROM}.
Fred Drakefc576191998-04-04 07:15:02 +0000158\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000159
Fred Drakefc576191998-04-04 07:15:02 +0000160\begin{methoddesc}[CD player]{gettrackinfo}{track}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000161Returns information about the specified track. The returned
162information is a tuple consisting of two elements, the start time of
163the track and the duration of the track.
Fred Drakefc576191998-04-04 07:15:02 +0000164\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000165
Fred Drakefc576191998-04-04 07:15:02 +0000166\begin{methoddesc}[CD player]{msftoblock}{min, sec, frame}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000167Converts a minutes, seconds, frames triple representing a time in
168absolute time code into the corresponding logical block number for the
Fred Draked98329c1998-03-16 06:38:42 +0000169given CD-ROM drive. You should use \function{msftoframe()} rather than
170\method{msftoblock()} for comparing times. The logical block number
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000171differs from the frame number by an offset required by certain CD-ROM
172drives.
Fred Drakefc576191998-04-04 07:15:02 +0000173\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000174
Fred Drakefc576191998-04-04 07:15:02 +0000175\begin{methoddesc}[CD player]{play}{start, play}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000176Starts playback of an audio CD in the CD-ROM drive at the specified
177track. The audio output appears on the CD-ROM drive's headphone and
178audio jacks (if fitted). Play stops at the end of the disc.
Fred Draked98329c1998-03-16 06:38:42 +0000179\var{start} is the number of the track at which to start playing the
180CD; if \var{play} is 0, the CD will be set to an initial paused
181state. The method \method{togglepause()} can then be used to commence
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000182play.
Fred Drakefc576191998-04-04 07:15:02 +0000183\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000184
Fred Drakefc576191998-04-04 07:15:02 +0000185\begin{methoddesc}[CD player]{playabs}{minutes, seconds, frames, play}
Fred Draked98329c1998-03-16 06:38:42 +0000186Like \method{play()}, except that the start is given in minutes,
187seconds, and frames instead of a track number.
Fred Drakefc576191998-04-04 07:15:02 +0000188\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000189
Fred Drakefc576191998-04-04 07:15:02 +0000190\begin{methoddesc}[CD player]{playtrack}{start, play}
Fred Draked98329c1998-03-16 06:38:42 +0000191Like \method{play()}, except that playing stops at the end of the
192track.
Fred Drakefc576191998-04-04 07:15:02 +0000193\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000194
Fred Drakefc576191998-04-04 07:15:02 +0000195\begin{methoddesc}[CD player]{playtrackabs}{track, minutes, seconds, frames, play}
Fred Draked98329c1998-03-16 06:38:42 +0000196Like \method{play()}, except that playing begins at the spcified
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000197absolute time and ends at the end of the specified track.
Fred Drakefc576191998-04-04 07:15:02 +0000198\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000199
Fred Drakefc576191998-04-04 07:15:02 +0000200\begin{methoddesc}[CD player]{preventremoval}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000201Locks the eject button on the CD-ROM drive thus preventing the user
202from arbitrarily ejecting the caddy.
Fred Drakefc576191998-04-04 07:15:02 +0000203\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000204
Fred Drakefc576191998-04-04 07:15:02 +0000205\begin{methoddesc}[CD player]{readda}{num_frames}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000206Reads the specified number of frames from an audio CD mounted in the
207CD-ROM drive. The return value is a string representing the audio
Fred Draked98329c1998-03-16 06:38:42 +0000208frames. This string can be passed unaltered to the
209\method{parseframe()} method of the parser object.
Fred Drakefc576191998-04-04 07:15:02 +0000210\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000211
Fred Drakefc576191998-04-04 07:15:02 +0000212\begin{methoddesc}[CD player]{seek}{minutes, seconds, frames}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000213Sets the pointer that indicates the starting point of the next read of
214digital audio data from a CD-ROM. The pointer is set to an absolute
Fred Draked98329c1998-03-16 06:38:42 +0000215time code location specified in \var{minutes}, \var{seconds}, and
216\var{frames}. The return value is the logical block number to which
217the pointer has been set.
Fred Drakefc576191998-04-04 07:15:02 +0000218\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000219
Fred Drakefc576191998-04-04 07:15:02 +0000220\begin{methoddesc}[CD player]{seekblock}{block}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000221Sets 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
223logical block number. The return value is the logical block number to
224which the pointer has been set.
Fred Drakefc576191998-04-04 07:15:02 +0000225\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000226
Fred Drakefc576191998-04-04 07:15:02 +0000227\begin{methoddesc}[CD player]{seektrack}{track}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000228Sets the pointer that indicates the starting point of the next read of
229digital audio data from a CD-ROM. The pointer is set to the specified
230track. The return value is the logical block number to which the
231pointer has been set.
Fred Drakefc576191998-04-04 07:15:02 +0000232\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000233
Fred Drakefc576191998-04-04 07:15:02 +0000234\begin{methoddesc}[CD player]{stop}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000235Stops the current playing operation.
Fred Drakefc576191998-04-04 07:15:02 +0000236\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000237
Fred Drakefc576191998-04-04 07:15:02 +0000238\begin{methoddesc}[CD player]{togglepause}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000239Pauses the CD if it is playing, and makes it play if it is paused.
Fred Drakefc576191998-04-04 07:15:02 +0000240\end{methoddesc}
241
242
243\subsection{Parser Objects}
244\label{cd-parser-objects}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000245
Fred Draked98329c1998-03-16 06:38:42 +0000246Parser objects (returned by \function{createparser()}) have the
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000247following methods:
248
Fred Drakefc576191998-04-04 07:15:02 +0000249\begin{methoddesc}[CD parser]{addcallback}{type, func, arg}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000250Adds a callback for the parser. The parser has callbacks for eight
Guido van Rossumd45c1561995-03-30 11:47:50 +0000251different types of data in the digital audio data stream. Constants
Fred Draked98329c1998-03-16 06:38:42 +0000252for these types are defined at the \module{cd} module level (see above).
253The callback is called as follows: \code{\var{func}(\var{arg}, type,
254data)}, where \var{arg} is the user supplied argument, \var{type} is
255the particular type of callback, and \var{data} is the data returned
256for this \var{type} of callback. The type of the data depends on the
257\var{type} of callback as follows:
258
Fred Drakeee601911998-04-11 20:53:03 +0000259\begin{tableii}{l|p{4in}}{code}{Type}{Value}
Fred Draked98329c1998-03-16 06:38:42 +0000260 \lineii{audio}{String which can be passed unmodified to
261\function{al.writesamps()}.}
262 \lineii{pnum}{Integer giving the program (track) number.}
263 \lineii{index}{Integer giving the index number.}
264 \lineii{ptime}{Tuple consisting of the program time in minutes,
265seconds, and frames.}
266 \lineii{atime}{Tuple consisting of the absolute time in minutes,
267seconds, and frames.}
268 \lineii{catalog}{String of 13 characters, giving the catalog number
269of the CD.}
270 \lineii{ident}{String of 12 characters, giving the ISRC
Fred Drake0d213d31998-04-11 16:40:46 +0000271identification number of the recording. The string consists of two
272characters country code, three characters owner code, two characters
273giving the year, and five characters giving a serial number.}
Fred Draked98329c1998-03-16 06:38:42 +0000274 \lineii{control}{Integer giving the control bits from the CD
275subcode data}
276\end{tableii}
Fred Drakefc576191998-04-04 07:15:02 +0000277\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000278
Fred Drakefc576191998-04-04 07:15:02 +0000279\begin{methoddesc}[CD parser]{deleteparser}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000280Deletes the parser and frees the memory it was using. The object
281should not be used after this call. This call is done automatically
282when the last reference to the object is removed.
Fred Drakefc576191998-04-04 07:15:02 +0000283\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000284
Fred Drakefc576191998-04-04 07:15:02 +0000285\begin{methoddesc}[CD parser]{parseframe}{frame}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000286Parses one or more frames of digital audio data from a CD such as
Fred Draked98329c1998-03-16 06:38:42 +0000287returned by \method{readda()}. It determines which subcodes are
288present in the data. If these subcodes have changed since the last
289frame, then \method{parseframe()} executes a callback of the
290appropriate type passing to it the subcode data found in the frame.
291Unlike the \C{} function, more than one frame of digital audio data
292can be passed to this method.
Fred Drakefc576191998-04-04 07:15:02 +0000293\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000294
Fred Drakefc576191998-04-04 07:15:02 +0000295\begin{methoddesc}[CD parser]{removecallback}{type}
Fred Draked98329c1998-03-16 06:38:42 +0000296Removes the callback for the given \var{type}.
Fred Drakefc576191998-04-04 07:15:02 +0000297\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000298
Fred Drakefc576191998-04-04 07:15:02 +0000299\begin{methoddesc}[CD parser]{resetparser}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000300Resets the fields of the parser used for tracking subcodes to an
Fred Draked98329c1998-03-16 06:38:42 +0000301initial state. \method{resetparser()} should be called after the disc
302has been changed.
Fred Drakefc576191998-04-04 07:15:02 +0000303\end{methoddesc}