I did some reading and looking at code and figured out how to play sound files. Woohoo!
The attached 7zip file contains the test program and the WAV files.
I will add sounds to the game soon.
PS I would still like to include the sound data in the program itself,
rather than have to use external resources (sound files).
I saw Fellippe's "frostbite.bas" generates the files if they are not found.
It uses ogg format which might be necessary to keep the program size smaller.
I need to find code to generate the data statements in "LoadAssets" -
it looks like base64 encoding not entirely sure.
This method seems easier than trying to generate WAV files from scratch or using _SNDRAW,
so I will look more into this when I have time...
The attached 7zip file contains the test program and the WAV files.
I will add sounds to the game soon.
PS I would still like to include the sound data in the program itself,
rather than have to use external resources (sound files).
I saw Fellippe's "frostbite.bas" generates the files if they are not found.
It uses ogg format which might be necessary to keep the program size smaller.
I need to find code to generate the data statements in "LoadAssets" -
it looks like base64 encoding not entirely sure.
This method seems easier than trying to generate WAV files from scratch or using _SNDRAW,
so I will look more into this when I have time...
Code: (Select All)
' Just a little sound test program to see if we can
' play and loop WAV files, change volume,
' and play 2 or more simultaneously.
' It works!
' BOOLEAN CONSTANTS
Const FALSE = 0
Const TRUE = Not FALSE
' BASIC PROGRAM METADATA
Dim Shared m_ProgramPath$: m_ProgramPath$ = Left$(Command$(0), _InStrRev(Command$(0), "\"))
Dim Shared m_ProgramName$: m_ProgramName$ = Mid$(Command$(0), _InStrRev(Command$(0), "\") + 1)
' LOCAL VARIABLES
Dim lngUpSound As Long
Dim lngDownSound As Long
Dim lngLeftSound As Long
Dim lngRightSound As Long
Dim lngEndSound As Long
Dim iPowerLevel As Integer
Dim iOldPowerLevel As Integer
Dim bUpdate As Integer
Dim bUp As Integer
Dim bDown As Integer
Dim bLeft As Integer
Dim bRight As Integer
Dim iWarningCount As Long
Dim bDoCount As Integer
Dim sngVolume As Single
Dim bPowerChanged As Integer
Dim in$
Dim sError As String: sError = ""
' LOAD SOUNDS
lngUpSound = _SndOpen(m_ProgramPath$ + "lunar_thrust1.wav")
lngDownSound = _SndOpen(m_ProgramPath$ + "lunar_alarm2.wav")
lngLeftSound = _SndOpen(m_ProgramPath$ + "lunar_alarm1.wav")
lngRightSound = _SndOpen(m_ProgramPath$ + "lunar_beep1.wav")
lngEndSound = _SndOpen(m_ProgramPath$ + "lunar_explode1.wav")
' ARE SOUNDS LOADED?
If lngUpSound = 0 Then sError = sError + "lngUpSound=0" + Chr$(13)
If lngDownSound = 0 Then sError = sError + "lngDownSound=0" + Chr$(13)
If lngLeftSound = 0 Then sError = sError + "lngLeftSound=0" + Chr$(13)
If lngRightSound = 0 Then sError = sError + "lngRightSound=0" + Chr$(13)
If lngEndSound = 0 Then sError = sError + "lngEndSound=0" + Chr$(13)
If Len(sError) > 0 Then Cls: Print sError: Input "PRESS ENTER TO EXIT"; in$: End
' INITIALIZE
bUpdate = TRUE
iPowerLevel = 1
iOldPowerLevel = 1
bUp = FALSE
bDown = FALSE
bLeft = FALSE
bRight = FALSE
iWarningCount = 100
sngVolume = GetVolumePercent!(iPowerLevel)
bPowerChanged = TRUE
bDoCount = FALSE
' MAIN LOOP
Do
' SHOW CHANGES ON SCREEN
If bUpdate = TRUE Then
Cls
Print "SOUND EFFECTS TEST HARNESS"
Print "-------------------------------------------------------------------------------"
Print "PRESS 1-7 TO CHANGE POWER (ENGINE VOLUME):"
Print "iPowerLevel =" + cstr$(iPowerLevel)
Print "sngVolume =" + _Trim$(Str$(sngVolume))
Print
Print "UP ACTIVATES ENGINE:"
Print "bUp =" + TrueFalse$(bUp)
Print
Print "DOWN STARTS COUNTDOWN TO SELF-DESTRUCT:"
Print "bDown =" + TrueFalse$(bDown)
Print
Print "LEFT ACTIVATES ALARM #1:"
Print "bLeft =" + TrueFalse$(bLeft)
Print
Print "RIGHT ACTIVATES ALARM #2:"
Print "bRight =" + TrueFalse$(bRight)
Print
Print "SELF-DESTRUCT TIMER:"
Print "iWarningCount=" + cstr$(iWarningCount) + IIFSTR$(bDoCount, " <- COUNTDOWN TO BOOM!", "")
Print
Print "PRESS ESC TO QUIT"
bUpdate = FALSE
End If
While _DeviceInput(1): Wend ' clear and update the keyboard buffer
If _Button(KeyCode_1%) Then
iPowerLevel = 1
ElseIf _Button(KeyCode_2%) Then
iPowerLevel = 2
ElseIf _Button(KeyCode_3%) Then
iPowerLevel = 3
ElseIf _Button(KeyCode_4%) Then
iPowerLevel = 4
ElseIf _Button(KeyCode_5%) Then
iPowerLevel = 5
ElseIf _Button(KeyCode_6%) Then
iPowerLevel = 6
ElseIf _Button(KeyCode_7%) Then
iPowerLevel = 7
End If
If iPowerLevel <> iOldPowerLevel Then
bPowerChanged = TRUE
bUpdate = TRUE
iOldPowerLevel = iPowerLevel
sngVolume = GetVolumePercent!(iPowerLevel)
End If
If _Button(KeyCode_Up%) Then
If bUp = FALSE Then bUpdate = TRUE
bUp = TRUE
Else
If bUp = TRUE Then bUpdate = TRUE
bUp = FALSE
End If
If _Button(KeyCode_Down%) Then
If bDown = FALSE Then bUpdate = TRUE
bDown = TRUE
Else
If bDown = TRUE Then bUpdate = TRUE
bDown = FALSE
End If
If _Button(KeyCode_Left%) Then
If bLeft = FALSE Then bUpdate = TRUE
bLeft = TRUE
Else
If bLeft = TRUE Then bUpdate = TRUE
bLeft = FALSE
End If
If _Button(KeyCode_Right%) Then
If bRight = FALSE Then bUpdate = TRUE
bRight = TRUE
Else
If bRight = TRUE Then bUpdate = TRUE
bRight = FALSE
End If
If _Button(KeyCode_Escape%) Then
Exit Do
End If
' START/STOP SOUNDS AND SET VOLUME
If bUp = TRUE Then
If lngUpSound <> 0 Then
If bPowerChanged = TRUE Then _SndVol lngUpSound, sngVolume
If _SndPlaying(lngUpSound) = FALSE Then _SndLoop lngUpSound '_SNDPLAY lngUpSound
End If
Else
If lngUpSound <> 0 Then
If _SndPlaying(lngUpSound) = TRUE Then _SndStop lngUpSound
End If
End If
If bDown = TRUE Then
If bDoCount = FALSE Then
If lngDownSound <> 0 Then
bDoCount = TRUE
iWarningCount = 100
If _SndPlaying(lngDownSound) = FALSE Then _SndLoop lngDownSound '_SNDPLAY lngDownSound
End If
End If
End If
' LEFT
If bLeft = TRUE Then
If lngLeftSound <> 0 Then
If _SndPlaying(lngLeftSound) = FALSE Then _SndLoop lngLeftSound '_SNDPLAY lngUpSound
End If
Else
If lngLeftSound <> 0 Then
If _SndPlaying(lngLeftSound) = TRUE Then _SndStop lngLeftSound
End If
End If
' RIGHT
If bRight = TRUE Then
If lngRightSound <> 0 Then
If _SndPlaying(lngRightSound) = FALSE Then _SndLoop lngRightSound '_SNDPLAY lngUpSound
End If
Else
If lngRightSound <> 0 Then
If _SndPlaying(lngRightSound) = TRUE Then _SndStop lngRightSound
End If
End If
' COUNTDOWN WITH WARNING
If bDoCount = TRUE Then
bUpdate = TRUE
iWarningCount = iWarningCount - 1
If iWarningCount < 1 Then
' STOP ALL SOUNDS
If lngUpSound <> 0 Then
If _SndPlaying(lngUpSound) = TRUE Then _SndStop lngUpSound
End If
If lngDownSound <> 0 Then
If _SndPlaying(lngDownSound) = TRUE Then _SndStop lngDownSound
End If
If lngLeftSound <> 0 Then
If _SndPlaying(lngLeftSound) = TRUE Then _SndStop lngLeftSound
End If
If lngRightSound <> 0 Then
If _SndPlaying(lngRightSound) = TRUE Then _SndStop lngRightSound
End If
'' WAIT A SECOND
'_Delay 1
' SHOW MESSAGE
Cls
Print "BOOM!"
' PLAY FINAL SOUND
If lngEndSound <> 0 Then
If _SndPlaying(lngEndSound) = TRUE Then _SndStop lngEndSound
_SndPlay lngEndSound
End If
bDoCount = FALSE
' PROMPT TO CONTINUE
Input "PRESS ENTER TO CONTINUE"; in$
End If
End If
_Limit 30
Loop
_SndClose lngUpSound
_SndClose lngDownSound
_SndClose lngLeftSound
_SndClose lngEndSound
_SndClose lngRightSound
Function GetVolumePercent! (iPowerLevel As Integer)
GetVolumePercent! = iPowerLevel / 7
End Function
Function cstr$ (myValue)
'cstr$ = LTRIM$(RTRIM$(STR$(myValue)))
cstr$ = _Trim$(Str$(myValue))
End Function ' cstr$
Function IIFSTR$ (Condition, IfTrue$, IfFalse$)
If Condition Then IIFSTR$ = IfTrue$ Else IIFSTR$ = IfFalse$
End Function
Function TrueFalse$ (myValue)
If myValue = TRUE Then
TrueFalse$ = "TRUE"
Else
TrueFalse$ = "FALSE"
End If
End Function ' TrueFalse$
' ################################################################################################################################################################
' BEGIN KEYBOARD _BUTTON CODE FUNCTIONS
' ################################################################################################################################################################
Function KeyCode_Escape% ()
KeyCode_Escape% = 2
End Function
Function KeyCode_1% ()
KeyCode_1% = 3
End Function
Function KeyCode_2% ()
KeyCode_2% = 4
End Function
Function KeyCode_3% ()
KeyCode_3% = 5
End Function
Function KeyCode_4% ()
KeyCode_4% = 6
End Function
Function KeyCode_5% ()
KeyCode_5% = 7
End Function
Function KeyCode_6% ()
KeyCode_6% = 8
End Function
Function KeyCode_7% ()
KeyCode_7% = 9
End Function
Function KeyCode_8% ()
KeyCode_8% = 10
End Function
Function KeyCode_9% ()
KeyCode_9% = 11
End Function
Function KeyCode_0% ()
KeyCode_0% = 12
End Function
Function KeyCode_Up% ()
KeyCode_Up% = 329
End Function
Function KeyCode_Left% ()
KeyCode_Left% = 332
End Function
Function KeyCode_Down% ()
KeyCode_Down% = 337
End Function
Function KeyCode_Right% ()
KeyCode_Right% = 334
End Function
' ################################################################################################################################################################
' END KEYBOARD _BUTTON CODE FUNCTIONS
' ################################################################################################################################################################