Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Phoenix Edition v3.1 released!
#16
I made a test with the code of SierraKen below which reads an mp3 audio file with animation. the quality of the sound is better with the version 3.0.0 of qb64. to note that the animation disappears with the version 3.1.0...

Code: (Select All)
'Tesla Coil by SierraKen - September 1, 2022.
'Tesla Coil will shoot lightning to your music like a real one.
'Make sure and put a song file in the same folder as this program.
'Thank you for the frequency example at the QB64 Wiki Help Page https://qb64phoenix.com/qb64wiki/index.php/MEMSOUND

_Title "Tesla Coil by SierraKen"
Screen _NewImage(800, 600, 32)

start:
Clear
Cls
Dim file$
Input "Song Filename Here: ", file$

DefLng A-Z
Option _Explicit
Option _ExplicitArray
Dim bolts As Single, bolts2 As Single, t As Single
Dim a$
Print "Loading...";
Dim Song As Long
Song = _SndOpen(file$) ' Replace this with your (rad, mid, it, xm, s3m, mod, mp3, flac, ogg, wav) sound file
If Song < 1 Then
    Print "Failed to load song!"
    End
End If
Print "Done!"
_Display
_SndPlay Song

Dim SampleData As _MEM
SampleData = _MemSound(Song, 1) ' This can now be 0 or 1
If SampleData.SIZE = 0 Then
    Print "Failed to access sound sample data."
    End
End If

Dim y As Long, i As _Unsigned _Integer64, sf As Single, si As Integer
Dim sz As _Unsigned _Integer64

sz = _CV(_Unsigned _Integer64, _MK$(_Offset, SampleData.ELEMENTSIZE)) ' sz is the total size of the sound in bytes

Do Until Not _SndPlaying(Song) Or i + (_Width * sz) > SampleData.SIZE
    a$ = InKey$
    If a$ = Chr$(27) Then _SndClose Song: End
    Cls
    Locate 1, 1: Print i; "/"; SampleData.SIZE, "Frame Size ="; sz, "Data Type ="; SampleData.TYPE
    Line (0, 500)-(800, 500), _RGB32(127, 255, 127)
    Line (400, 350)-(400, 500), _RGB32(255, 0, 0)

    $Checking:Off
    If (sz = 4 Or sz = 2) And SampleData.TYPE = 1 Then ' integer stereo or mono
        For y = 0 To _Width - 1
            si = _MemGet(SampleData, SampleData.OFFSET + i + y * sz, Integer) 'get sound data
            If 300 * si / 32768 = 0 Then GoTo skip:

            For bolts2 = 1 To 3
                For bolts = 1 To t
                    Line (400, 350)-(400 + 300 * si / 32768, (y / 2) + 200), _RGB32(255, 255, 255)
                Next bolts
                t = t + 2
            Next bolts2
            t = 0

        Next
    ElseIf (sz = 8 Or sz = 4) And SampleData.TYPE = 4 Then ' floating point stereo or mono
        For y = 0 To _Width - 1
            sf = _MemGet(SampleData, SampleData.OFFSET + i + y * sz, Single) 'get sound data
            If sf * 300 = 0 Then GoTo skip:
            For bolts2 = 1 To 3
                For bolts = 1 To t
                    Line (400, 350)-(400 + sf * 300, (y / 2) + 200), _RGB32(255, 0, 0)
                Next bolts
                t = t + 2
            Next bolts2
            t = 0
        Next
    ElseIf sz = 2 And SampleData.TYPE = 0 Then ' integer mono (QB64 OpenAL stuff)
        For y = 0 To _Width - 1
            si = _MemGet(SampleData, SampleData.OFFSET + i + y * sz, Integer) 'get sound data
            If 300 * si / 32768 = 0 Then GoTo skip:
            For bolts2 = 1 To 3
                For bolts = 1 To t
                    Line (400, 350)-(400 + 300 * si / 32768, (y / 2) + 200), _RGB32(255, 255, 255)
                Next bolts
                t = t + 2
            Next bolts2
            t = 0
        Next
    End If
    skip:

    $Checking:On

    _Display
    _Limit 60

    i = Fix(_SndGetPos(Song) * _SndRate) * sz ' Calculate the new sample frame position
Loop

_SndClose Song 'closing the sound releases the mem blocks
_AutoDisplay
GoTo start:
Reply


Messages In This Thread
Phoenix Edition v3.1 released! - by SMcNeill - 09-04-2022, 02:46 AM
RE: Phoenix Edition v3.1 released! - by SMcNeill - 09-04-2022, 03:26 AM
RE: Phoenix Edition v3.1 released! - by bplus - 09-04-2022, 04:59 PM
RE: Phoenix Edition v3.1 released! - by OldMoses - 09-04-2022, 05:53 PM
RE: Phoenix Edition v3.1 released! - by bplus - 09-04-2022, 06:59 PM
RE: Phoenix Edition v3.1 released! - by SMcNeill - 09-04-2022, 08:31 PM
RE: Phoenix Edition v3.1 released! - by OldMoses - 09-05-2022, 01:32 AM
RE: Phoenix Edition v3.1 released! - by Stuart - 09-04-2022, 06:18 PM
RE: Phoenix Edition v3.1 released! - by Coolman - 09-04-2022, 06:28 PM
RE: Phoenix Edition v3.1 released! - by Stuart - 09-05-2022, 12:19 AM
RE: Phoenix Edition v3.1 released! - by Coolman - 09-05-2022, 10:45 AM
RE: Phoenix Edition v3.1 released! - by Gets - 09-05-2022, 01:31 AM
RE: Phoenix Edition v3.1 released! - by SMcNeill - 09-05-2022, 02:05 AM
RE: Phoenix Edition v3.1 released! - by Coolman - 09-05-2022, 02:02 PM
RE: Phoenix Edition v3.1 released! - by OldMoses - 09-05-2022, 03:19 PM
RE: Phoenix Edition v3.1 released! - by SMcNeill - 09-05-2022, 04:13 PM
RE: Phoenix Edition v3.1 released! - by a740g - 09-05-2022, 04:44 PM
RE: Phoenix Edition v3.1 released! - by Ikerkaz - 09-05-2022, 02:08 PM
RE: Phoenix Edition v3.1 released! - by Coolman - 09-05-2022, 06:09 PM
RE: Phoenix Edition v3.1 released! - by SMcNeill - 09-05-2022, 06:29 PM
RE: Phoenix Edition v3.1 released! - by SMcNeill - 09-05-2022, 11:25 PM
RE: Phoenix Edition v3.1 released! - by SMcNeill - 09-06-2022, 08:37 PM
RE: Phoenix Edition v3.1 released! - by mnrvovrfc - 09-08-2022, 03:54 AM
RE: Phoenix Edition v3.1 released! - by bert22306 - 09-05-2022, 10:00 PM
RE: Phoenix Edition v3.1 released! - by Stuart - 09-06-2022, 01:38 AM
RE: Phoenix Edition v3.1 released! - by SMcNeill - 09-06-2022, 02:44 AM
RE: Phoenix Edition v3.1 released! - by Stuart - 09-06-2022, 05:24 PM
RE: Phoenix Edition v3.1 released! - by SMcNeill - 09-06-2022, 04:43 AM
RE: Phoenix Edition v3.1 released! - by Stuart - 09-06-2022, 05:49 PM
RE: Phoenix Edition v3.1 released! - by Gets - 09-07-2022, 04:01 PM
RE: Phoenix Edition v3.1 released! - by Stuart - 09-08-2022, 10:01 AM
RE: Phoenix Edition v3.1 released! - by a740g - 09-10-2022, 07:10 PM
RE: Phoenix Edition v3.1 released! - by Stuart - 09-10-2022, 11:26 PM



Users browsing this thread: 11 Guest(s)