home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / g / gametp20.zip / DSOUND.INT < prev    next >
Text File  |  1992-11-05  |  8KB  |  234 lines

  1. Unit Dsound;
  2.  
  3. { DSOUND version 1.0 Copyright (C) 1992 Scott D. Ramsay     }
  4. {                                  ramsays@access.digex.com }
  5.  
  6. {   This unit allows you to play VOC files in the background with a   }
  7. { sound blaster compatible card. The VOC files can be in the heap     }
  8. { space or EMS memory.  For EMS memory, VOC files must be under 64k   }
  9. { in size.  Heap space voc files can be greater than 64k in size.     }
  10. {   DSOUND.TPU can be used freely in commerical and non-commerical    }
  11. { programs.  As long as you don't give yourself credit for writing    }
  12. { this portion of the code.  When distributing it please include all  }
  13. { files and samples so others may enjoy using the code.  Thanks.      }
  14.  
  15. Interface
  16.  
  17. Uses Dos,LimEMS;
  18.  
  19. const
  20.   ScardHere  : boolean = false;          { Is set to true if Sound Blaster }
  21.                                          {  card is found.                 }
  22.   n16_block  = 4;                        { largest size of heap VOC file   }
  23.                                          {  size = n16block*$fff8          }
  24.  
  25. type
  26.   Psound    = ^Tsound;
  27.   Tsound    = object
  28.                 sblk   : array[0..n16_block-1] of pointer;
  29.                 size   : longint;
  30.                 blck   : byte;
  31.                 initok : boolean;
  32.                 constructor init(vocfile:string);
  33.                 function loadvoc(vocfile:string):boolean; virtual;
  34.                 function filevoc(var fil:file;bsize:longint):boolean; virtual;
  35.                 procedure cleanvoc; virtual;
  36.                 procedure play; virtual;
  37.                 destructor done; virtual;
  38.               end;
  39.   PEmsSound = ^TEmsSound;
  40.   TEmsSound = object(Tsound)
  41.                 EMSseg,handle : word;
  42.                 EMSok         : boolean;
  43.                 constructor init(vocfile:string);
  44.                 function loadvoc(vocfile:string):boolean; virtual;
  45.                 procedure cleanvoc; virtual;
  46.                 procedure play; virtual;
  47.                 destructor done; virtual;
  48.               end;
  49.  
  50. var
  51.   StatusWord : Word;        { stores status of voice file  }
  52.                             {   0   -  No sound is playing }
  53.                             {  FFFF - Sound is playing     }
  54.  
  55. function ScardSetup(portn,Intn:byte): boolean;
  56. function Use_DRV(fn:string):boolean;
  57. procedure PlayVOC(var buffer);
  58. procedure Scard_IO(add:word);
  59. procedure Scard_INT(intno:word);
  60. procedure Scard_stop;
  61. function Scard_pause : integer;
  62. function scard_resume : integer;
  63.  
  64. { See Implementation section for description of functions }
  65.  
  66. implementation
  67.  
  68. (*************************************************************************)
  69. function Use_DRV(fn:string):boolean;
  70.  
  71.   If you want to use a driver supplied by Sound Blaster instead of
  72.  the unit's internal driver, call this function after SCARDSETUP.
  73.  
  74.    fn   the file name of the SB driver.  Usually CT-VOICE.DRV.
  75.  
  76. (*************************************************************************)
  77. procedure Scard_IO(add:word);
  78.  
  79.   Called by SCARDSETUP.  Sets to the card IO port address.
  80.  
  81. (*************************************************************************)
  82. procedure Scard_Int(intno:word);
  83.  
  84.   Called by SCARDSETUP.  Sets to the card IRQ number.
  85.  
  86. (*************************************************************************)
  87. procedure Scard_stop;
  88.  
  89.   Stops playing sounds.
  90.  
  91. (*************************************************************************)
  92. function Scard_pause : integer;
  93.  
  94.   Pauses playing sounds.
  95.  
  96.   returns 0 no error
  97.  
  98. (*************************************************************************)
  99. function scard_resume : integer;
  100.  
  101.   Resumes playing paused sounds.
  102.  
  103.   returns 0 no error
  104.  
  105. (*************************************************************************)
  106. function ScardSetup(portn,Intn:byte): boolean;
  107.  
  108.   Inits the DSOUND unit and card.  Returns TRUE if card is found.
  109.  
  110.   portn     : Port address of Sound card
  111.   intn      : IRQ number of Sound card
  112.  
  113.     NOTE:   set PORTN and INTN to 0 to use BLASTER environment variable
  114.            for setting the port and IRQ.
  115.  
  116. (*************************************************************************)
  117. procedure PlayVOC(var buffer);
  118.  
  119.   Play a voice file.  At memory location BUFFER.
  120.  
  121. (*************************************************************************)
  122. constructor Tsound.init(vocfile:string);
  123.  
  124.   Inits Tsound.  Loads voice in memory.
  125.  
  126.    Tsound variables:
  127.  
  128.   sblk    Pointers to hold 64k blocks of voice file.
  129.   size    Size of voice file.  set to zero if none, or error
  130.   blck    number of 64k blocks voice uses.
  131.   initok  set TRUE if no error loading voice.
  132.  
  133. (*************************************************************************)
  134. function Tsound.filevoc(var fil:file;bsize:longint):boolean;
  135.  
  136.   Same as Tsound.loadvoc, loads a voc file in a file.
  137.  
  138.   fil     A file that is already open and the current file position
  139.           is the beginning of voc file.
  140.   bsize   size of the voice.
  141.  
  142.   This method is used by FLICS.TPU,  this method is good if you want
  143.  to pool your VOC files to one big file.
  144.  
  145.  See also:
  146.      Tsound.loadvoc
  147.  
  148. (*************************************************************************)
  149. function Tsound.loadvoc(vocfile:string): boolean;
  150.  
  151.   This method loads the voc file into heap memory.  Returns TRUE if
  152.   successfull.
  153.  
  154. (*************************************************************************)
  155. procedure Tsound.play;
  156.  
  157.   Take a guess.  Plays the sound.
  158.  
  159. (*************************************************************************)
  160. procedure Tsound.cleanvoc;
  161.  
  162.   Deallocates the sound from heap space
  163.  
  164. (*************************************************************************)
  165. destructor Tsound.Done;
  166.  
  167.   Calls Tsound.cleanvoc;
  168.  
  169. (*************************************************************************)
  170. constructor TEmsSound.init(vocfile:string);
  171.  
  172.   Inits TEmsSound.  Loads voice in EMS memory.
  173.  
  174.    TEmsSound variables:
  175.  
  176.    EMSseg           EMS segment windows address
  177.    handle           handle to the EMS memory
  178.    EMSok            TRUE if EMS is ok, and voc file is under 64k
  179.  
  180. (*************************************************************************)
  181. function TEmsSound.loadvoc(vocfile:string):boolean;
  182.  
  183.   Same as Tsound.loadvoc
  184.  
  185.   Loads a vocfile to EMS memory returns TRUE is successful.
  186.   voice file must be under 64k
  187.  
  188. (*************************************************************************)
  189. function TEmsSound.filevoc
  190.  
  191.   It is inherited from TSound  do not call.  Not implemented.
  192.  
  193. (*************************************************************************)
  194. procedure TEmsSound.cleanvoc;
  195.  
  196.  Same as TSound.cleanvoc
  197.  
  198.   Deallocates the sound from EMS memory
  199.  
  200. (*************************************************************************)
  201. procedure TEmsSound.play;
  202.  
  203.   Plays sound
  204.  
  205. (*************************************************************************)
  206. destructor TEmsSound.done;
  207.  
  208.   calls TemsSound.cleanvoc
  209.  
  210. (*************************************************************************)
  211.  
  212.  
  213. Note:   This unit uses EXITPROC pointer to deallocate its
  214.        internal workings.  If you use EXITPROC in you program
  215.        be sure to chain it.
  216.  
  217.        e.g.
  218.  
  219.        var
  220.          OldExitProc : pointer;
  221.  
  222.        procedure MyExitProcedure; far;
  223.        begin
  224.          { do my exit coding here }
  225.          ExitProc := OldExitProc;
  226.        end;
  227.  
  228.          .
  229.          .
  230.          .
  231.  
  232.          OldExitProc := ExitProc;
  233.          ExitProc := @MyExitProcedure;
  234.