home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / msdos / sndbords / proaudio / pas_sdk1 / pas-sdk1.arj / PAS / CDROMAPP / CDPLAY.C < prev    next >
C/C++ Source or Header  |  1992-09-23  |  3KB  |  143 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4.  
  5. #define OKAY 0
  6.  
  7. #include "cdmaster.h"
  8.  
  9. char *syntax=
  10.     "Syntax: cdplay [drive# [starttrack# [endtrack#]]].\n"
  11.     "\tdrive#\tnumber of CDROM drive;  defaults to the first drive#\n"
  12.     "\t\tuse '.' to specify the first drive# when specifying track#'s.\n"
  13.     "\tstarttrack#\tstarting track number to play.\n"
  14.     "\tendtrack#\tending track number to play.\n"
  15.     "\t\tuse -1 to play to end of disc, -2 to play to end of track.\n";
  16. char *nodrives= "No CDROM drives attached.\n";
  17. char *nomscdex= "MSCDEX is not installed.\n";
  18.  
  19. main(int argc, char **argv)
  20. {
  21.     int bgntrack= 1;
  22.     int endtrack= 1;
  23.     int numcdroms= 0;
  24.     int ourdrive= 0;
  25.     struct cdtable *cdt;
  26.  
  27.     if (!ismscdex())
  28.         {
  29.         fprintf(stderr, nomscdex);
  30.         return(1);
  31.         }
  32.  
  33.     if (!(numcdroms= getnumcdroms()))
  34.         {
  35.         fprintf(stderr, nodrives);
  36.         return(2);
  37.         }
  38.  
  39.     switch (argc)
  40.         {
  41.         case 4:
  42.             endtrack= atoi(argv[3]);
  43.         case 3:
  44.             bgntrack= atoi(argv[2]);
  45.         case 2:
  46.             if (argv[1][0] != '.')
  47.                 {
  48.                 if (!(ourdrive= atoi(argv[1])))
  49.                     {
  50.                     fprintf(stderr, syntax);
  51.                     return(3);
  52.                     }
  53.                 break;
  54.                 }
  55.  
  56.         case 1:
  57.             if (!(ourdrive= getfirstcdrom()))
  58.                 {
  59.                 fprintf(stderr, nodrives);
  60.                 return(4);
  61.                 }
  62.             break;
  63.  
  64.         default:
  65.             fprintf(stderr, syntax);
  66.             return(5);
  67.         }
  68.  
  69.     if (endtrack == -1)
  70.         endtrack= 99;
  71.     else
  72.     if (endtrack == -2)
  73.         endtrack= bgntrack;
  74.     else
  75.     if (endtrack < bgntrack)
  76.         endtrack= bgntrack;
  77.  
  78.     /* Programming Notes:
  79.     *    Call "createaudiotoc()" to get a quick structure allocated.
  80.     *
  81.     *    Get the trackinfo for the desired track.  Convert the
  82.     *    frame/min/sec/unknown bytes in trackinfo (the starting address)
  83.     *    to a long by getting the address of the frame member and calling
  84.     *    "redtolong()" using a pointer, but subtract 2 seconds from this
  85.     *    value (150 frames);  it is not known why, but if you use the
  86.     *    "starting address" as returned by the driver you actually address
  87.     *    data 2 seconds into the disc (this is required here because
  88.     *    "cdtrackinfo()" is a low level call (cdrom.c) and returns exactly
  89.     *    what the driver provides, whereas "gettrackframes()" (cdmaster.c)
  90.     *    does the adjustment for us.
  91.     *
  92.     *    Then, accumulate the count of frames to play for each track in the
  93.     *    range specified on the command line.
  94.     *
  95.     *    Finally, "cdplay()".
  96.     */
  97.  
  98.     if (cdt= createaudiotoc(ourdrive))
  99.         {
  100.         int status= 0;
  101.         long sframe;
  102.         long tframes= 0;
  103.         int track= bgntrack;
  104.         struct trackinfo ti;
  105.  
  106.         if (status= cdtrackinfo(ourdrive, bgntrack, &ti) >= 0)
  107.             {
  108.             long *redaddress= (long *) &ti.frame;
  109.             long sframe= redtolong((*redaddress)); //- (75* 2);
  110.  
  111.             do
  112.                 {
  113.                 long f= gettrackframes(ourdrive, track);
  114.  
  115.                 if (f == -1)
  116.                     status= -1;
  117.                 else
  118.                 if (!f)
  119.                     if (endtrack != 99)
  120.                         status= -1;
  121.                     else
  122.                         break;
  123.                 if (status < 0)
  124.                     break;
  125.                 tframes+= f;
  126.                 }
  127.             while (++track <= endtrack);
  128.  
  129.             printf("play drive: %2d - From: %2d - Upto: %2d ", ourdrive, bgntrack, track- 1);
  130.  
  131.             if (status >= 0)
  132.                 status= cdplay(ourdrive, sframe, tframes);
  133.             }
  134.         printf("= %X.\n", status);
  135.         destroyaudiotoc(ourdrive);
  136.         }
  137.     else
  138.         printf("failed, no initialization.\n");
  139.  
  140.     return(OKAY);
  141. }
  142.  
  143.