home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m003_1 / sdk_dos.ddi / BASIC / MUSIC / DEMOCMF.BAS next >
Encoding:
BASIC Source File  |  1991-11-13  |  3.1 KB  |  153 lines

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