home *** CD-ROM | disk | FTP | other *** search
/ Sound Sensations! / sound_sensations.iso / soundb / qb_sbkit / democmf.bas < prev    next >
BASIC Source File  |  1990-07-01  |  3KB  |  163 lines

  1. '
  2. ' This program output the sample CMF file FFARES.CMF
  3. '
  4.  
  5. ' $INCLUDE: 'SBC.BI'
  6. ' $INCLUDE: 'SBCSYS.BI'
  7. ' $INCLUDE: 'SBCMUSIC.BI'
  8.  
  9. DECLARE FUNCTION LODCMF% (filename$, segment%, offset%)
  10. DECLARE SUB PLAYCMF(buffer%())
  11.  
  12. REM $DYNAMIC
  13. CLEAR
  14.  
  15. CLS
  16.  
  17. PRINT "SBK QuickBasic Play CMF File Example"
  18.  
  19. ' Allocate 64K buffer for CMF file
  20. DIM buffer%(1 TO 64,1 TO 512)
  21.  
  22. ' Set I/O address
  23. CTIOADDX (&H220)
  24.  
  25. ' Check for Sound Blaster Card
  26. IF (SBCHKCRD% > 4) THEN
  27.  
  28.      ' Initialize driver
  29.      IF (SMINIT% <> 0) THEN
  30.  
  31.       ' Load music file
  32.       IF (LODCMF("FFARES.CMF", VARSEG(buffer%(1,1)), VARPTR(buffer%(1,1))) <> 0) THEN
  33.  
  34.            ' Check for file version number
  35.            IF buffer%(3,1) < &h101 THEN
  36.             PRINT "Old version not supported."
  37.            ELSE
  38.             CALL PLAYCMF(buffer%())
  39.            ENDIF
  40.  
  41.       ENDIF
  42.  
  43.       ' Terminate driver before exit
  44.       CALL SMEXIT
  45.      ELSE
  46.       PRINT "SBFMDRV driver not installed"
  47.      ENDIF
  48.  
  49. ELSE
  50.     PRINT "Sound Blaster Card not found"
  51. END IF
  52.  
  53. END
  54.  
  55.  
  56. ' ------------------------------------------------------------------------ '
  57.  
  58.  
  59. REM $STATIC
  60. FUNCTION LODCMF% (filename$, segment%, offset%)
  61.  
  62. ' This function loads voice file into buffer%
  63.  
  64.      DIM handle%, filelen&
  65.  
  66.      handle% = DOSOPEN(filename$)
  67.      LODCMF% = 0
  68.  
  69.      IF (handle% <> 0) THEN
  70.       filelen& = FILESIZE&(handle%)
  71.  
  72.       IF (DOSREAD%(handle%, offset%, segment%, filelen&) <> 0) THEN
  73.            LODCMF% = 1
  74.       ELSE
  75.            PRINT "Read file error."
  76.       END IF
  77.  
  78.       DOSCLOSE(handle%)
  79.      ELSE
  80.       PRINT "Open " + filename$ + "error."
  81.      END IF
  82.  
  83. END FUNCTION
  84.  
  85.  
  86. ' ------------------------------------------------------------------------ '
  87.  
  88.  
  89. SUB PLAYCMF (buffer%())
  90.  
  91.      DIM insblk AS INTEGER, musicblk AS INTEGER
  92.      DIM time0rate AS INTEGER, freq AS LONG
  93.  
  94.      ' Get instrument table offset
  95.      insblk = buffer%(4,1)
  96.  
  97.      ' Get music offset
  98.      musicblk = buffer%(5,1)
  99.  
  100.      ' Reset driver
  101.      CALL SMRESET
  102.  
  103.      ' Set song frequency
  104.      freq = 1193180&
  105.      freq = freq / buffer%(7,1)
  106.      time0rate = freq
  107.      CALL SMSONSPD(time0rate)
  108.  
  109.      ' Set instrument table
  110.      CALL SMINST(buffer%(INT(insblk/2+1),1),buffer%(19,1))
  111.  
  112.      ' Start Music
  113.      CALL SMPLAY(buffer%(INT(musicblk/2+1),1))
  114.  
  115.      ' Wait Music End
  116.  
  117.      CALL WAITMUS
  118.  
  119. END SUB
  120.  
  121.  
  122. ' ------------------------------------------------------------------------ '
  123.  
  124.  
  125. SUB  WAITMUS
  126.  
  127.      DIM  userkey AS INTEGER, transpose AS INTEGER
  128.  
  129.      transpose = 0
  130.  
  131.      WHILE SMSTATUS% <> 0
  132.  
  133.       c$ = INKEY$
  134.  
  135.       IF c$ <> "" THEN
  136.  
  137.            userkey = ASC(c$)
  138.  
  139.            SELECT CASE userkey
  140.             CASE ASC("S"), ASC("s"), 27
  141.              CALL SMSTOP
  142.             CASE ASC("P"), ASC("p")
  143.              CALL SMPAUSE
  144.             CASE ASC("C"), ASC("c")
  145.              CALL SMRESUME
  146.             CASE 0
  147.              userkey = ASC(MID$(c$,2,1))
  148.  
  149.              IF userkey = 75 THEN
  150.                   transpose = transpose - 1
  151.              ELSEIF userkey = 77 THEN
  152.                   transpose = transpose + 1
  153.              ENDIF
  154.  
  155.              CALL SMTRNPOS(transpose)
  156.            END SELECT
  157.  
  158.       ENDIF
  159.  
  160.      WEND
  161.  
  162. END SUB
  163.