home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m003_1 / sdk_dos.ddi / BASIC / VOICE / DEMOVDR.BAS < prev    next >
Encoding:
BASIC Source File  |  1991-11-13  |  4.4 KB  |  203 lines

  1. '
  2. ' This program records a voice file TEMP.VOC
  3. '
  4.  
  5. ' $INCLUDE: 'SBC.BI'
  6. ' $INCLUDE: 'SBCSYS.BI'
  7. ' $INCLUDE: 'SBCVOICE.BI'
  8.  
  9. DECLARE   SUB  RECVOCFILE(filename$)
  10. DECLARE   SUB  SHOWERROR()
  11.  
  12. REM $DYNAMIC
  13. CLEAR
  14.  
  15. ' Following statements free memory for the loadable drivers.
  16. ' You must free sufficient memory for the loadable drivers.
  17. ' The free memory must be larger than the driver file size.
  18.  
  19. ' Free 8K memory for the CTVDSK.DRV at the moment
  20. DUMMY = SETMEM(-8192)
  21.  
  22. ' Following statements free memory for the Disk Double Buffer
  23. ' Two 32K buffers are released by BASIC
  24. DUMMY = SETMEM(-16400)
  25. DUMMY = SETMEM(-16400)
  26. DUMMY = SETMEM(-16400)
  27. DUMMY = SETMEM(-16400)
  28.  
  29. CLS
  30.  
  31. PRINT "SBK Basic Voice Recording (disk version) Example"
  32.  
  33. IF (SBGETENV% = 0) THEN
  34.     IF SBCHKCRD% THEN
  35.         IF SBTSTINT% THEN
  36.             IF SBTSTDMA% >= 0 THEN
  37.  
  38.                 ' Load CTVDSK.DRV
  39.                 DRVADDX% = LOADDRV% ("CTVDSK.DRV")
  40.  
  41.                 ' If driver loaded successfully
  42.                 IF (DRVADDX% <> 0) THEN
  43.  
  44.                     ' Set driver address
  45.                     DSKADDX (DRVADDX%)
  46.  
  47.                     ' Initial the driver, with 64K buffer as double buffer
  48.                     IF ( SVDINIT%((16)) = 0 ) THEN
  49.  
  50.                         ' Off DAC speaker
  51.                         CALL SVDSPKER(INT(0))
  52.  
  53.                         ' Output the voice file
  54.                         CALL RECVOCFILE("TEMP.VOC")
  55.  
  56.                         ' Terminate the driver
  57.                         CALL SVDEXIT
  58.  
  59.                     ELSE
  60.                         CALL SHOWERROR
  61.                     ENDIF
  62.  
  63.                     ' Release memory allocated for CTVDSK
  64.                     CALL FREEMEM(DRVADDX%)
  65.                 ENDIF
  66.             ELSE
  67.                 PRINT "Error on DMA channel."
  68.             ENDIF
  69.         ELSE
  70.             PRINT "Error on interrupt."
  71.         ENDIF
  72.     ELSE
  73.         PRINT "Sound Blaster Card not found or wrong I/O setting"
  74.     ENDIF
  75. ELSE
  76.     PRINT "BLASTER environment variable not set or incomplete or invalid."
  77. ENDIF
  78.  
  79. ' Return the memory to BASIC
  80. DUMMY = SETMEM(16400)
  81. DUMMY = SETMEM(16400)
  82. DUMMY = SETMEM(16400)
  83. DUMMY = SETMEM(16400)
  84.  
  85. DUMMY = SETMEM(8192)
  86.  
  87. END
  88.  
  89.  
  90. ' ------------------------------------------------------------------------ '
  91.  
  92. FUNCTION LOADDRV% (szDrvName$)
  93.  
  94.     DIM szDrvFile$, Handle%, dwFileLen&, wDrvSeg%
  95.  
  96.  
  97.     LOADDRV% = 0
  98.  
  99.     ' search SOUND environment for driver
  100.     szDrvFile$ = ENVIRON$("SOUND")
  101.  
  102.     IF (szDrvFile$ <> "") THEN
  103.         szDrvFile$ = szDrvFile$ + "\DRV\" + szDrvName$
  104.  
  105.         IF (FINDFILE%(szDrvFile$) = 0) THEN
  106.             szDrvFile$ = ""
  107.         ENDIF
  108.     ENDIF
  109.  
  110.     ' search the current directory for driver
  111.     IF (szDrvFile$ = "") THEN
  112.         szDrvFile$ = szDrvName$
  113.     ENDIF
  114.  
  115.     IF (FINDFILE%(szDrvFile$) <> 0) THEN
  116.         Handle% = DOSOPEN%(szDrvFile$)
  117.  
  118.         IF (Handle% <> 0) THEN
  119.             dwFileLen& = FILESIZE(Handle%)
  120.  
  121.             wDrvSeg% = ALLOCMEM(INT((dwFileLen& + 15) / 16))
  122.  
  123.             IF (wDrvSeg% <> 0) THEN
  124.                 IF DOSREAD%(Handle%, INT(0), wDrvSeg%, dwFileLen&) THEN
  125.                     LOADDRV% = wDrvSeg%
  126.                 ENDIF
  127.             ENDIF
  128.  
  129.             DOSCLOSE(Handle%)
  130.         ELSE
  131.             PRINT "Error in opening " + szDrvFile$
  132.         ENDIF
  133.     ELSE
  134.         PRINT "Driver file " + szDrvName$ + " does not exist ..."
  135.     ENDIF
  136.  
  137. END FUNCTION
  138.  
  139.  
  140. ' ------------------------------------------------------------------------ '
  141.  
  142.  
  143. REM %STATIC
  144. SUB  RECVOCFILE(filename$)
  145.  
  146. ' This function create a file and record voice into it
  147.  
  148.      DIM  handle AS INTEGER, userkey AS INTEGER
  149.  
  150.      handle = DOSCREATE%(filename$)
  151.  
  152.      IF (handle <> 0) THEN
  153.  
  154.       SVDSPKER(INT(0))
  155.  
  156.       IF (SVDINPUT%(handle,(8000)) = 0) THEN
  157.  
  158.            WHILE CTVOICE% <> 0
  159.  
  160.             c$ = INKEY$
  161.  
  162.             IF (c$ <> "") THEN
  163.  
  164.              userkey = ASC(c$)
  165.  
  166.              IF userkey = 27 THEN
  167.                   CALL SVDSTOP
  168.              ENDIF
  169.  
  170.             ENDIF
  171.  
  172.            WEND
  173.  
  174.       ENDIF
  175.  
  176.      ENDIF
  177.  
  178. END SUB
  179.  
  180.  
  181. ' ------------------------------------------------------------------------ '
  182.  
  183.  
  184. SUB  SHOWERROR
  185.  
  186. ' This function show the error code from the driver
  187.  
  188.      DIM  errcode AS INTEGER
  189.  
  190.      errcode = SVDDRVERR%
  191.  
  192.      PRINT "Driver error ="; errcode
  193.  
  194.      errcode = SVDEXTERR%
  195.  
  196.      IF (errcode <> 0) THEN
  197.         PRINT "Dos error ="; errcode
  198.      ENDIF
  199.  
  200. END SUB
  201.  
  202.  
  203.