home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- BorderStyle = 1 'Fixed Single
- Caption = "Form1"
- ClientHeight = 4065
- ClientLeft = 45
- ClientTop = 420
- ClientWidth = 5175
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 271
- ScaleMode = 3 'Pixel
- ScaleWidth = 345
- StartUpPosition = 2 'CenterScreen
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- '----------------------------------------------------------------------
- ' Visual Basic Game Programming With DirectX
- ' SoundTest Program
- '----------------------------------------------------------------------
- Option Explicit
- Option Base 0
- 'program variables
- Dim dx As DirectX8
- Dim ds As DirectSound8
- Dim Sound1 As DirectSoundSecondaryBuffer8
- Private Sub Form_Load()
- 'create the DirectX8 object
- Set dx = New DirectX8
- 'create the DirectSound8 object
- Set ds = dx.DirectSoundCreate("")
- If Err.Number <> 0 Then
- MsgBox "Error creating DirectSound object"
- Shutdown
- End If
- 'set the priority level for DirectSound
- ds.SetCooperativeLevel Me.hWnd, DSSCL_PRIORITY
- 'load the wave files
- Set Sound1 = LoadSound(App.Path & "\halleluja.wav")
- 'play the halleleuia sound
- PlaySound Sound1, False, False
- End Sub
- Public Function LoadSound(ByVal sFilename As String) _
- As DirectSoundSecondaryBuffer8
- Dim dsBuf As DSBUFFERDESC
- 'set up sound buffer for normal playback
- dsBuf.lFlags = DSBCAPS_STATIC
- 'load wave file into DirectSound buffer
- Set LoadSound = ds.CreateSoundBufferFromFile(sFilename, dsBuf)
- If Err.Number <> 0 Then
- MsgBox "Error loading sound file: " & sFilename
- Shutdown
- End If
- End Function
- Public Sub PlaySound(ByRef Sound As DirectSoundSecondaryBuffer8, _
- ByVal bCloseFirst As Boolean, ByVal bLoopSound As Boolean)
- 'stop currently playing waves?
- If bCloseFirst Then
- Sound.Stop
- Sound.SetCurrentPosition 0
- End If
- 'loop the sound?
- If bLoopSound Then
- Sound.Play DSBPLAY_LOOPING
- Else
- Sound.Play DSBPLAY_DEFAULT
- End If
- End Sub
- Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
- If KeyCode = 27 Then Shutdown
- End Sub
- Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
- Shutdown
- End Sub
- Private Sub Shutdown()
- 'stop sound playback
- Sound1.Stop
- 'delete DirectX Audio objects
- Set dx = Nothing
- Set ds = Nothing
- Set Sound1 = Nothing
- End
- End Sub
-