home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dspgroup / sound.arc / PLAY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-23  |  1.1 KB  |  58 lines

  1. /* Play an audio file through the D/A converter on the Delanco Spry board */
  2.  
  3. #include <stdio.h>
  4. #include <stat.h>
  5. #define    SEG    0xd000
  6. #define    IOBASE    0x300
  7.  
  8. main(argc,argv)
  9. int argc;
  10. char *argv[];
  11. {
  12.     huge char *offset,*buf,*lmalloc();
  13.     int fd;
  14.     struct stat statbuf;
  15.     long size;
  16.     int c,i;
  17.     int count = 1;
  18.     extern char *optarg;
  19.     extern int optind;
  20.     char *name;
  21.  
  22.     while((c = getopt(argc,argv,"n:")) != EOF){
  23.         switch(c){
  24.         case 'n':
  25.             count = atoi(optarg);
  26.             break;
  27.         }
  28.     }
  29.     while(optind < argc){
  30.         name = argv[optind++];
  31.  
  32.         if(stat(name,&statbuf) == -1){
  33.             printf("Can't stat %s\n",name);
  34.             continue;
  35.         }
  36.         size = statbuf.st_size;
  37.         buf = lmalloc(size);
  38.         if(buf == NULL){
  39.             printf("Can't alloc buffer of size %lu\n",size);
  40.             continue;
  41.         }
  42.         if((fd = open(name,0)) == -1){
  43.             printf("Can't read %s\n",name);
  44.             continue;
  45.         }
  46.         offset = buf;
  47.         while(read(fd,offset,16384) > 0){
  48.             offset += 16384;
  49.         }
  50.         close(fd);
  51.         for(i=0;i<count;i++)
  52.             play8lin(IOBASE,buf,size);
  53.         /* Return DAC to zero volts */
  54.         outportw(IOBASE+0,2048);
  55.         lfree(buf);
  56.     }
  57. }
  58.