1 \section{Built-in Module
\module{cd
}}
5 This module provides an interface to the Silicon Graphics CD library.
6 It is available only on Silicon Graphics systems.
8 The way the library works is as follows. A program opens the CD-ROM
9 device with
\function{open()
} and creates a parser to parse the data
10 from the CD with
\function{createparser()
}. The object returned by
11 \function{open()
} can be used to read data from the CD, but also to get
12 status information for the CD-ROM device, and to get information about
13 the CD, such as the table of contents. Data from the CD is passed to
14 the parser, which parses the frames, and calls any callback
15 functions that have previously been added.
17 An audio CD is divided into
\dfn{tracks
} or
\dfn{programs
} (the terms
18 are used interchangeably). Tracks can be subdivided into
19 \dfn{indices
}. An audio CD contains a
\dfn{table of contents
} which
20 gives the starts of the tracks on the CD. Index
0 is usually the
21 pause before the start of a track. The start of the track as given by
22 the table of contents is normally the start of index
1.
24 Positions on a CD can be represented in two ways. Either a frame
25 number or a tuple of three values, minutes, seconds and frames. Most
26 functions use the latter representation. Positions can be both
27 relative to the beginning of the CD, and to the beginning of the
30 Module
\module{cd
} defines the following functions and constants:
33 \begin{funcdesc
}{createparser
}{}
34 Create and return an opaque parser object. The methods of the parser
35 object are described below.
38 \begin{funcdesc
}{msftoframe
}{minutes, seconds, frames
}
39 Converts a
\code{(
\var{minutes
},
\var{seconds
},
\var{frames
})
} triple
40 representing time in absolute time code into the corresponding CD
44 \begin{funcdesc
}{open
}{\optional{device
\optional{, mode
}}}
45 Open the CD-ROM device. The return value is an opaque player object;
46 methods of the player object are described below. The device is the
47 name of the SCSI device file, e.g.
\code{'/dev/scsi/sc0d4l0'
}, or
48 \code{None
}. If omitted or
\code{None
}, the hardware inventory is
49 consulted to locate a CD-ROM drive. The
\var{mode
}, if not omited,
50 should be the string
\code{'r'
}.
53 The module defines the following variables:
55 \begin{excdesc
}{error
}
56 Exception raised on various errors.
59 \begin{datadesc
}{DATASIZE
}
60 The size of one frame's worth of audio data. This is the size of the
61 audio data as passed to the callback of type
\code{audio
}.
64 \begin{datadesc
}{BLOCKSIZE
}
65 The size of one uninterpreted frame of audio data.
68 The following variables are states as returned by
69 \function{getstatus()
}:
71 \begin{datadesc
}{READY
}
72 The drive is ready for operation loaded with an audio CD.
75 \begin{datadesc
}{NODISC
}
76 The drive does not have a CD loaded.
79 \begin{datadesc
}{CDROM
}
80 The drive is loaded with a CD-ROM. Subsequent play or read operations
81 will return I/O errors.
84 \begin{datadesc
}{ERROR
}
85 An error aoocurred while trying to read the disc or its table of
89 \begin{datadesc
}{PLAYING
}
90 The drive is in CD player mode playing an audio CD through its audio
94 \begin{datadesc
}{PAUSED
}
95 The drive is in CD layer mode with play paused.
98 \begin{datadesc
}{STILL
}
99 The equivalent of
\constant{PAUSED
} on older (non
3301) model Toshiba
100 CD-ROM drives. Such drives have never been shipped by SGI.
103 \begin{datadesc
}{audio
}
111 Integer constants describing the various types of parser callbacks
112 that can be set by the
\method{addcallback()
} method of CD parser
117 \subsection{Player Objects
}
118 \label{player-objects
}
120 Player objects (returned by
\function{open()
}) have the following
123 \begin{methoddesc
}[CD player
]{allowremoval
}{}
124 Unlocks the eject button on the CD-ROM drive permitting the user to
125 eject the caddy if desired.
128 \begin{methoddesc
}[CD player
]{bestreadsize
}{}
129 Returns the best value to use for the
\var{num_frames
} parameter of
130 the
\method{readda()
} method. Best is defined as the value that
131 permits a continuous flow of data from the CD-ROM drive.
134 \begin{methoddesc
}[CD player
]{close
}{}
135 Frees the resources associated with the player object. After calling
136 \method{close()
}, the methods of the object should no longer be used.
139 \begin{methoddesc
}[CD player
]{eject
}{}
140 Ejects the caddy from the CD-ROM drive.
143 \begin{methoddesc
}[CD player
]{getstatus
}{}
144 Returns information pertaining to the current state of the CD-ROM
145 drive. The returned information is a tuple with the following values:
146 \var{state
},
\var{track
},
\var{rtime
},
\var{atime
},
\var{ttime
},
147 \var{first
},
\var{last
},
\var{scsi_audio
},
\var{cur_block
}.
148 \var{rtime
} is the time relative to the start of the current track;
149 \var{atime
} is the time relative to the beginning of the disc;
150 \var{ttime
} is the total time on the disc. For more information on
151 the meaning of the values, see the man page
\manpage{CDgetstatus
}{3dm
}.
152 The value of
\var{state
} is one of the following:
\constant{ERROR
},
153 \constant{NODISC
},
\constant{READY
},
\constant{PLAYING
},
154 \constant{PAUSED
},
\constant{STILL
}, or
\constant{CDROM
}.
157 \begin{methoddesc
}[CD player
]{gettrackinfo
}{track
}
158 Returns information about the specified track. The returned
159 information is a tuple consisting of two elements, the start time of
160 the track and the duration of the track.
163 \begin{methoddesc
}[CD player
]{msftoblock
}{min, sec, frame
}
164 Converts a minutes, seconds, frames triple representing a time in
165 absolute time code into the corresponding logical block number for the
166 given CD-ROM drive. You should use
\function{msftoframe()
} rather than
167 \method{msftoblock()
} for comparing times. The logical block number
168 differs from the frame number by an offset required by certain CD-ROM
172 \begin{methoddesc
}[CD player
]{play
}{start, play
}
173 Starts playback of an audio CD in the CD-ROM drive at the specified
174 track. The audio output appears on the CD-ROM drive's headphone and
175 audio jacks (if fitted). Play stops at the end of the disc.
176 \var{start
} is the number of the track at which to start playing the
177 CD; if
\var{play
} is
0, the CD will be set to an initial paused
178 state. The method
\method{togglepause()
} can then be used to commence
182 \begin{methoddesc
}[CD player
]{playabs
}{minutes, seconds, frames, play
}
183 Like
\method{play()
}, except that the start is given in minutes,
184 seconds, and frames instead of a track number.
187 \begin{methoddesc
}[CD player
]{playtrack
}{start, play
}
188 Like
\method{play()
}, except that playing stops at the end of the
192 \begin{methoddesc
}[CD player
]{playtrackabs
}{track, minutes, seconds, frames, play
}
193 Like
\method{play()
}, except that playing begins at the spcified
194 absolute time and ends at the end of the specified track.
197 \begin{methoddesc
}[CD player
]{preventremoval
}{}
198 Locks the eject button on the CD-ROM drive thus preventing the user
199 from arbitrarily ejecting the caddy.
202 \begin{methoddesc
}[CD player
]{readda
}{num_frames
}
203 Reads the specified number of frames from an audio CD mounted in the
204 CD-ROM drive. The return value is a string representing the audio
205 frames. This string can be passed unaltered to the
206 \method{parseframe()
} method of the parser object.
209 \begin{methoddesc
}[CD player
]{seek
}{minutes, seconds, frames
}
210 Sets the pointer that indicates the starting point of the next read of
211 digital audio data from a CD-ROM. The pointer is set to an absolute
212 time code location specified in
\var{minutes
},
\var{seconds
}, and
213 \var{frames
}. The return value is the logical block number to which
214 the pointer has been set.
217 \begin{methoddesc
}[CD player
]{seekblock
}{block
}
218 Sets the pointer that indicates the starting point of the next read of
219 digital audio data from a CD-ROM. The pointer is set to the specified
220 logical block number. The return value is the logical block number to
221 which the pointer has been set.
224 \begin{methoddesc
}[CD player
]{seektrack
}{track
}
225 Sets the pointer that indicates the starting point of the next read of
226 digital audio data from a CD-ROM. The pointer is set to the specified
227 track. The return value is the logical block number to which the
228 pointer has been set.
231 \begin{methoddesc
}[CD player
]{stop
}{}
232 Stops the current playing operation.
235 \begin{methoddesc
}[CD player
]{togglepause
}{}
236 Pauses the CD if it is playing, and makes it play if it is paused.
240 \subsection{Parser Objects
}
241 \label{cd-parser-objects
}
243 Parser objects (returned by
\function{createparser()
}) have the
246 \begin{methoddesc
}[CD parser
]{addcallback
}{type, func, arg
}
247 Adds a callback for the parser. The parser has callbacks for eight
248 different types of data in the digital audio data stream. Constants
249 for these types are defined at the
\module{cd
} module level (see above).
250 The callback is called as follows:
\code{\var{func
}(
\var{arg
}, type,
251 data)
}, where
\var{arg
} is the user supplied argument,
\var{type
} is
252 the particular type of callback, and
\var{data
} is the data returned
253 for this
\var{type
} of callback. The type of the data depends on the
254 \var{type
} of callback as follows:
256 \begin{tableii
}{l|p
{4in
}}{code
}{Type
}{Value
}
257 \lineii{audio
}{String which can be passed unmodified to
258 \function{al.writesamps()
}.
}
259 \lineii{pnum
}{Integer giving the program (track) number.
}
260 \lineii{index
}{Integer giving the index number.
}
261 \lineii{ptime
}{Tuple consisting of the program time in minutes,
262 seconds, and frames.
}
263 \lineii{atime
}{Tuple consisting of the absolute time in minutes,
264 seconds, and frames.
}
265 \lineii{catalog
}{String of
13 characters, giving the catalog number
267 \lineii{ident
}{String of
12 characters, giving the ISRC
268 identification number of the recording. The string consists of two
269 characters country code, three characters owner code, two characters
270 giving the year, and five characters giving a serial number.
}
271 \lineii{control
}{Integer giving the control bits from the CD
276 \begin{methoddesc
}[CD parser
]{deleteparser
}{}
277 Deletes the parser and frees the memory it was using. The object
278 should not be used after this call. This call is done automatically
279 when the last reference to the object is removed.
282 \begin{methoddesc
}[CD parser
]{parseframe
}{frame
}
283 Parses one or more frames of digital audio data from a CD such as
284 returned by
\method{readda()
}. It determines which subcodes are
285 present in the data. If these subcodes have changed since the last
286 frame, then
\method{parseframe()
} executes a callback of the
287 appropriate type passing to it the subcode data found in the frame.
288 Unlike the
\C{} function, more than one frame of digital audio data
289 can be passed to this method.
292 \begin{methoddesc
}[CD parser
]{removecallback
}{type
}
293 Removes the callback for the given
\var{type
}.
296 \begin{methoddesc
}[CD parser
]{resetparser
}{}
297 Resets the fields of the parser used for tracking subcodes to an
298 initial state.
\method{resetparser()
} should be called after the disc