home *** CD-ROM | disk | FTP | other *** search
/ Sound Sensations! / sound_sensations.iso / soundb / qb_sbkit / demovmr.bas < prev    next >
BASIC Source File  |  1990-07-01  |  4KB  |  175 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. ' Free 4K memory for the CT-VOICE.DRV
  19. DUMMY = SETMEM(-4096)
  20.  
  21. ' Allocate 100K buffer for voice data
  22. DIM buffer%(1 TO 100,1 TO 512)
  23.  
  24. CLS
  25. PRINT "SBK Voice Recording (memory version) Example"
  26.  
  27. ' Set I/O address
  28. CTIOADDX (&H220)
  29.  
  30. ' Check for Sound Blaster Card
  31. IF ((SBCHKCRD% AND 4) = 4) THEN
  32.  
  33.      ' Scan for interrupt
  34.      IF (SBSCNINT% > 0) THEN
  35.  
  36.       ' Load CT-VOICE.DRV
  37.       DRVADDX% = LOADDRV%
  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.  
  48.             CALL SVMSPKER(INT(0))
  49.  
  50.             ' Record a voice file
  51.             CALL RECFILE("TEMP.VOC",buffer%())
  52.  
  53.             ' Terminate driver before exit
  54.             CALL SVMEXIT
  55.  
  56.            ENDIF
  57.  
  58.       END IF
  59.  
  60.      END IF
  61.  
  62. ELSE
  63.     PRINT "Sound Blaster Card not found"
  64. END IF
  65.  
  66. ' Return the memory to BASIC
  67. DUMMY = SETMEM(4096)
  68.  
  69. END
  70.  
  71.  
  72. ' ------------------------------------------------------------------------ '
  73.  
  74. REM $STATIC
  75. SUB RECFILE(filename$,buffer%())
  76.  
  77. ' This function records a voice buffer and saves it into file
  78.  
  79.      DIM   bufsize AS LONG
  80.  
  81.      ' Set the buffer size to 100K
  82.      bufsize = 100000&
  83.  
  84.      IF (RECORD%(buffer%(),bufsize) <> 0) THEN
  85.       CALL SAVEVOC(filename$,buffer%())
  86.      ENDIF
  87.  
  88. END SUB
  89.  
  90.  
  91. ' ------------------------------------------------------------------------ '
  92.  
  93.  
  94. FUNCTION RECORD%(buffer%(),bufsize&)
  95.  
  96. ' This function records the voice, until buffer full.
  97. ' Keyboard input is checked for terminating the recording before the buffer
  98. ' is full.
  99.  
  100.      DIM userkey AS INTEGER, voice AS INTEGER
  101.  
  102.      SVMSPKER INT(0)
  103.  
  104.      RECORD% = 0
  105.  
  106.      IF (SVMINPUT%(buffer%(1,1),bufsize&,INT(8000)) = 0) THEN
  107.  
  108.       RECORD% = 1
  109.  
  110.       WHILE CTVOICE% <> 0
  111.  
  112.            c$ = INKEY$
  113.  
  114.            IF c$ <> "" THEN
  115.  
  116.             IF c$=chr$(27) THEN
  117.              CALL SVMSTOP
  118.             ENDIF
  119.  
  120.            END IF
  121.  
  122.       WEND
  123.  
  124.      END IF
  125.  
  126. END FUNCTION
  127.  
  128.  
  129. ' ------------------------------------------------------------------------ '
  130.  
  131.  
  132. SUB SAVEVOC(filename$,buffer%())
  133.  
  134. ' This function save the buffer into a Creative Voice file format
  135.  
  136.      DIM header AS VOCHDR, handle AS INTEGER, bufsize AS LONG
  137.  
  138.      ' Setup the voice file format
  139.      header.id = "Creative Voice File" + CHR$(26)
  140.      header.offset = 26
  141.      header.version = &H10A
  142.      header.checkcode = &H1129
  143.  
  144.      ' Create a file
  145.      handle = DOSCREATE%(filename$)
  146.  
  147.      IF (handle <> 0) THEN
  148.  
  149.       ' Write the file header
  150.       IF (DOSWRITE%(handle,VARPTR(header.id),VARSEG(header.id),26) <> 0) THEN
  151.  
  152.            ' Get the voice block length from buffer
  153.            DEF SEG = VARSEG(buffer%(1,1))
  154.             bufsize = PEEK(VARPTR(buffer%(1,1)) + 1)
  155.            DEF SEG
  156.  
  157.            bufsize = bufsize + 256& * buffer%(2,1)
  158.  
  159.            ' Add 5 bytes for the block header and terminating block
  160.            bufsize = bufsize + 5
  161.  
  162.            ' Write the buffer
  163.            IF (DOSWRITE%(handle,VARPTR(buffer%(1,1)),VARSEG(buffer%(1,1)),bufsize) = 0) THEN
  164.             PRINT "Write file error."
  165.            ENDIF
  166.  
  167.       ENDIF
  168.  
  169.       CALL DOSCLOSE(handle)
  170.      ELSE
  171.       PRINT "Creating file error.\n"
  172.      ENDIF
  173.  
  174. END SUB
  175.