home *** CD-ROM | disk | FTP | other *** search
/ IRIS Development Option 6.2 / IRIS_Development_Option_6.2_814-0478-001.iso / dist / dmedia_dev.idb / usr / include / dmedia / cdaudio.h.z / cdaudio.h
C/C++ Source or Header  |  1996-03-14  |  11KB  |  448 lines

  1. #ifndef __CDAUDIO_H_
  2. #define __CDAUDIO_H_
  3.  
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7.  
  8. /*
  9.  * cdaudio.h
  10.  *
  11.  * Functions for playing audio CD's on a CD ROM drive
  12.  *
  13.  *
  14.  * Copyright 1991, Silicon Graphics, Inc.
  15.  * All Rights Reserved.
  16.  *
  17.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  18.  * the contents of this file may not be disclosed to third parties, copied or
  19.  * duplicated in any form, in whole or in part, without the prior written
  20.  * permission of Silicon Graphics, Inc.
  21.  *
  22.  * RESTRICTED RIGHTS LEGEND:
  23.  * Use, duplication or disclosure by the Government is subject to restrictions
  24.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  25.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  26.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  27.  * rights reserved under the Copyright Laws of the United States.
  28.  */
  29.  
  30. /*
  31.  * Possible states for the cd player.  These are for the state field
  32.  * of a CDSTATUS structure.
  33.  */
  34.  
  35. #define CD_ERROR    0
  36. #define CD_NODISC   1
  37. #define CD_READY    2
  38. #define CD_PLAYING  3
  39. #define CD_PAUSED   4
  40. #define CD_STILL    5
  41. #define CD_CDROM    6
  42.  
  43. /*
  44.  * Block size information for digital audio data
  45.  */
  46. #define CDDA_DATASIZE        2352
  47. #define CDDA_SUBCODESIZE    (sizeof(struct subcodeQ))
  48. #define CDDA_BLOCKSIZE        (sizeof(struct cdframe))
  49. #define CDDA_NUMSAMPLES        (CDDA_DATASIZE/2)
  50.  
  51. /*
  52.  * Handle for playing audio on a CD-ROM drive
  53.  */
  54. typedef struct cdplayer CDPLAYER;
  55.  
  56. /*
  57.  * Buffer to receive current status information
  58.  */
  59. typedef struct {
  60.     int     state;
  61.     int     track;
  62.     int     min;            /* relative to beginning of track */
  63.     int     sec;
  64.     int     frame;
  65.     int     abs_min;        /* relative to beginning of disc */
  66.     int     abs_sec;
  67.     int     abs_frame;
  68.     int     total_min;      /* total on disc */
  69.     int     total_sec;
  70.     int     total_frame;
  71.     int     first;          /* first legal track number */
  72.     int     last;           /* last legal track number */
  73.     int    scsi_audio;    /* true if drive can transfer audio via SCSI */
  74.     int    cur_block;    /* block no. for next audio data read */
  75.     int    polyfilla[3];    /* future expansion */
  76. } CDSTATUS;
  77.  
  78. /*
  79.  * Buffer to receive information about a particular track
  80.  */
  81. typedef struct {
  82.     int     start_min;
  83.     int     start_sec;
  84.     int     start_frame;
  85.     int     total_min;
  86.     int     total_sec;
  87.     int     total_frame;
  88. } CDTRACKINFO;
  89.  
  90. /*
  91.  * Buffer for getting/setting the volume
  92.  */
  93. typedef struct {
  94.     unsigned char    chan0;
  95.     unsigned char    chan1;
  96.     unsigned char    chan2;
  97.     unsigned char    chan3;
  98. } CDVOLUME;
  99.  
  100. /*************************************************************************
  101.  *
  102.  * Defines and structures for CD digital audio data
  103.  *
  104.  *************************************************************************/
  105.  
  106. /*
  107.  * Defines for control field
  108.  */
  109. #define CDQ_PREEMP_MASK        0xd
  110. #define CDQ_COPY_MASK        0xb
  111. #define    CDQ_DDATA_MASK        0xd
  112. #define CDQ_BROADCAST_MASK    0x8
  113. #define CDQ_PREEMPHASIS        0x1
  114. #define CDQ_COPY_PERMITTED    0x2        
  115. #define CDQ_DIGITAL_DATA    0x4
  116. #define CDQ_BROADCAST_USE    0x8
  117.  
  118. /*
  119.  * Defines for the type field
  120.  */
  121. #define CDQ_MODE1        0x1
  122. #define CDQ_MODE2        0x2
  123. #define CDQ_MODE3        0x3
  124.  
  125. /*
  126.  * Useful sub-structures
  127.  */
  128. struct cdpackedbcd { unchar dhi:4, dlo:4; };
  129.  
  130. struct cdtimecode {
  131.     unchar mhi:4, mlo:4;
  132.     unchar shi:4, slo:4;
  133.     unchar fhi:4, flo:4;
  134. };
  135.  
  136. struct cdident {
  137.     unchar country[2];
  138.     unchar owner[3];
  139.     unchar year[2];
  140.     unchar serial[5];
  141. };
  142.  
  143. /*
  144.  * Structure of CD subcode Q
  145.  */
  146. typedef struct subcodeQ {
  147.     unchar control;
  148.     unchar type;
  149.     union {
  150.         struct {
  151.         struct cdpackedbcd track;
  152.         struct cdpackedbcd index;    /* aka point during track 0 */
  153.         struct cdtimecode ptime;
  154.             struct cdtimecode atime;
  155.             unchar fill[6];
  156.         } mode1;
  157.         struct {
  158.             unchar catalognumber[13];
  159.             struct cdpackedbcd aframe;
  160.         } mode2;
  161.         struct {
  162.         struct cdident ident;
  163.             struct cdpackedbcd aframe;
  164.             unchar fill;
  165.         } mode3;
  166.     } data;
  167. } CDSUBCODEQ;
  168.  
  169. /*
  170.  * Structure of the digital audio (DA) data as delivered by the drive
  171.  * In CD parlance this is a one subcode frame
  172.  */
  173. typedef struct cdframe {
  174.     char audio[CDDA_DATASIZE];
  175.     struct subcodeQ subcode;
  176. } CDFRAME;
  177.  
  178. /********************************************************************/
  179.  
  180. /*
  181.  * Compatibility with old names
  182.  */
  183. #define cd_open         CDopen
  184. #define cd_play         CDplay
  185. #define cd_play_track        CDplaytrack
  186. #define cd_play_track_abs    CDplaytrackabs
  187. #define cd_play_abs        CDplayabs
  188. #define cd_readda        CDreadda
  189. #define cd_seek            CDseek
  190. #define cd_seek_track        CDseektrack
  191. #define cd_stop            CDstop
  192. #define cd_eject        CDeject
  193. #define cd_close        CDclose
  194. #define cd_get_status        CDgetstatus
  195. #define cd_toggle_pause        CDtogglepause
  196. #define cd_get_track_info    CDgettrackinfo
  197. #define cd_get_volume        CDgetvolume
  198. #define cd_set_volume        CDsetvolume
  199.  
  200. /********************************************************************
  201.  *
  202.  * CD-ROM Drive Functions.
  203.  *
  204.  * The various *play* functions operate the CD-ROM drive as a player
  205.  * delivering audio from the audio jacks on the drive.  They do not
  206.  * transfer any digital audio data into the host computer.  
  207.  *
  208.  * CDstop and CDtogglepause are only for use when operating the drive
  209.  * as a player.
  210.  *
  211.  ********************************************************************/
  212.  
  213. /*
  214.  * Open a devscsi device corresponding to a CD-ROM drive for audio.
  215.  * Specifying NULL for devscsi causes the hardware inventory
  216.  * to be consulted for a CD-ROM drive.
  217.  *
  218.  * direction specifies way the device is to be used "r", "w", or "rw".
  219.  * It is for future support of writable CD's and is currently ignored.
  220.  */
  221. CDPLAYER * CDopen( char const *devscsi, char const *direction );
  222.  
  223. /*
  224.  * Play the disc, starting at start and continuing through the rest
  225.  * of the tracks.  If play is 0, start in pause mode.
  226.  */
  227. int CDplay( CDPLAYER *cd, int start, int play );
  228.  
  229. /*
  230.  * Play one track; play ends when track is over
  231.  */
  232. int CDplaytrack( CDPLAYER *cd, int track, int play );
  233.  
  234. /*
  235.  * Play one track, starting at min:sec:frame within that track
  236.  */
  237. int CDplaytrackabs( CDPLAYER *cdplayer, int track,
  238.  int min, int sec, int frame, int play );
  239.  
  240. /*
  241.  * Play starting at min:sec:frame, continuing throught the rest of
  242.  * the disc
  243.  */
  244. int CDplayabs( CDPLAYER *cd, int min, int sec, int frame, int play );
  245.  
  246. /*
  247.  * Read digital audio data
  248.  */
  249. int CDreadda( CDPLAYER *cd, CDFRAME *buf, int num_frames );
  250.  
  251. /*
  252.  * Return the best size for the num_frames argument of CDreadda.
  253.  * This size will maintain continous data flow from the CD.
  254.  */
  255. int CDbestreadsize( CDPLAYER *cd );
  256.  
  257. /*
  258.  * Position drive at minute, second, frame for reading digital audio
  259.  */
  260. unsigned long CDseek( CDPLAYER *cd, int min, int sec, int frame );
  261.  
  262. /*
  263.  * Position drive at given logical block number.
  264.  */
  265. unsigned long CDseekblock( CDPLAYER *cd, unsigned long block);
  266.  
  267. /*
  268.  * Position drive at start of track t.
  269.  */
  270. int CDseektrack( CDPLAYER *cd, int t );
  271.  
  272. /*
  273.  * Stop play (or pause)
  274.  */
  275. int CDstop( CDPLAYER *cd );
  276.  
  277. /*
  278.  * Eject the caddy
  279.  */
  280. int CDeject( CDPLAYER *cd );
  281.  
  282. /*
  283.  * Enable the eject button
  284.  */
  285. void CDallowremoval( CDPLAYER *cd );
  286.  
  287. /*
  288.  * Disable the eject button
  289.  */
  290. void CDpreventremoval( CDPLAYER *cd );
  291.  
  292. /*
  293.  * close the devscsi device
  294.  */
  295. int CDclose( CDPLAYER *cd );
  296.  
  297. /*
  298.  * Get current status
  299.  */
  300. int CDgetstatus( CDPLAYER *cd, CDSTATUS *status );
  301.  
  302. /*
  303.  * if playing, pause it; if paused, play it.  Otherwise do nothing
  304.  */
  305. int CDtogglepause( CDPLAYER *cd );
  306.  
  307. /*
  308.  * Get information about a track
  309.  */
  310. int CDgettrackinfo( CDPLAYER *cd, int track, CDTRACKINFO *info );
  311.  
  312. /*
  313.  * Set/Get volume
  314.  */
  315. int CDsetvolume( CDPLAYER *cd, CDVOLUME *vol );
  316. int CDgetvolume( CDPLAYER *cd, CDVOLUME *vol );
  317.  
  318. /*
  319.  * Convert an ascii string to timecode
  320.  * return 0 if timecode invalid
  321.  */
  322. int CDatotime(struct cdtimecode *tc, const char *loc);
  323.  
  324. /*
  325.  * Convert an ascii string to msf
  326.  * return 0 if timecode invalid
  327.  */
  328. int CDatomsf(const char *loc, int *m, int *s, int *f);
  329.  
  330. /*
  331.  * Convert a frame number to struct timecode
  332.  */
  333.  
  334. void CDframetotc(unsigned long frame, struct cdtimecode *tc);
  335.  
  336. /*
  337.  * Convert a frame number to mins/secs/frames
  338.  */
  339.  
  340. void CDframetomsf(unsigned long frame, int *m, int *s, int *f);
  341.  
  342. /*
  343.  * Convert a struct time code to a displayable ASCII string
  344.  */
  345. void CDtimetoa( char *s, struct cdtimecode *tp );
  346.  
  347. /*
  348.  * Convert an array of 6-bit values to an ASCII string
  349.  * This function returns the number of characters converted
  350.  */
  351. int CDsbtoa( char *s, const unchar *sixbit, int count );
  352.  
  353. /*
  354.  * Convert (minutes, seconds, frame) value to logical block number
  355.  * on given device.  This function is device specific.  You should
  356.  * use CDmsftoframe instead.
  357.  */
  358. unsigned long CDmsftoblock( CDPLAYER *cd, int m, int s, int f );
  359.  
  360. /*
  361.  * Convert a logical block number to a (minutes, seconds, frame) value.
  362.  */
  363. void CDblocktomsf( CDPLAYER *cd, unsigned long frame, int *m, int *s,  int*f );
  364.  
  365. /*
  366.  * Convert (minutes, seconds, frame) value to CD frame number.
  367.  * This is useful when you need to compare two values.
  368.  */
  369. unsigned long CDmsftoframe( int m, int s, int f );
  370.  
  371. /*
  372.  * Convert struct timecode value to CD frame number.
  373.  * This is useful when you need to compare two timecode values.
  374.  */
  375. unsigned long CDtctoframe( struct cdtimecode* tc );
  376.  
  377.  
  378. /********************************************************************
  379.  *
  380.  * Digital Audio Data Parser Functions
  381.  *
  382.  * These functions aid in parsing the digital audio data that is
  383.  * transferred by the CD-ROM drive.
  384.  *
  385.  ********************************************************************/
  386.  
  387. /*
  388.  * Identifiers for the different types of callbacks from the
  389.  * parser.
  390.  */
  391. typedef enum cddatatypes {
  392.     cd_audio, cd_pnum, cd_index, cd_ptime, cd_atime, cd_catalog, cd_ident,
  393.     cd_control
  394. } CDDATATYPES;
  395.  
  396. /*
  397.  * Structure to unpack program and index numbers into to pass them to
  398.  * callback
  399.  */
  400. typedef struct cdprognum {
  401.     int value;            /* Program number converted to integer */
  402.     struct cdpackedbcd bcd;    /* Program number in BCD digits */
  403. } CDPROGNUM;
  404.  
  405. /*
  406.  * Handle for a cdparser structure
  407.  */
  408. typedef struct cdparser CDPARSER;
  409.  
  410. typedef void (*CDCALLBACKFUNC)(void*, enum cddatatypes, void*);
  411.  
  412. /*
  413.  * Make a new parser
  414.  */
  415. CDPARSER *CDcreateparser();
  416.  
  417. /*
  418.  * Delete a parser and free the memory
  419.  */
  420. void CDdeleteparser(CDPARSER *);
  421.  
  422. /*
  423.  * Reset a parser.  This should be called after a disc has been ejected and
  424.  * a new one loaded.
  425.  */
  426. void CDresetparser(CDPARSER *);
  427.  
  428. /*
  429.  * Set up or remove a callback from the parser for one of the data items from
  430.  * the enumerated list of cddatatypes.
  431.  */
  432. #define CDsetcallback CDaddcallback    /* remove 2 releases after 4.1 */
  433. void CDaddcallback(CDPARSER *cdp, CDDATATYPES type,
  434.                    CDCALLBACKFUNC func, void *arg);
  435. void CDremovecallback(CDPARSER *cdp, CDDATATYPES type);
  436.  
  437. /*
  438.  * Parse a frame of digital audio data.  CDparseframe calls each established
  439.  * callback passing it the data item it is expecting.
  440.  */
  441. void CDparseframe(CDPARSER *cdp, CDFRAME *cdfp);
  442.  
  443. #ifdef __cplusplus
  444. }
  445. #endif
  446.  
  447. #endif /* !__CDAUDIO_H_ */
  448.