home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / soundx / dactest.c next >
Encoding:
C/C++ Source or Header  |  1996-11-20  |  2.1 KB  |  98 lines

  1.  
  2. /* Copyright 1993 by Peter Sprenger   Pete@amber.dinoco.de
  3.  *                   5014 Kerpen 3
  4.  *                   Germany
  5.  *
  6.  * Permission to use, copy, modify, and distribute this
  7.  * software and its documentation for any purpose and without
  8.  * fee is hereby granted, provided that the above copyright
  9.  * notice appear in all copies.  The author Peter Sprenger
  10.  * makes no representations about the suitability of this
  11.  * software for any purpose.  It is provided "as is" without
  12.  * express or implied warranty.
  13.  */
  14.  
  15.  
  16. #include <stddef.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <dos.h>
  20. #include <io.h>
  21. #include <fcntl.h>
  22. #include <alloc.h>
  23. #include <sys\stat.h>
  24. #include "mydef.h"
  25. #include "sound.h"
  26. #include "timerx.h"
  27. #include "dmalib.h"
  28.  
  29. extern volatile BYTE dma_sb_busy;
  30.  
  31.  
  32. void main(int argc,char *argv[])
  33. {
  34.     int file;
  35.     WORD ret,rate;
  36.     struct stat mystat;
  37.     long length;
  38.     char huge *base,huge *base2;
  39.     BYTE left,right;
  40.  
  41.  
  42.     if(argc==2 || argc==3)
  43.     {
  44.         if(argc==2) rate=16000;
  45.         else
  46.         {
  47.             rate=atoi(argv[2]);
  48.             if(!rate) return;
  49.         }
  50.         stat(argv[1],&mystat);
  51.         length=mystat.st_size;
  52.         printf("size:%lu\n",length);
  53.         base=farmalloc(length);
  54.         if(!base)
  55.         {
  56.             printf("Not enough memory\n");
  57.             return;
  58.         }
  59.         file=open(argv[1],O_RDONLY|O_BINARY);
  60.         if(file== -1)
  61.         {
  62.             printf("Cannot open file\n");
  63.             if(base) farfree(base);
  64.             return;
  65.         }
  66.         file=open(argv[1],O_RDONLY|O_BINARY);
  67.         base2=base;
  68.         do
  69.         {
  70.             ret=read(file,base2,32700);  /* do not use this call in small model! */
  71.             base2+=ret;
  72.         } while(ret==32700);
  73.         close(file);
  74.  
  75.         if(SB_Setup())
  76.         {
  77.             SB_SetVect(sample);
  78.             SetRate(rate);
  79.             Play((char far *)base,bit8,length);
  80.             msdelay(1000);
  81.             Play((char far *)base,bit8,length);
  82.  
  83.             MIX_Reset();
  84.             MIX_SetOutput(MIX_STEREO);
  85.             MIX_SetInput(MIX_IN_CD|MIX_HIGH_FILT);
  86.             MIX_SetVolume(MIX_MASTER_VOL,3,9);
  87.             MIX_GetVolume(MIX_FM_VOL,&left,&right);
  88.  
  89.             while(dma_sb_busy && !kbhit());
  90.  
  91.             SB_RemoveVect();
  92.         }
  93.  
  94.         farfree(base);
  95.     }
  96.     else printf("usage: dactest filename [sample rate]\n");
  97. }
  98.