My Lunar Lander bloatware! (ver 0.33)
#7
(07-20-2022, 06:47 PM)SierraKen Wrote: Here is one of my simple clocks using Dav's chimes. The chimes section is towards the bottom. When you run it, press the Space Bar to hear the chimes anytime. They also play at the top of the hour.

Thanks! The fade out that eliminates the clicks after the sound is helpful. 

I see the comment "do other stuff, but it may interrupt sound" which leads to my next question - 
if it's a sound effect for a game, where we're constantly redrawing the screen, reading the keyboard for input, and making calculations, 
the sound effects need to be asynchronous. How do we get it to NOT interrupt the sound? 
When the player lets go of the "thrust" button, the engine sound should stop immediately, without any clicks. 

Here's my test harness where I am playing with your "chimes" code: 
Code: (Select All)
' SierraKen
' Here is one of my simple clocks using Dav's chimes.
' The chimes section is towards the bottom.
' When you run it, press the Space Bar to hear the chimes anytime.
' They also play at the top of the hour.

' https://staging.qb64phoenix.com/showthread.php?tid=654&pid=4228#pid4228

_Title "Chimes #1"

' BOOLEAN CONSTANTS
Const FALSE = 0
Const TRUE = Not FALSE

Dim HZ&
Dim iCount%
Dim iIncrement&
Dim iDirection&
Dim iMinHZ&
Dim iMaxHZ&
Dim bQuit%

iCount% = 0
iMinHZ& = 1
iMaxHZ& = 20000
iMinInc& = 1
iMaxInc& = 16384
iIncrement& = 40
iDirection& = 1
HZ& = iMinHZ& ' start at 128 Hz
'HZ& = 340 ' 340Hz
bQuit% = FALSE

_Limit 500
Do
    iCount% = iCount% + 1
    HZ& = HZ& + (iIncrement& * iDirection&)
    ttt = 0
    Cls
    Print "_SndRaw experiment based on Clock by SierraKen"
    Print
    Print "Chime #" + _Trim$(Str$(iCount%))
    Print
    Print "Frequency = " + _Trim$(Str$(HZ&)) + " Hz"
    Print "Increment = " + _Trim$(Str$((iIncrement& * iDirection&))) + " Hz"
    Print "Min freq  = " + _Trim$(Str$(iMinHZ&)) + " Hz"
    Print "Max freq  = " + _Trim$(Str$(iMaxHZ&)) + " Hz"
    Print
    Print "Press 1 to decrease frequency increment by 5."
    Print "Press 2 to increase " + Chr$(34) + " " + Chr$(34)
    Print
    Print "Press Esc to quit."

    Do
        GoSub GetInput

        ' queue some sound
        Do While _SndRawLen < 0.1 ' you may wish to adjust this
            sample = Sin(ttt * HZ& * Atn(1) * 8) ' HZ% HZ sine wave (ttt * 440 * 2p)
            sample = sample * Exp(-ttt * 3) ' fade out eliminates clicks after sound
            _SndRaw sample
            ttt = ttt + 1 / _SndRate ' sound card sample frequency determines time
        Loop
        ' do other stuff, but it may interrupt sound
    Loop While ttt < 2 ' play for 2 seconds

    Do While _SndRawLen > 0 ' Finish any left over queued sound!
        GoSub GetInput
    Loop

    If HZ& < iMinHZ& Or HZ& > iMaxHZ& Then
        iDirection& = iDirection& * -1
    End If

    _KeyClear: '_DELAY 1
    If bQuit% = TRUE Then Exit Do
Loop
End

GetInput:
sKey$ = InKey$
If sKey$ = Chr$(27) Then
    bQuit% = TRUE
ElseIf sKey$ = "1" Then
    iIncrement& = iIncrement& - 5: If iIncrement& < iMinInc& Then iIncrement& = iMinInc&
ElseIf sKey$ = "2" Then
    iIncrement& = iIncrement& + 5: If iIncrement& > iMaxInc& Then iIncrement& = iMaxInc&
End If
Return

' /////////////////////////////////////////////////////////////////////////////

Sub PrintAt (iRow%, iCol%, sText$)
    '_PrintString (iCol% * 8, iRow% * 16), sText$
    _PrintString (iCol% * 8, iRow% * 16), sText$
    '_PrintString (iCol%, iRow%), sText$
End Sub ' PrintAt
Reply


Messages In This Thread
RE: My Lunar Lander bloatware! (ver 0.33) - by madscijr - 07-21-2022, 06:16 PM



Users browsing this thread: 2 Guest(s)