39.3.cd — CD-ROM access on SGI systems¶
Deprecated since version 2.6:Thecd module has been removed in Python 3.
This module provides an interface to the Silicon Graphics CD library. It isavailable only on Silicon Graphics systems.
The way the library works is as follows. A program opens the CD-ROM device withopen() and creates a parser to parse the data from the CD withcreateparser(). The object returned byopen() can be used to readdata from the CD, but also to get status information for the CD-ROM device, andto get information about the CD, such as the table of contents. Data from theCD is passed to the parser, which parses the frames, and calls any callbackfunctions that have previously been added.
An audio CD is divided intotracks orprograms (the terms are usedinterchangeably). Tracks can be subdivided intoindices. An audio CDcontains atable of contents which gives the starts of the tracks on theCD. Index 0 is usually the pause before the start of a track. The start of thetrack as given by the table of contents is normally the start of index 1.
Positions on a CD can be represented in two ways. Either a frame number or atuple of three values, minutes, seconds and frames. Most functions use thelatter representation. Positions can be both relative to the beginning of theCD, and to the beginning of the track.
Modulecd defines the following functions and constants:
cd.createparser()¶Create and return an opaque parser object. The methods of the parser object aredescribed below.
cd.msftoframe(minutes,seconds,frames)¶Converts a
(minutes,seconds,frames)triple representing time in absolutetime code into the corresponding CD frame number.
cd.open([device[,mode]])¶Open the CD-ROM device. The return value is an opaque player object; methods ofthe player object are described below. The device is the name of the SCSIdevice file, e.g.
'/dev/scsi/sc0d4l0', orNone. If omitted orNone,the hardware inventory is consulted to locate a CD-ROM drive. Themode, ifnot omitted, should be the string'r'.
The module defines the following variables:
- exception
cd.error¶ Exception raised on various errors.
cd.DATASIZE¶The size of one frame’s worth of audio data. This is the size of the audio dataas passed to the callback of type
audio.
cd.BLOCKSIZE¶The size of one uninterpreted frame of audio data.
The following variables are states as returned bygetstatus():
cd.READY¶The drive is ready for operation loaded with an audio CD.
cd.NODISC¶The drive does not have a CD loaded.
cd.CDROM¶The drive is loaded with a CD-ROM. Subsequent play or read operations willreturn I/O errors.
cd.ERROR¶An error occurred while trying to read the disc or its table of contents.
cd.PLAYING¶The drive is in CD player mode playing an audio CD through its audio jacks.
cd.PAUSED¶The drive is in CD layer mode with play paused.
cd.STILL¶The equivalent of
PAUSEDon older (non 3301) model Toshiba CD-ROMdrives. Such drives have never been shipped by SGI.
cd.audio¶cd.pnum¶cd.index¶cd.ptime¶cd.atime¶cd.catalog¶cd.ident¶cd.control¶Integer constants describing the various types of parser callbacks that can beset by the
addcallback()method of CD parser objects (see below).
39.3.1.Player Objects¶
Player objects (returned byopen()) have the following methods:
CD player.allowremoval()Unlocks the eject button on the CD-ROM drive permitting the user to eject thecaddy if desired.
CD player.bestreadsize()Returns the best value to use for thenum_frames parameter of the
readda()method. Best is defined as the value that permits a continuousflow of data from the CD-ROM drive.
CD player.close()Frees the resources associated with the player object. After calling
close(), the methods of the object should no longer be used.
CD player.eject()Ejects the caddy from the CD-ROM drive.
CD player.getstatus()Returns information pertaining to the current state of the CD-ROM drive. Thereturned information is a tuple with the following values:state,track,rtime,atime,ttime,first,last,scsi_audio,cur_block.rtimeis the time relative to the start of the current track;atime is the timerelative to the beginning of the disc;ttime is the total time on the disc.For more information on the meaning of the values, see the man pageCDgetstatus(3dm). The value ofstate is one of the following:
ERROR,NODISC,READY,PLAYING,PAUSED,STILL, orCDROM.
CD player.gettrackinfo(track)Returns information about the specified track. The returned information is atuple consisting of two elements, the start time of the track and the durationof the track.
CD player.msftoblock(min, sec, frame)Converts a minutes, seconds, frames triple representing a time in absolute timecode into the corresponding logical block number for the given CD-ROM drive.You should use
msftoframe()rather thanmsftoblock()for comparingtimes. The logical block number differs from the frame number by an offsetrequired by certain CD-ROM drives.
CD player.play(start, play)Starts playback of an audio CD in the CD-ROM drive at the specified track. Theaudio output appears on the CD-ROM drive’s headphone and audio jacks (iffitted). Play stops at the end of the disc.start is the number of the trackat which to start playing the CD; ifplay is 0, the CD will be set to aninitial paused state. The method
togglepause()can then be used tocommence play.
CD player.playabs(minutes, seconds, frames, play)Like
play(), except that the start is given in minutes, seconds, andframes instead of a track number.
CD player.playtrack(start, play)Like
play(), except that playing stops at the end of the track.
CD player.playtrackabs(track, minutes, seconds, frames, play)Like
play(), except that playing begins at the specified absolute time andends at the end of the specified track.
CD player.preventremoval()Locks the eject button on the CD-ROM drive thus preventing the user fromarbitrarily ejecting the caddy.
CD player.readda(num_frames)Reads the specified number of frames from an audio CD mounted in the CD-ROMdrive. The return value is a string representing the audio frames. This stringcan be passed unaltered to the
parseframe()method of the parser object.
CD player.seek(minutes, seconds, frames)Sets the pointer that indicates the starting point of the next read of digitalaudio data from a CD-ROM. The pointer is set to an absolute time code locationspecified inminutes,seconds, andframes. The return value is thelogical block number to which the pointer has been set.
CD player.seekblock(block)Sets the pointer that indicates the starting point of the next read of digitalaudio data from a CD-ROM. The pointer is set to the specified logical blocknumber. The return value is the logical block number to which the pointer hasbeen set.
CD player.seektrack(track)Sets the pointer that indicates the starting point of the next read of digitalaudio data from a CD-ROM. The pointer is set to the specified track. Thereturn value is the logical block number to which the pointer has been set.
CD player.stop()Stops the current playing operation.
CD player.togglepause()Pauses the CD if it is playing, and makes it play if it is paused.
39.3.2.Parser Objects¶
Parser objects (returned bycreateparser()) have the following methods:
CD parser.addcallback(type, func, arg)Adds a callback for the parser. The parser has callbacks for eight differenttypes of data in the digital audio data stream. Constants for these types aredefined at the
cdmodule level (see above). The callback is called asfollows:func(arg,type,data), wherearg is the user supplied argument,type is the particular type of callback, anddata is the data returned forthistype of callback. The type of the data depends on thetype of callbackas follows:Type
Value
audioString which can be passed unmodified to
al.writesamps().pnumInteger giving the program (track) number.
indexInteger giving the index number.
ptimeTuple consisting of the program time inminutes, seconds, and frames.
atimeTuple consisting of the absolute time inminutes, seconds, and frames.
catalogString of 13 characters, giving the catalognumber of the CD.
identString of 12 characters, giving the ISRCidentification number of the recording.The string consists of two characterscountry code, three characters owner code,two characters giving the year, and fivecharacters giving a serial number.
controlInteger giving the control bits from the CDsubcode data
CD parser.deleteparser()Deletes the parser and frees the memory it was using. The object should not beused after this call. This call is done automatically when the last referenceto the object is removed.
CD parser.parseframe(frame)Parses one or more frames of digital audio data from a CD such as returned by
readda(). It determines which subcodes are present in the data. If thesesubcodes have changed since the last frame, thenparseframe()executes acallback of the appropriate type passing to it the subcode data found in theframe. Unlike the C function, more than one frame of digital audio data can bepassed to this method.
CD parser.removecallback(type)Removes the callback for the giventype.
CD parser.resetparser()Resets the fields of the parser used for tracking subcodes to an initial state.
resetparser()should be called after the disc has been changed.
