blob: 7c114d8ccb5e21cb239cde18b1263de29cd7c851 [file] [log] [blame]
Fred Drakefc576191998-04-04 07:15:02 +00001\section{Built-in Module \module{cd}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{builtin}{cd}
3
4\modulesynopsis{Interface to the CD-ROM on Silicon Graphics systems.}
5
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +00006
7This module provides an interface to the Silicon Graphics CD library.
8It is available only on Silicon Graphics systems.
9
10The way the library works is as follows. A program opens the CD-ROM
Fred Draked98329c1998-03-16 06:38:42 +000011device with \function{open()} and creates a parser to parse the data
12from the CD with \function{createparser()}. The object returned by
13\function{open()} can be used to read data from the CD, but also to get
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000014status information for the CD-ROM device, and to get information about
15the CD, such as the table of contents. Data from the CD is passed to
16the parser, which parses the frames, and calls any callback
17functions that have previously been added.
18
19An audio CD is divided into \dfn{tracks} or \dfn{programs} (the terms
20are used interchangeably). Tracks can be subdivided into
21\dfn{indices}. An audio CD contains a \dfn{table of contents} which
22gives the starts of the tracks on the CD. Index 0 is usually the
23pause before the start of a track. The start of the track as given by
24the table of contents is normally the start of index 1.
25
26Positions on a CD can be represented in two ways. Either a frame
27number or a tuple of three values, minutes, seconds and frames. Most
28functions use the latter representation. Positions can be both
29relative to the beginning of the CD, and to the beginning of the
30track.
31
Fred Draked98329c1998-03-16 06:38:42 +000032Module \module{cd} defines the following functions and constants:
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000033
Guido van Rossumd45c1561995-03-30 11:47:50 +000034
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000035\begin{funcdesc}{createparser}{}
36Create and return an opaque parser object. The methods of the parser
37object are described below.
38\end{funcdesc}
39
Fred Draked98329c1998-03-16 06:38:42 +000040\begin{funcdesc}{msftoframe}{minutes, seconds, frames}
41Converts a \code{(\var{minutes}, \var{seconds}, \var{frames})} triple
42representing time in absolute time code into the corresponding CD
43frame number.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000044\end{funcdesc}
45
Fred Draked98329c1998-03-16 06:38:42 +000046\begin{funcdesc}{open}{\optional{device\optional{, mode}}}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000047Open the CD-ROM device. The return value is an opaque player object;
48methods of the player object are described below. The device is the
Fred Draked98329c1998-03-16 06:38:42 +000049name of the SCSI device file, e.g. \code{'/dev/scsi/sc0d4l0'}, or
50\code{None}. If omitted or \code{None}, the hardware inventory is
51consulted to locate a CD-ROM drive. The \var{mode}, if not omited,
52should be the string \code{'r'}.
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000053\end{funcdesc}
54
55The module defines the following variables:
56
Fred Draked98329c1998-03-16 06:38:42 +000057\begin{excdesc}{error}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000058Exception raised on various errors.
Fred Draked98329c1998-03-16 06:38:42 +000059\end{excdesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000060
61\begin{datadesc}{DATASIZE}
62The size of one frame's worth of audio data. This is the size of the
63audio data as passed to the callback of type \code{audio}.
64\end{datadesc}
65
66\begin{datadesc}{BLOCKSIZE}
67The size of one uninterpreted frame of audio data.
68\end{datadesc}
69
Fred Draked98329c1998-03-16 06:38:42 +000070The following variables are states as returned by
71\function{getstatus()}:
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +000072
73\begin{datadesc}{READY}
74The drive is ready for operation loaded with an audio CD.
75\end{datadesc}
76
77\begin{datadesc}{NODISC}
78The drive does not have a CD loaded.
79\end{datadesc}
80
81\begin{datadesc}{CDROM}
82The drive is loaded with a CD-ROM. Subsequent play or read operations
83will return I/O errors.
84\end{datadesc}
85
86\begin{datadesc}{ERROR}
87An error aoocurred while trying to read the disc or its table of
88contents.
89\end{datadesc}
90
91\begin{datadesc}{PLAYING}
92The drive is in CD player mode playing an audio CD through its audio
93jacks.
94\end{datadesc}
95
96\begin{datadesc}{PAUSED}
97The drive is in CD layer mode with play paused.
98\end{datadesc}
99
100\begin{datadesc}{STILL}
Fred Draked98329c1998-03-16 06:38:42 +0000101The equivalent of \constant{PAUSED} on older (non 3301) model Toshiba
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000102CD-ROM drives. Such drives have never been shipped by SGI.
103\end{datadesc}
104
Guido van Rossumd45c1561995-03-30 11:47:50 +0000105\begin{datadesc}{audio}
106\dataline{pnum}
107\dataline{index}
108\dataline{ptime}
109\dataline{atime}
110\dataline{catalog}
111\dataline{ident}
112\dataline{control}
113Integer constants describing the various types of parser callbacks
Fred Draked98329c1998-03-16 06:38:42 +0000114that can be set by the \method{addcallback()} method of CD parser
Guido van Rossumd45c1561995-03-30 11:47:50 +0000115objects (see below).
116\end{datadesc}
117
Fred Drakefc576191998-04-04 07:15:02 +0000118
119\subsection{Player Objects}
120\label{player-objects}
121
Fred Draked98329c1998-03-16 06:38:42 +0000122Player objects (returned by \function{open()}) have the following
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000123methods:
124
Fred Drakefc576191998-04-04 07:15:02 +0000125\begin{methoddesc}[CD player]{allowremoval}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000126Unlocks the eject button on the CD-ROM drive permitting the user to
127eject the caddy if desired.
Fred Drakefc576191998-04-04 07:15:02 +0000128\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000129
Fred Drakefc576191998-04-04 07:15:02 +0000130\begin{methoddesc}[CD player]{bestreadsize}{}
Fred Draked98329c1998-03-16 06:38:42 +0000131Returns the best value to use for the \var{num_frames} parameter of
132the \method{readda()} method. Best is defined as the value that
133permits a continuous flow of data from the CD-ROM drive.
Fred Drakefc576191998-04-04 07:15:02 +0000134\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000135
Fred Drakefc576191998-04-04 07:15:02 +0000136\begin{methoddesc}[CD player]{close}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000137Frees the resources associated with the player object. After calling
Fred Draked98329c1998-03-16 06:38:42 +0000138\method{close()}, the methods of the object should no longer be used.
Fred Drakefc576191998-04-04 07:15:02 +0000139\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000140
Fred Drakefc576191998-04-04 07:15:02 +0000141\begin{methoddesc}[CD player]{eject}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000142Ejects the caddy from the CD-ROM drive.
Fred Drakefc576191998-04-04 07:15:02 +0000143\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000144
Fred Drakefc576191998-04-04 07:15:02 +0000145\begin{methoddesc}[CD player]{getstatus}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000146Returns information pertaining to the current state of the CD-ROM
147drive. The returned information is a tuple with the following values:
Fred Draked98329c1998-03-16 06:38:42 +0000148\var{state}, \var{track}, \var{rtime}, \var{atime}, \var{ttime},
149\var{first}, \var{last}, \var{scsi_audio}, \var{cur_block}.
150\var{rtime} is the time relative to the start of the current track;
151\var{atime} is the time relative to the beginning of the disc;
152\var{ttime} is the total time on the disc. For more information on
153the meaning of the values, see the man page \manpage{CDgetstatus}{3dm}.
154The value of \var{state} is one of the following: \constant{ERROR},
155\constant{NODISC}, \constant{READY}, \constant{PLAYING},
156\constant{PAUSED}, \constant{STILL}, or \constant{CDROM}.
Fred Drakefc576191998-04-04 07:15:02 +0000157\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000158
Fred Drakefc576191998-04-04 07:15:02 +0000159\begin{methoddesc}[CD player]{gettrackinfo}{track}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000160Returns information about the specified track. The returned
161information is a tuple consisting of two elements, the start time of
162the track and the duration of the track.
Fred Drakefc576191998-04-04 07:15:02 +0000163\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000164
Fred Drakefc576191998-04-04 07:15:02 +0000165\begin{methoddesc}[CD player]{msftoblock}{min, sec, frame}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000166Converts a minutes, seconds, frames triple representing a time in
167absolute time code into the corresponding logical block number for the
Fred Draked98329c1998-03-16 06:38:42 +0000168given CD-ROM drive. You should use \function{msftoframe()} rather than
169\method{msftoblock()} for comparing times. The logical block number
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000170differs from the frame number by an offset required by certain CD-ROM
171drives.
Fred Drakefc576191998-04-04 07:15:02 +0000172\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000173
Fred Drakefc576191998-04-04 07:15:02 +0000174\begin{methoddesc}[CD player]{play}{start, play}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000175Starts playback of an audio CD in the CD-ROM drive at the specified
176track. The audio output appears on the CD-ROM drive's headphone and
177audio jacks (if fitted). Play stops at the end of the disc.
Fred Draked98329c1998-03-16 06:38:42 +0000178\var{start} is the number of the track at which to start playing the
179CD; if \var{play} is 0, the CD will be set to an initial paused
180state. The method \method{togglepause()} can then be used to commence
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000181play.
Fred Drakefc576191998-04-04 07:15:02 +0000182\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000183
Fred Drakefc576191998-04-04 07:15:02 +0000184\begin{methoddesc}[CD player]{playabs}{minutes, seconds, frames, play}
Fred Draked98329c1998-03-16 06:38:42 +0000185Like \method{play()}, except that the start is given in minutes,
186seconds, and frames instead of a track number.
Fred Drakefc576191998-04-04 07:15:02 +0000187\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000188
Fred Drakefc576191998-04-04 07:15:02 +0000189\begin{methoddesc}[CD player]{playtrack}{start, play}
Fred Draked98329c1998-03-16 06:38:42 +0000190Like \method{play()}, except that playing stops at the end of the
191track.
Fred Drakefc576191998-04-04 07:15:02 +0000192\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000193
Fred Drakefc576191998-04-04 07:15:02 +0000194\begin{methoddesc}[CD player]{playtrackabs}{track, minutes, seconds, frames, play}
Fred Draked98329c1998-03-16 06:38:42 +0000195Like \method{play()}, except that playing begins at the spcified
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000196absolute time and ends at the end of the specified track.
Fred Drakefc576191998-04-04 07:15:02 +0000197\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000198
Fred Drakefc576191998-04-04 07:15:02 +0000199\begin{methoddesc}[CD player]{preventremoval}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000200Locks the eject button on the CD-ROM drive thus preventing the user
201from arbitrarily ejecting the caddy.
Fred Drakefc576191998-04-04 07:15:02 +0000202\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000203
Fred Drakefc576191998-04-04 07:15:02 +0000204\begin{methoddesc}[CD player]{readda}{num_frames}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000205Reads the specified number of frames from an audio CD mounted in the
206CD-ROM drive. The return value is a string representing the audio
Fred Draked98329c1998-03-16 06:38:42 +0000207frames. This string can be passed unaltered to the
208\method{parseframe()} method of the parser object.
Fred Drakefc576191998-04-04 07:15:02 +0000209\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000210
Fred Drakefc576191998-04-04 07:15:02 +0000211\begin{methoddesc}[CD player]{seek}{minutes, seconds, frames}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000212Sets the pointer that indicates the starting point of the next read of
213digital audio data from a CD-ROM. The pointer is set to an absolute
Fred Draked98329c1998-03-16 06:38:42 +0000214time code location specified in \var{minutes}, \var{seconds}, and
215\var{frames}. The return value is the logical block number to which
216the pointer has been set.
Fred Drakefc576191998-04-04 07:15:02 +0000217\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000218
Fred Drakefc576191998-04-04 07:15:02 +0000219\begin{methoddesc}[CD player]{seekblock}{block}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000220Sets 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
222logical block number. The return value is the logical block number to
223which the pointer has been set.
Fred Drakefc576191998-04-04 07:15:02 +0000224\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000225
Fred Drakefc576191998-04-04 07:15:02 +0000226\begin{methoddesc}[CD player]{seektrack}{track}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000227Sets the pointer that indicates the starting point of the next read of
228digital audio data from a CD-ROM. The pointer is set to the specified
229track. The return value is the logical block number to which the
230pointer has been set.
Fred Drakefc576191998-04-04 07:15:02 +0000231\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000232
Fred Drakefc576191998-04-04 07:15:02 +0000233\begin{methoddesc}[CD player]{stop}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000234Stops the current playing operation.
Fred Drakefc576191998-04-04 07:15:02 +0000235\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000236
Fred Drakefc576191998-04-04 07:15:02 +0000237\begin{methoddesc}[CD player]{togglepause}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000238Pauses the CD if it is playing, and makes it play if it is paused.
Fred Drakefc576191998-04-04 07:15:02 +0000239\end{methoddesc}
240
241
242\subsection{Parser Objects}
243\label{cd-parser-objects}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000244
Fred Draked98329c1998-03-16 06:38:42 +0000245Parser objects (returned by \function{createparser()}) have the
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000246following methods:
247
Fred Drakefc576191998-04-04 07:15:02 +0000248\begin{methoddesc}[CD parser]{addcallback}{type, func, arg}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000249Adds a callback for the parser. The parser has callbacks for eight
Guido van Rossumd45c1561995-03-30 11:47:50 +0000250different types of data in the digital audio data stream. Constants
Fred Draked98329c1998-03-16 06:38:42 +0000251for these types are defined at the \module{cd} module level (see above).
252The callback is called as follows: \code{\var{func}(\var{arg}, type,
253data)}, where \var{arg} is the user supplied argument, \var{type} is
254the particular type of callback, and \var{data} is the data returned
255for this \var{type} of callback. The type of the data depends on the
256\var{type} of callback as follows:
257
Fred Drakeee601911998-04-11 20:53:03 +0000258\begin{tableii}{l|p{4in}}{code}{Type}{Value}
Fred Draked98329c1998-03-16 06:38:42 +0000259 \lineii{audio}{String which can be passed unmodified to
260\function{al.writesamps()}.}
261 \lineii{pnum}{Integer giving the program (track) number.}
262 \lineii{index}{Integer giving the index number.}
263 \lineii{ptime}{Tuple consisting of the program time in minutes,
264seconds, and frames.}
265 \lineii{atime}{Tuple consisting of the absolute time in minutes,
266seconds, and frames.}
267 \lineii{catalog}{String of 13 characters, giving the catalog number
268of the CD.}
269 \lineii{ident}{String of 12 characters, giving the ISRC
Fred Drake0d213d31998-04-11 16:40:46 +0000270identification number of the recording. The string consists of two
271characters country code, three characters owner code, two characters
272giving the year, and five characters giving a serial number.}
Fred Draked98329c1998-03-16 06:38:42 +0000273 \lineii{control}{Integer giving the control bits from the CD
274subcode data}
275\end{tableii}
Fred Drakefc576191998-04-04 07:15:02 +0000276\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000277
Fred Drakefc576191998-04-04 07:15:02 +0000278\begin{methoddesc}[CD parser]{deleteparser}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000279Deletes the parser and frees the memory it was using. The object
280should not be used after this call. This call is done automatically
281when the last reference to the object is removed.
Fred Drakefc576191998-04-04 07:15:02 +0000282\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000283
Fred Drakefc576191998-04-04 07:15:02 +0000284\begin{methoddesc}[CD parser]{parseframe}{frame}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000285Parses one or more frames of digital audio data from a CD such as
Fred Draked98329c1998-03-16 06:38:42 +0000286returned by \method{readda()}. It determines which subcodes are
287present in the data. If these subcodes have changed since the last
288frame, then \method{parseframe()} executes a callback of the
289appropriate type passing to it the subcode data found in the frame.
290Unlike the \C{} function, more than one frame of digital audio data
291can be passed to this method.
Fred Drakefc576191998-04-04 07:15:02 +0000292\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000293
Fred Drakefc576191998-04-04 07:15:02 +0000294\begin{methoddesc}[CD parser]{removecallback}{type}
Fred Draked98329c1998-03-16 06:38:42 +0000295Removes the callback for the given \var{type}.
Fred Drakefc576191998-04-04 07:15:02 +0000296\end{methoddesc}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000297
Fred Drakefc576191998-04-04 07:15:02 +0000298\begin{methoddesc}[CD parser]{resetparser}{}
Sjoerd Mullenderffd6de11995-03-28 11:56:52 +0000299Resets the fields of the parser used for tracking subcodes to an
Fred Draked98329c1998-03-16 06:38:42 +0000300initial state. \method{resetparser()} should be called after the disc
301has been changed.
Fred Drakefc576191998-04-04 07:15:02 +0000302\end{methoddesc}