home *** CD-ROM | disk | FTP | other *** search
/ Apollo 18: The Moon Missions / 990125_1647.ISO / Landing / LM4 / SOUNDS.BAS < prev    next >
BASIC Source File  |  1996-06-06  |  7KB  |  206 lines

  1. Attribute VB_Name = "Module2"
  2. Option Explicit
  3. '------------------------------------------------------------
  4. ' WAVEMIX.BAS
  5. ' This module contains declarations for all the functions
  6. ' in the WaveMix DLL, and provides some higher-level Basic
  7. ' functions to make using WaveMix simpler.
  8. '------------------------------------------------------------
  9. Dim hWaveMix As Integer
  10. Dim lpWaveMix() As Long
  11. Dim WaveHandle As Integer
  12. Global WAVMIX_Quiet As Integer
  13.  
  14. Global Const WAVEMIX_MAXCHANNELS = 8
  15.  
  16. Type tChannelInfo
  17.     Loops As Integer
  18.     WaveFile As String
  19. End Type
  20.  
  21. Type WAVEMIXINFO
  22.    wSize As Integer
  23.    bVersionMajor As String * 1
  24.    bVersionMinor As String * 1
  25.    szDate(12) As String
  26.    dwFormats As Long
  27. End Type
  28.  
  29. Type MIXCONFIG
  30.     wSize As Integer
  31.     dwFlags As Long
  32.     wChannels As Integer
  33.     wSamplingRate As Integer
  34. End Type
  35.  
  36. Type MIXPLAYPARAMS
  37.     wSize As Integer
  38.     hMixSession As Integer
  39.     iChannel As Integer
  40.     lpMixWave As Long
  41.     hWndNotify As Integer
  42.     dwFlags As Long
  43.     wLoops As Integer
  44. End Type
  45.  
  46. ' WaveMix DLL declarations.
  47.  
  48. Declare Function WaveMixInit Lib "WAVEMIX.DLL" () As Integer
  49. Declare Function WaveMixConfigureInit Lib "WAVEMIX.DLL" (lpConfig As MIXCONFIG) As Integer
  50. Declare Function WaveMixActivate Lib "WAVEMIX.DLL" (ByVal hMixSession As Integer, ByVal fActivate As Integer) As Integer
  51. Declare Function WaveMixOpenWave Lib "WAVEMIX.DLL" (ByVal hMixSession As Integer, szWaveFilename As Any, ByVal hInst As Integer, ByVal dwFlags As Long) As Long
  52. Declare Function WaveMixOpenChannel Lib "WAVEMIX.DLL" (ByVal hMixSession As Integer, ByVal iChannel As Integer, ByVal dwFlags As Long) As Long
  53. Declare Function WaveMixPlay Lib "WAVEMIX.DLL" (lpMixPlayParams As MIXPLAYPARAMS) As Integer
  54. Declare Function WaveMixFlushChannel Lib "WAVEMIX.DLL" (ByVal hMixSession As Integer, ByVal iChannel As Integer, ByVal dwFlags As Long) As Integer
  55. Declare Function WaveMixCloseChannel Lib "WAVEMIX.DLL" (ByVal hMixSession As Integer, ByVal iChannel As Integer, ByVal dwFlags As Long) As Integer
  56. Declare Function WaveMixFreeWave Lib "WAVEMIX.DLL" (ByVal hMixSession As Integer, ByVal lpMixWave As Long) As Integer
  57. Declare Function WaveMixCloseSession Lib "WAVEMIX.DLL" (ByVal hMixSession As Integer) As Integer
  58. Declare Sub WaveMixPump Lib "WAVEMIX.DLL" ()
  59. Declare Function WaveMixGetInfo Lib "WAVEMIX.DLL" (lpWaveMixInfo As WAVEMIXINFO) As Integer
  60.  
  61. 'Channel
  62. Global Channel(0 To 7) As tChannelInfo
  63.  
  64. Function WAVMIX_AddFile(FileName As String) As Integer
  65. '------------------------------------------------------------
  66. ' Open a wave file and assign it to the next available
  67. ' channel.
  68. '------------------------------------------------------------
  69. Dim wRtn As Long
  70.  
  71.     WAVMIX_AddFile = False
  72.     If WAVMIX_Quiet Then Exit Function
  73.     If WaveHandle + 1 = WAVEMIX_MAXCHANNELS Then Exit Function
  74.  
  75.     ReDim Preserve lpWaveMix(WaveHandle)
  76.     lpWaveMix(WaveHandle) = WaveMixOpenWave(hWaveMix, ByVal FileName, 0, 0)
  77.     wRtn = WaveMixOpenChannel(hWaveMix, WaveHandle, 0)
  78.     WAVMIX_AddFile = WaveHandle
  79.     WaveHandle = WaveHandle + 1
  80. End Function
  81.  
  82. Sub WAVMIX_SetFile(FileName As String, AChannel As Integer)
  83. '------------------------------------------------------------
  84. ' Assign a new wave file, FileName, to the specified channel,
  85. ' AChannel.  If this channel is currently assigned another
  86. ' wave file, stop playing the channel and free the active
  87. ' wave file.
  88. '------------------------------------------------------------
  89. Dim wRtn As Long
  90.     
  91.     If WAVMIX_Quiet Then Exit Sub
  92.     
  93.     If AChannel > UBound(lpWaveMix) Then
  94.         ReDim Preserve lpWaveMix(AChannel)
  95.         WaveHandle = AChannel
  96.     End If
  97.     
  98.     ' If another wave is currently assigned to this
  99.     ' channel, free it.
  100.     If lpWaveMix(AChannel) <> 0 Then
  101.         WAVMIX_StopChannel AChannel
  102.         wRtn = WaveMixFreeWave(hWaveMix, lpWaveMix(AChannel))
  103.     End If
  104.     
  105.     ' Open the new wave and assign it to this channel.
  106.     lpWaveMix(AChannel) = WaveMixOpenWave(hWaveMix, ByVal FileName, 0, 0)
  107.     wRtn = WaveMixOpenChannel(hWaveMix, AChannel, 0)
  108. End Sub
  109.  
  110.  
  111. Sub WAVMIX_Close()
  112. '------------------------------------------------------------
  113. ' Stop playing all channels and free all wave files, then
  114. ' close down this WaveMix session.
  115. '------------------------------------------------------------
  116. Dim wRtn As Long
  117. Dim i As Integer, rc As Integer
  118.     
  119.     If WAVMIX_Quiet Then Exit Sub
  120.  
  121.     If (hWaveMix <> 0) Then
  122.         For i = 0 To UBound(lpWaveMix)
  123.             If lpWaveMix(i) <> 0 Then
  124.                 WAVMIX_StopChannel i
  125.                 rc = WaveMixFreeWave(hWaveMix, lpWaveMix(i))
  126.             End If
  127.         Next
  128.         wRtn = WaveMixCloseSession(hWaveMix)
  129.         hWaveMix = 0
  130.     End If
  131. End Sub
  132.  
  133. Function WAVMIX_InitMixer() As Integer
  134. '------------------------------------------------------------
  135. ' Initialize and activate the WaveMix DLL.
  136. '------------------------------------------------------------
  137. Dim wRtn As Long
  138. Dim config As MIXCONFIG
  139.  
  140.     If WAVMIX_Quiet Then Exit Function
  141.  
  142.     WaveHandle = 0
  143.     ReDim lpWaveMix(0)
  144.     ChDir App.path
  145.     
  146.     config.wSize = Len(config)
  147.     config.dwFlags = 1
  148.     'Allow stereo sound
  149.     config.wChannels = 2
  150.     hWaveMix = WaveMixConfigureInit(config)
  151.     wRtn = WaveMixActivate(hWaveMix, True)
  152.  
  153.     If (wRtn <> 0) Then
  154.         WAVMIX_InitMixer = False
  155.     Else
  156.         WAVMIX_InitMixer = True
  157.     End If
  158. End Function
  159.  
  160. Sub WAVMIX_StopChannel(ChannelNum As Integer)
  161. '------------------------------------------------------------
  162. ' Stop playing the specified channel.
  163. '------------------------------------------------------------
  164. Dim rc As Integer
  165.  
  166.     If WAVMIX_Quiet Then Exit Sub
  167.     If (hWaveMix = 0) Then Exit Sub
  168.     
  169.     rc = WaveMixFlushChannel(hWaveMix, ChannelNum, 0)
  170. End Sub
  171.  
  172. Sub WAVMIX_Activate(Activate As Integer)
  173. '------------------------------------------------------------
  174. ' Activate the WaveMix DLL.
  175. '------------------------------------------------------------
  176. Dim rc As Integer
  177.  
  178.     If WAVMIX_Quiet Then Exit Sub
  179.     If (hWaveMix = 0) Then Exit Sub
  180.  
  181.     rc = WaveMixActivate(hWaveMix, Activate)
  182. End Sub
  183.  
  184. Sub WAVMIX_PlayChannel(ChannelNum As Integer, LoopWave As Integer)
  185. '------------------------------------------------------------
  186. ' Play a specified channel, and indicate whether the sound
  187. ' should be looped.
  188. '------------------------------------------------------------
  189. Dim params As MIXPLAYPARAMS
  190. Dim wRtn As Long
  191.  
  192.     If WAVMIX_Quiet Then Exit Sub
  193.     If ChannelNum > UBound(lpWaveMix) Then Exit Sub
  194.     If (hWaveMix = 0) Then Exit Sub
  195.  
  196.     params.wSize = Len(params)
  197.     params.hMixSession = hWaveMix
  198.     params.iChannel = ChannelNum
  199.     params.lpMixWave = lpWaveMix(ChannelNum)
  200.     params.hWndNotify = 0
  201.     params.dwFlags = 5
  202.     params.wLoops = LoopWave
  203.     wRtn = WaveMixPlay(params)
  204. End Sub
  205.  
  206.