home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m003_1 / sdk_dos.ddi / BASIC / VOICE / DEMOVMR.BAS < prev   
Encoding:
BASIC Source File  |  1991-11-13  |  5.4 KB  |  230 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 FUNCTION LDVFILE% (filename$, segment%, offset%)
  10. DECLARE SUB RECFILE(filename$,buffer%())
  11. DECLARE FUNCTION RECORD%(buffer%(),bufsize&)
  12. DECLARE SUB SAVEVOC(filename$,buffer%())
  13.  
  14.  
  15. REM $DYNAMIC
  16. CLEAR
  17.  
  18. ' Following statements free memory for the loadable drivers.
  19. ' You must free sufficient memory for the loadable drivers.
  20. ' The free memory must be larger than the driver file size.
  21.  
  22. ' Free 8K memory for the CT-VOICE.DRV at the moment
  23. DUMMY = SETMEM(-8192)
  24.  
  25. ' Allocate 100K buffer for voice data file
  26. DIM buffer%(1 TO 100, 1 TO 512)
  27.  
  28. CLS
  29. PRINT "SBK Voice Recording (memory version) Example"
  30.  
  31. IF (SBGETENV% = 0) THEN
  32.     IF SBCHKCRD% THEN
  33.         IF SBTSTINT% THEN
  34.             IF SBTSTDMA% >= 0 THEN
  35.  
  36.                 ' Load CT-VOICE.DRV
  37.                 DRVADDX% = LOADDRV% ("CT-VOICE.DRV")
  38.  
  39.                 ' If driver loaded successfully
  40.                 IF (DRVADDX% <> 0) THEN
  41.  
  42.                     ' Set driver address
  43.                     CTVADDX (DRVADDX%)
  44.  
  45.                     ' Initialize driver
  46.                     IF (SVMINIT% = 0) THEN
  47.                         CALL SVMSPKER(INT(0))
  48.  
  49.                         ' Record a voice file
  50.                         CALL RECFILE("TEMP.VOC",buffer%())
  51.  
  52.                         ' Terminate driver before exit
  53.                         CALL SVMEXIT
  54.                     END IF
  55.  
  56.                     ' Release memory allocated for CT-VOICE
  57.                     CALL FREEMEM(DRVADDX%)
  58.                 END IF
  59.             ELSE
  60.                 PRINT "Error on DMA channel."
  61.             ENDIF
  62.         ELSE
  63.             PRINT "Error on interrupt."
  64.         ENDIF
  65.     ELSE
  66.         PRINT "Sound Blaster Card not found or wrong I/O setting"
  67.     ENDIF
  68. ELSE
  69.     PRINT "BLASTER environment variable not set or incomplete or invalid."
  70. ENDIF
  71.  
  72. ' Return memory to BASIC
  73. DUMMY = SETMEM(8192)
  74.  
  75. END
  76.  
  77.  
  78. ' ------------------------------------------------------------------------ '
  79.  
  80. FUNCTION LOADDRV% (szDrvName$)
  81.  
  82.     DIM szDrvFile$, Handle%, dwFileLen&, wDrvSeg%
  83.  
  84.  
  85.     LOADDRV% = 0
  86.  
  87.     ' search SOUND environment for driver
  88.     szDrvFile$ = ENVIRON$("SOUND")
  89.  
  90.     IF (szDrvFile$ <> "") THEN
  91.         szDrvFile$ = szDrvFile$ + "\DRV\" + szDrvName$
  92.  
  93.         IF (FINDFILE%(szDrvFile$) = 0) THEN
  94.             szDrvFile$ = ""
  95.         ENDIF
  96.     ENDIF
  97.  
  98.     ' search the current directory for driver
  99.     IF (szDrvFile$ = "") THEN
  100.         szDrvFile$ = szDrvName$
  101.     ENDIF
  102.  
  103.     IF (FINDFILE%(szDrvFile$) <> 0) THEN
  104.         Handle% = DOSOPEN%(szDrvFile$)
  105.  
  106.         IF (Handle% <> 0) THEN
  107.             dwFileLen& = FILESIZE(Handle%)
  108.  
  109.             wDrvSeg% = ALLOCMEM(INT((dwFileLen& + 15) / 16))
  110.  
  111.             IF (wDrvSeg% <> 0) THEN
  112.                 IF DOSREAD%(Handle%, INT(0), wDrvSeg%, dwFileLen&) THEN
  113.                     LOADDRV% = wDrvSeg%
  114.                 ENDIF
  115.             ENDIF
  116.  
  117.             DOSCLOSE(Handle%)
  118.         ELSE
  119.             PRINT "Error in opening " + szDrvFile$
  120.         ENDIF
  121.     ELSE
  122.         PRINT "Driver file " + szDrvName$ + " does not exist ..."
  123.     ENDIF
  124.  
  125. END FUNCTION
  126.  
  127.  
  128. ' ------------------------------------------------------------------------ '
  129.  
  130. REM $STATIC
  131. SUB RECFILE(filename$,buffer%())
  132.  
  133. ' This function records a voice buffer and saves it into file
  134.  
  135.      DIM   bufsize AS LONG
  136.  
  137.      ' Set the buffer size to 100K
  138.      bufsize = 100000&
  139.  
  140.      IF (RECORD%(buffer%(),bufsize) <> 0) THEN
  141.       CALL SAVEVOC(filename$,buffer%())
  142.      ENDIF
  143.  
  144. END SUB
  145.  
  146.  
  147. ' ------------------------------------------------------------------------ '
  148.  
  149.  
  150. FUNCTION RECORD%(buffer%(),bufsize&)
  151.  
  152. ' This function records the voice, until buffer full.
  153. ' Keyboard input is checked for terminating the recording before the buffer
  154. ' is full.
  155.  
  156.      DIM userkey AS INTEGER, voice AS INTEGER
  157.  
  158.      CALL SVMSPKER(INT(0))
  159.      RECORD% = 0
  160.  
  161.      IF (SVMINPUT%(buffer%(1,1),bufsize&,INT(8000)) = 0) THEN
  162.  
  163.       RECORD% = 1
  164.  
  165.       WHILE CTVOICE% <> 0
  166.  
  167.            c$ = INKEY$
  168.  
  169.            IF c$ <> "" THEN
  170.  
  171.             IF c$=chr$(27) THEN
  172.              CALL SVMSTOP
  173.             ENDIF
  174.  
  175.            END IF
  176.  
  177.       WEND
  178.  
  179.      END IF
  180.  
  181. END FUNCTION
  182.  
  183.  
  184. ' ------------------------------------------------------------------------ '
  185.  
  186.  
  187. SUB SAVEVOC(filename$,buffer%())
  188.  
  189. ' This function save the buffer into a Creative Voice file format
  190.  
  191.      DIM header AS VOCHDR, handle AS INTEGER, bufsize AS LONG
  192.  
  193.      ' Setup the voice file format
  194.      header.id = "Creative Voice File" + CHR$(26)
  195.      header.offset = 26
  196.      header.version = &H10A
  197.      header.checkcode = &H1129
  198.  
  199.      ' Create a file
  200.      handle = DOSCREATE%(filename$)
  201.  
  202.      IF (handle <> 0) THEN
  203.  
  204.       ' Write the file header
  205.       IF (DOSWRITE%(handle,VARPTR(header.id),VARSEG(header.id),26) <> 0) THEN
  206.  
  207.            ' Get the voice block length from buffer
  208.            DEF SEG = VARSEG(buffer%(1,1))
  209.             bufsize = PEEK(VARPTR(buffer%(1,1)) + 1)
  210.            DEF SEG
  211.  
  212.            bufsize = bufsize + 256& * buffer%(2,1)
  213.  
  214.            ' Add 5 bytes for the block header and terminating block
  215.            bufsize = bufsize + 5
  216.  
  217.            ' Write the buffer
  218.            IF (DOSWRITE%(handle,VARPTR(buffer%(1,1)),VARSEG(buffer%(1,1)),bufsize) = 0) THEN
  219.             PRINT "Write file error."
  220.            ENDIF
  221.  
  222.       ENDIF
  223.  
  224.       CALL DOSCLOSE(handle)
  225.      ELSE
  226.       PRINT "Creating file error.\n"
  227.      ENDIF
  228.  
  229. END SUB
  230.