Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Phoenix Edition v3.1 released!
#11
I'm still using version 1.5 because I didn't want to rewrite all of my functions, but the audio backend being replaced is reason enough to finally upgrade. I've only ran one test and it's finishing in 1/3 of the time it took on 1.5, so I'm happy with the performance so far.
Reply
#12
(09-04-2022, 06:59 PM)bplus Wrote:
(09-04-2022, 05:53 PM)OldMoses Wrote:
(09-04-2022, 04:59 PM)bplus Wrote: Wow nice list of improvements. What is difference between shift left / right and rotate left /right?

shifts will drop bits from the end shifted toward. Rotate will carry those bits around to the opposite end.

Thanks, OK left and right shifts mult or divide by 2, what does rotate do?

I can recall, from back in the days when I attempted to fool with Assembly, that most CPU's had ROL & ROR in their instruction set. Also known as 'circular shifting' or 'rotate no carry'. However, I can't recall ever using it. The mathematics of doing it is pretty squirrely, and I can't for the life of me think of a mathematical application. I can't find much on the net about it, other than what it is. I found a mention on wikipedia that it is used frequently in cryptography. Not surprising given the arcane nature of that pursuit. I can imagine a simple encryption scheme of using a key array to rotate character bytes in certain order, to scramble them up and then reversing the order to unscramble them, but I'm sure its use is far more sophisticated than my kindergarden encryption ideas.

A lot of languages don't have native support for circular shifting, requiring the writing of appropriate functions, so now QB64PE has something to distinguish it from the rest of the rabble. Perhaps someone can discuss why it was added.

You can rotate 0 & -1 in either direction until the cows fly in to roost and they will remain 0 & -1, respectively.

It will act very much like _SHL & _SHR until a set bit crosses the MSB/LSB boundary and signs will flip (unless you're working with unsigned variables) and all sorts of weird fun commences.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply
#13
@OldMoses The math isn't as complex as you think. Let's take 10000001 as an example.

To rotate left once:
Shift the bits left once, store the result: 00000010
Take the original, shift the bits right 7 times, store the result: 00000001

OR those results:
00000010
00000001 (OR)
==========
00000011

And that's the general idea behind it. Wink

I've personally never needed it either, but other folks did and they requested it from us. Since it was easy enough to implement (as illustrated in the example above), we went ahead and added it into the language for everyone to be able to use and enjoy.

Now, let's hope somebody out there can show us some amazing uses for it!
Reply
#14
(09-05-2022, 12:19 AM)Stuart Wrote:
(09-04-2022, 06:28 PM)Coolman Wrote: miniaudio seems to be statically linked to the executable. i tested with a code. the size of the program generated by version 3.0.0 is about 2,8 mo while the one generated by version 3.1.0 is about 3.1 mo. that said the executable won't have any dependency on it. that's good. thank you for integrating the -no-pie option. the other additions and modifications seem interesting. great job.

I didn't test with v3.0.0, but the "old audio backend (LPGL)" wasn't changed until v3.1.0; and I can verify that it's what's slowing me down because when I choose to use the older, original backend I regain the lost 5% of time.  It might even be a fraction of a percent faster.

When the option to "Use the old audio backend (LPGL)" is turned on in the Compiler Options the .exe size is now 2168 KB which is 65 KB smaller than when the new backend for audio is used (but it's still 3KB larger than the 0.8.2 version -- which is probably due to the other fixes and enhancements).

I hope that this slow down can be fixed somehow because the program I have uses very short sounds for sound events, but if it ends up costing me 5% of speed loss then the sounds will have to go and not even be available as an option...

Thanks a lot for your response @Coolman -- it did lead me in the right direction of what to check for next.

hi @Stuart. i didn't feel any slowdown in version 3.1.0 of qb64 for the sound but i didn't do a thorough test. that said qb64 has been fully compiled with the -O3 option by modifying the makefile. it would be necessary to do other tests because a difference of 5% is too important and may impact many programs...
Reply
#15
(09-05-2022, 01:32 AM)OldMoses Wrote: I can recall, from back in the days when I attempted to fool with Assembly, that most CPU's had ROL & ROR in their instruction set. Also known as 'circular shifting' or 'rotate no carry'. However, I can't recall ever using it. The mathematics of doing it is pretty squirrely, and I can't for the life of me think of a mathematical application.
Rotates are used in combination with shifts when you want to shift say a 16 bit number that is contained in two bytes. Shift left the LS byte and the left most bit get pushed out into the carry bit. Then rotate left the MS byte and that pulls the carry bit into the right most position of the MS byte. The left most bit of the MS byte is pushed out into the carry bit. So basically shift doesn't pull the (possibly unknown) carry bit into the byte. Dunno how the carry bit is with BASIC, but that's how it generally works with micros using assembly anyway.
Reply
#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
#17
Hi, I am compiling a program and Windows Security is detecting that my program is a virus ??????

Trojan:Win32/Wacatac.H!ml

I am developing a game, and it worked fine in old QB64. Yesterday I downloaded v3.1 and I have changed several things (nothing important), and since 10 minutes the virus alert is rising Sad

Do you have any idea of what is happening?
Thank you!!!
IKZ
10 PRINT "Hola! Smile"
20 GOTO 10
Reply
#18
(09-05-2022, 02:02 PM)Coolman Wrote: 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...


I got the same result. Plays the sound but not the animation.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply
#19
(09-05-2022, 02:02 PM)Coolman Wrote: 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:


The problem here is two-fold.   

First, there's a glitch in the old OpenAL backend which always reports your audio as being TYPE 0, so it's *always* handled by the segment reading' integer mono (QB64 OpenAL stuff).  The new backend fixes that problem, and we now get stereo sound out of our speakers!  YAY!!

Which leads to the second issue -- a minor glitch in the original code:

Take a close look and look at these lines:

Code: (Select All)
If (sz = 4 Or sz = 2) And SampleData.TYPE = 1 Then ' integer stereo or mono
ElseIf (sz = 8 Or sz = 4) And SampleData.TYPE = 4 Then

Mem.TYPEs aren't one value; they're a collection of bits which make up that value.  
1, 2, 4,8, 16, 32 <-- these values are the size of your data type.  
128 <-- this value says that your data type is an integer.

For a _BYTE, it has a value of 129.  (size 1 flag for byte + 128 integer flag)
For a _LONG, it has a value of 132.  (size 4 flag for long + 128 integer flag)

These values aren't = 1 or = 4.  You check to see if they AND 128 (integer) or AND 256 (float)....


Code: (Select All)
If (sz = 4 Or sz = 2) And (SampleData.TYPE AND 128) Then ' integer stereo or mono
ElseIf (sz = 8 Or sz = 4) And (SampleData.TYPE AND 256) Then

Make the changes above so that you're ANDing the type, rather than EQUALing the type, and it plays just fine.

The problem here wasn't QB64 -- it was a minor glitch in the code which wasn't found because the previous version of QB64 was glitched and never triggered this issue in the past so it wasn't found and debugged.  Wink
Reply
#20
[attachment=824 Wrote:Coolman pid='6295' dateline='1662386558']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...

I made the changes in the download. Also see Example 1 and 2 in _MEMSOUND - QB64 Phoenix Edition Wiki


Attached Files
.bas   Tesla Coil by SierraKen.bas (Size: 3.35 KB / Downloads: 54)
Reply




Users browsing this thread: 1 Guest(s)