Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Valentine's Beating Heart
#11
I will have to admit...

I *SUCK* at SNDRAW and am basically just tossing stuff at it and hoping it sticks.

I has no idea how to make a true THUMP-THUMP  or BA-DUMP sound.   So... The last one sounded like something you might hear on a hospital monitor or such, and so I just went with it.

Anybody got any nice pointers for how the heck to make various sounds and put them together with _SNDRAW?  I'm almost clueless when it comes to the new sound commands and just... toss poo until I get a "PLOP" or "PLIP" of "ZZZZTTT" or whatever.  LOL!
Reply
#12
and here is my update with a few old tricks
Code: (Select All)

Screen _NewImage(800, 600, 32): _ScreenMove 270, 60
_Title "bplus mod of Steves Code Inspired by bplus #2"

Const TWO_PI = 6.283185307
Const max = 100
Dim Shared Particles(1 To 300) As Particle
Dim Shared cN, pR, pG, pB ' color palette

Type Particle
    x As Single
    y As Single
    dx As Single
    dy As Single
    life As Single
    sz As Single
    col As _Unsigned Long
End Type

'-----------------------------------------
' Main loop
'-----------------------------------------
Dim t As Single, beat As Integer
Dim scale As Single
Do
    Line (0, 0)-(_Width, _Height), &H11000000, BF
    t = t + .05
    UpdateParticles 1, max / 2

    scale = 8 + Sin(t) * 1.5
    DrawHeartFill 400, 300, scale, _RGB32(255, 0, 0)

    ' Beat detection
    If Sin(t) > .95 And beat = 0 Then
        ResetPal
        Burst 400, 300
        beat = 1
    End If
    If Sin(t) < .5 Then beat = 0

    UpdateParticles max / 2 + 1, max

    _Display
    _Limit 30
Loop

'-----------------------------------------
' Draw a parametric heart at scale S
'-----------------------------------------
Sub DrawHeart (cx As Single, cy As Single, s As Single, col As _Unsigned Long)
    Dim t As Single, x As Single, y As Single
    For t = 0 To TWO_PI Step .01
        x = 16 * Sin(t) ^ 3
        y = -(13 * Cos(t) - 5 * Cos(2 * t) - 2 * Cos(3 * t) - Cos(4 * t))
        PSet (cx + x * s, cy + y * s), col
    Next
End Sub

Sub DrawHeartFill (cx As Single, cy As Single, s As Single, col As _Unsigned Long)
    Dim t As Single, x As Single, y As Single
    For t = 0 To TWO_PI Step .01
        x = 16 * Sin(t) ^ 3
        y = -(13 * Cos(t) - 5 * Cos(2 * t) - 2 * Cos(3 * t) - Cos(4 * t))
        If t <> 0 Then Line (cx + x * s, cy + y * s)-(cx + lx * s, cy + s * ly), col
        lx = x: ly = y
    Next
    Paint (cx, cy), col, col
End Sub

'-----------------------------------------
' Spawn particle burst
'-----------------------------------------
Sub Burst (cx As Single, cy As Single)
    Dim i As Integer
    For i = 1 To 150
        Particles(i).x = cx
        Particles(i).y = cy
        Dim a As Single
        a = Rnd * TWO_PI
        r = Rnd * 7 + 2
        Particles(i).dx = r * Cos(a)
        Particles(i).dy = r * Sin(a)
        Particles(i).life = 1
        Particles(i).col = Pal~&
        Particles(i).sz = Rnd * 3 + .5
    Next
End Sub

'-----------------------------------------
' Update and draw particles
'-----------------------------------------
Sub UpdateParticles (istart, iend)
    Dim i As Integer
    For i = istart To iend
        If Particles(i).life > 0 Then
            Particles(i).x = Particles(i).x + Particles(i).dx
            Particles(i).y = Particles(i).y + Particles(i).dy
            Particles(i).life = Particles(i).life - .01
            Particles(i).sz = Abs(Particles(i).sz - .02)
            Dim a As Integer
            a = 255 * Particles(i).life
            DrawHeartFill Particles(i).x, Particles(i).y, Rnd * Particles(i).sz, Particles(i).col
        End If
    Next
End Sub

Function Pal~& ()
    cN = cN + .369 ''Dim Shared cN, pR, pG, pB, pA ' no pA
    Pal~& = _RGB32(127 + 127 * Sin(pR * cN), 127 + 127 * Sin(pG * cN), 127 + 127 * Sin(pB * cN))
End Function

Sub ResetPal ()
    ''Dim Shared CN, PR, PG, PB, PA ' no PA
    pR = Rnd ^ 2: pG = Rnd ^ 2: pB = Rnd ^ 2: cN = 0
End Sub

Smile if you dont like the palette just wait for next beat !

EDIT: 2026-02-16 Fixed dx, dy on the particle burst.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#13
(02-15-2026, 11:13 PM)SMcNeill Wrote: I will have to admit...

I *SUCK* at SNDRAW and am basically just tossing stuff at it and hoping it sticks.

I has no idea how to make a true THUMP-THUMP  or BA-DUMP sound.   So... The last one sounded like something you might hear on a hospital monitor or such, and so I just went with it.

Anybody got any nice pointers for how the heck to make various sounds and put them together with _SNDRAW?  I'm almost clueless when it comes to the new sound commands and just... toss poo until I get a "PLOP" or "PLIP" of "ZZZZTTT" or whatever.  LOL!

Steal ahenry3068's: https://qb64phoenix.com/forum/showthread...7#pid39927
It's pretty good!

BTW that glitch version IS Interesting!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#14
(02-15-2026, 11:13 PM)SMcNeill Wrote: I will have to admit...

I *SUCK* at SNDRAW and am basically just tossing stuff at it and hoping it sticks.

I has no idea how to make a true THUMP-THUMP  or BA-DUMP sound.   So... The last one sounded like something you might hear on a hospital monitor or such, and so I just went with it.

Anybody got any nice pointers for how the heck to make various sounds and put them together with _SNDRAW?  I'm almost clueless when it comes to the new sound commands and just... toss poo until I get a "PLOP" or "PLIP" of "ZZZZTTT" or whatever.  LOL!
   I just embed 8 bit PCM samples then upsample them to send to SNDRAW.   (8 bit to save space !) 

Look at my Video Library !   I use _SNDRAW in that to play back the PCM sound track from the files.  Those are stored as either 8 bit or 16 bit signed PCM.   (_sndraw takes signed FLOAT but it's an easy conversion ) You can create 8 bit PCM raw samples with Audacity or ffmpeg or other !
Reply
#15
Hi boyz and girlz
here my Saint Valentine's game

point and click and collect all hearts...
It should sound BadApple but in this moment my OS has decided to be not compatible with MIDI files...(Lucky TempodiBasic)
so I should reinstall VLC with the correct plugins...but another day now it is time to rest.


.zip   SaintValentineGame_.zip (Size: 55.08 KB / Downloads: 4)
Reply
#16
(02-16-2026, 12:57 AM)TempodiBasic Wrote: Hi boyz and girlz
here my Saint Valentine's game

point and click and collect all hearts...
It should sound BadApple but in this moment my OS has decided to be not compatible with MIDI files...(Lucky TempodiBasic)
so I should reinstall VLC with the correct plugins...but another day now it is time to rest.

  You didn't DIM SHARED The Music variable !    MIDI worked fine after I did that !

 But this attachment sounds better Smile Smile


Attached Files
.ogg   badapple.ogg (Size: 4.25 MB / Downloads: 3)
Reply
#17
Edit: fixed dx, dy in Particle bursts here
https://qb64phoenix.com/forum/showthread...6#pid39946

Took me awhile to find what was screwy looking in those bursts. Something Sprezzo warned about long ago:
Code: (Select All)
        Particles(i).dx = Cos(a) * (Rnd * 4)
        Particles(i).dy = Sin(a) * (Rnd * 4)
No!

dx = sameValue*cos(sameAngle)
dy = sameValue*sin(sameAngle)
Yes!

This is what happens when you steal code for mods, you have to discover the mistakes in it. Smile
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#18
Yep, using a different random for dx & dy was never going to work properly.  It's amazing how one can make the simplest mistakes.  Often when I've gone through very old code of mine I come across dumb errors like that.  The human brain with all its trillions of neural connections very capable of producing gibberish.
Reply
#19
@ahenry3068
that .ogg is quiet better,but I cannot say how muche because I'm not able to play MIDI files in Kubuntu...I must install by terminal or downloading and then opening with Discover (app central of Kubuntu) for installing....
I've got  vlc-plugin-fluidsync_3 and fluidsoundfont_gm_3, now I'm adding Timidity_2.14 
I hope that these addons are the solution... in the while my Discover doesn't accept other URL for adding more repositories to Discover, and from a mounth (it started with an adjournment of Discord app) Discover runs weird. Some application stuck as I launch them from laucher application menu, some others stuck in the first minute of working. And when I install another application I got the message Package failed to install  (copy in the clipboard)...but then it runs quiet good
so I am ready to learn another lesson about Linux Universe and its force.

That is the why I didn't recognize that I miss to share the handle of music file!
Thanks for trying it and for sharing a better music file.
Reply
#20
(02-16-2026, 12:09 AM)ahenry3068 Wrote:
(02-15-2026, 11:13 PM)SMcNeill Wrote: I will have to admit...

I *SUCK* at SNDRAW and am basically just tossing stuff at it and hoping it sticks.

I has no idea how to make a true THUMP-THUMP  or BA-DUMP sound.   So... The last one sounded like something you might hear on a hospital monitor or such, and so I just went with it.

Anybody got any nice pointers for how the heck to make various sounds and put them together with _SNDRAW?  I'm almost clueless when it comes to the new sound commands and just... toss poo until I get a "PLOP" or "PLIP" of "ZZZZTTT" or whatever.  LOL!
   I just embed 8 bit PCM samples then upsample them to send to SNDRAW.   (8 bit to save space !) 

Look at my Video Library !   I use _SNDRAW in that to play back the PCM sound track from the files.  Those are stored as either 8 bit or 16 bit signed PCM.   (_sndraw takes signed FLOAT but it's an easy conversion )    You can create 8 bit PCM raw samples with Audacity or ffmpeg or other !
You don't need any third party software to create audio samples from all music files supported by _SndOpen. Use _MemSound and detect the correct data type. For example, 16bit WAV PCM returns integer. Interleaved samples. MP3 returns Single interleaved samples. 8Bit WAV PCM returns _Unsigned _Byte interleaved samples (I think) I'm not sure about the others. You can find out how to do it in the sound programs in my thread.

As for creating audio as such just using arrays and math... yeah, that's high school math. The range must be from -1 to 1 (for compatibility with _SndRaw), the data type Single (is enough) and then experiment with Sin, Cos, loop interleaving, use different nested functions... that's the game. Such a blind shooting. But sometimes you're amazed at what comes out of it Smile )


Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)