home *** CD-ROM | disk | FTP | other *** search
/ ftp.cdrom.com/pub/cdrom/ / cdrom.tar / cdrom / sun_toshiba / pr.c < prev    next >
C/C++ Source or Header  |  1993-07-05  |  2KB  |  114 lines

  1. /* pr.c  --  Play music from Raw audio sectors.
  2.  *
  3.  * This program plays an audio CD on a SparcStation with a Toshiba XM3401
  4.  * CDROM drive. I'm using SunOS 4.1.3.
  5.  * You FIRST should have set the 3401 in raw CD-DA mode (e.g. via set_raw)!
  6.  * Warning: It's a dirty (test)program.
  7.  *
  8.  * Usage: pr [<Start Frame Number> [<Number Of Frames>]]
  9.  *
  10.  * Author: Adrie Koolen (adrie@ica.philips.nl)
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <sys/types.h>
  15. #include <scsi/scsi_types.h>
  16. #include <scsi/impl/uscsi.h>
  17.  
  18. #include <sun/audioio.h>
  19. #include "/usr/demo/SOUND/multimedia/ulaw2linear.h"
  20.  
  21. #define AUDIO_DEV    "/dev/audio"
  22.  
  23. /* Define the cluster length. Don't make it too large, or SunOS will fail! */
  24. #define NR_SECS    250
  25.  
  26. u_char scsibuf[] = {
  27.     0x28,    /* READ */
  28.     0x08,    /* LUN */
  29.     0x00,
  30.     0x00,
  31.     0x00,
  32.     0x00,
  33.     0x00,
  34.     NR_SECS / 256,    /* nr of blocks */
  35.     NR_SECS % 256,    /* nr of blocks */
  36.     0x00
  37. };
  38.  
  39. u_char databuf[2352 * NR_SECS];
  40. u_char bigbuf[NR_SECS * 107];
  41.  
  42. struct uscsi_cmd usc;
  43.  
  44. char *program;
  45. int afd;        /* Audio device file descriptor. */
  46.  
  47.  
  48. main(argc, argv)
  49. int argc;
  50. char *argv[];
  51. {
  52.     int fd;
  53.     int len;
  54.     int i, p;
  55.     int bnr;
  56.     int w;
  57.     int e;
  58.     int cnt;
  59.  
  60.     program = argv[0];
  61.  
  62.     bnr = (argc > 1) ? atoi(argv[1]) : 0;
  63.     cnt = (argc > 2) ? atoi(argv[2]) / NR_SECS : 5000;
  64.  
  65.     if ((fd = open("/dev/rsr0", 0)) < 0) 
  66.         pfatal("open");
  67.  
  68.     afd = open(AUDIO_DEV, O_RDWR);
  69.     if (afd < 0)
  70.       { fprintf(stderr, "%s: can't open /dev/audio.\n", program);
  71.         exit(1);
  72.       }
  73.  
  74. back:
  75.     usc.uscsi_cdb = (caddr_t) scsibuf;
  76.     usc.uscsi_cdblen = sizeof(scsibuf);
  77.     usc.uscsi_bufaddr = (caddr_t) databuf;
  78.     usc.uscsi_buflen = sizeof(databuf);
  79.     usc.uscsi_status = 0;
  80.     usc.uscsi_flags = (USCSI_DIAGNOSE | USCSI_ISOLATE | USCSI_READ);
  81.  
  82.     scsibuf[3] = (bnr >> 16) & 0xFF;
  83.     scsibuf[4] = (bnr >> 8) & 0xFF;
  84.     scsibuf[5] = bnr & 0xFF;
  85.  
  86.     /* printf("bnr = %d.\n", bnr); */
  87.  
  88.     if (ioctl(fd, USCSICMD, usc) < 0)
  89.         pfatal("ioctl");
  90.  
  91.     /* Convert the samples. Use only the left channel. */
  92.     p = e = 0;
  93.     for (i = 0; i < sizeof databuf; )
  94.       { bigbuf[p++] = audio_s2u((short)(databuf[i] + 256 * databuf[i+1]));
  95.         e += 44100;
  96.         i += (e / 8000) * 4;
  97.         e %= 8000;
  98.       }
  99.  
  100.     w = write(afd, bigbuf, p);
  101.  
  102.     bnr += NR_SECS;
  103.     if (cnt--) goto back;
  104. }
  105.  
  106. pfatal(s)
  107. char *s;
  108. {
  109.     fprintf(stderr, "%s: ", program);
  110.     perror(s);
  111.     fprintf(stderr, "\n");
  112.     exit(1);
  113. }
  114.