home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_BAS / QBSAMPLE.ZIP / QBSAMPLE.BAS < prev    next >
BASIC Source File  |  1994-01-18  |  2KB  |  101 lines

  1. DECLARE FUNCTION samplebyte% (bp%)
  2. DECLARE SUB writedsp (byte%, bp%)
  3. DECLARE SUB sbreset (bp%)
  4.  
  5. 'QB4.5 code to record a sample from the
  6. 'Soundblaster's Mic/Line Input and then
  7. 'play it back.  It does not detect for a
  8. 'Soundblaster, it's assumed that one is
  9. 'available.
  10.  
  11. 'This will be too slow in the IDE - run
  12. 'as a standalone .EXE file.
  13.  
  14. '(C) Copyright 1994 by Tim Gerchmez
  15. 'This code may be freely shared and
  16. 'distributed by any means desired.
  17.  
  18. bp% = &H220   'Soundblaster Base Port, change to &h240 or whatever
  19.               'for different hardware configuration
  20.  
  21. CALL sbreset(bp%) 'Reset the Soundblaster card
  22.  
  23. CLS : PRINT
  24. PRINT "Soundblaster Sample/Playback (direct, non-DMA)"
  25. PRINT
  26. INPUT "Length of Sample (1-32766)"; ls%
  27. IF ls% < 1 OR ls% > 32766 THEN END
  28. PRINT
  29. PRINT "Speak into the Microphone or start input to"
  30. PRINT "Line In jack.  Press a key to begin sampling."
  31. SLEEP
  32. PRINT : PRINT "Now Sampling..."
  33.  
  34. REDIM smp%(1 TO ls%)
  35.  
  36. FOR t% = 1 TO ls%
  37.         smp%(t%) = samplebyte(bp%)
  38.         FOR u% = 1 TO 25: NEXT u%  'Delay a little
  39. NEXT t%
  40.  
  41. 'Now play the sample back
  42.  
  43. CALL writedsp(&HD1, bp%)  'Turn speaker on
  44. FOR t% = 1 TO ls%
  45.         CALL writedsp(&H10, bp%)
  46.         CALL writedsp(smp%(t%), bp%)
  47. NEXT t%
  48. CALL writedsp(&HD3, bp%)  'Turn speaker off
  49.  
  50. FUNCTION samplebyte% (bp%)
  51.  
  52. 'Samples a byte from the SB's ADC, and returns
  53. 'the resultant byte.  Call with BP% = SB base port
  54. '(normally &h220)
  55.  
  56.  
  57. CALL writedsp(&H20, bp%) 'Command to sample one byte
  58. datavail% = bp% + 14
  59. dly:
  60.         IF INP(datavail%) AND &H80 = 0 THEN GOTO dly
  61. datread% = bp% + 10
  62. bt% = INP(datread%)
  63. samplebyte% = bt%
  64.  
  65. END FUNCTION
  66.  
  67. SUB sbreset (bp%)
  68.  
  69. 'Resets the Soundblaster chip -
  70. 'call with bp% = Base Port (normally &h220)
  71.  
  72. dspreset% = bp% + 6
  73. OUT dspreset%, 1
  74. FOR t% = 1 TO 10
  75.         a% = INP(dspreset%)  'Delay loop, give SB time to reset
  76. NEXT t%
  77. OUT dspreset%, 0
  78. dspread% = bp% + 10
  79. FOR t% = 1 TO 10
  80.         a% = INP(dspread%)
  81. NEXT t%
  82.  
  83. END SUB
  84.  
  85. SUB writedsp (byte%, bp%)
  86.  
  87. 'Writes to the Soundblaster's DSP Command Channel -
  88. 'call with bp% = SB base port (normally &h220)
  89. 'byte% = byte to write to DSP
  90.  
  91. dspcmd% = bp% + 12
  92. FOR t% = 1 TO 8
  93.         q% = INP(dspcmd%) 'Delay to give SB time to process code
  94. NEXT t%
  95. OUT dspcmd%, byte%
  96.  
  97.  
  98.  
  99. END SUB
  100.  
  101.