Posts: 733
Threads: 103
Joined: Apr 2022
Reputation:
14
09-12-2022, 12:12 PM
(This post was last modified: 09-12-2022, 12:14 PM by madscijr.)
(09-12-2022, 11:57 AM)TempodiBasic Wrote: PostScriptum:
you can find Gfortran.exe in the folder QB64\internal\c\c_compiler\bin
I think you can use it in association with Notepad++ with setting for fortran syntax.
FORTRAN!
I wonder if it will compile my programs from 10th grade computer class!
Posts: 733
Threads: 103
Joined: Apr 2022
Reputation:
14
(09-12-2022, 11:49 AM)TempodiBasic Wrote: and C++
Lol for many people C and C++ and C# are relatives... but do you remember the twins Arnold Schwarzenegger and Denny De Vito?
Just the same!
https://it.wikipedia.org/wiki/File:I_gem...Twins).jpg
Tempodi, Spriggsy converted the C to pure QB64 and it works! (Sort of!)
Now the next challenge is, how do we convert the event-driven code to normal QB64?
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
(09-08-2022, 03:01 AM)madscijr Wrote: (08-26-2022, 04:24 AM)JRace Wrote: That compilable source includes a batch file to automate compilation using QB64's bundled MinGW.
On the subject of MiniGW, I read that GCC can not only compile C and C++, but also Objective-C, Fortran, Ada, Go and D.
So can that batch file be tweaked to get it to build code from those languages, or is the MiniGW included with QB64 limited?
PS I also read "Versions prior to GCC 7 also supported Java, allowing compilation of Java to native machine code." Wow, I'm not a Java person, but it's neat to know that is (was?) possible.
The latest version is here: MinGW 12.2.0
If you also want the assembler: NASM 2.15.05
Quote:Have you tried it with the previous 2.x build of QB64 or an earlier one like 1.5?
No.
Posts: 734
Threads: 30
Joined: Apr 2022
Reputation:
43
09-12-2022, 02:00 PM
(This post was last modified: 09-12-2022, 05:26 PM by SpriggsySpriggs.)
Yo, @madscijr ... Does this help you with your WAV file stuff?
This version is a direct C translation:
Code: (Select All) Option Explicit
$NoPrefix
$Console:Only
Const WAVFILE_SAMPLES_PER_SECOND = 44100
Const SEEK_SET = 0
Type WAVFILE_HEADER
As String * 4 riff_tag
As Long riff_length
As String * 4 wave_tag, fmt_tag
As Long fmt_length
As Integer audio_format, num_channels
As Long sample_rate, byte_rate
As Integer block_align, bits_per_sample
As String * 4 data_tag
As Long data_length
End Type
Declare CustomType Library
Function fopen%& (filename As String, mode As String)
Sub fwrite (ByVal buffer As Offset, Byval size As Offset, Byval count As Offset, Byval stream As Offset)
Sub fflush (ByVal stream As Offset)
Function ftell& (ByVal stream As Offset)
Sub fseek (ByVal stream As Offset, Byval offset As Long, Byval origin As Long)
Sub fclose (ByVal stream As Offset)
End Declare
Const NUM_SAMPLES = WAVFILE_SAMPLES_PER_SECOND * 2
Dim As Integer waveform(0 To NUM_SAMPLES - 1)
Dim As Double frequency: frequency = 440.0
Dim As Long volume: volume = 32000
Dim As Long i
For i = 0 To NUM_SAMPLES - 1
Dim As Double t: t = i / WAVFILE_SAMPLES_PER_SECOND
waveform(i) = volume * Sin(frequency * t * 2 * Pi)
Next
Dim As Offset f: f = wavfile_open("sound.wav")
wavfile_write f, waveform(), NUM_SAMPLES
wavfile_close f
Function wavfile_open%& (filename As String)
Dim As WAVFILE_HEADER header
Dim As Long samples_per_second: samples_per_second = WAVFILE_SAMPLES_PER_SECOND
Dim As Long bits_per_sample: bits_per_sample = 16
header.riff_tag = "RIFF"
header.wave_tag = "WAVE"
header.fmt_tag = "fmt "
header.data_tag = "data"
header.riff_length = 0
header.fmt_length = 16
header.audio_format = 1
header.num_channels = 1
header.sample_rate = samples_per_second
header.byte_rate = samples_per_second * (bits_per_sample / 8)
header.block_align = bits_per_sample / 8
header.bits_per_sample = bits_per_sample
header.data_length = 0
Dim As Offset file: file = fopen(filename + Chr$(0), "wb+" + Chr$(0))
If file = 0 Then Exit Function
fwrite Offset(header), Len(header), 1, file
fflush file
wavfile_open = file
End Function
Sub wavfile_write (file As Offset, wav_data() As Integer, length As Long)
fwrite Offset(wav_data()), 2, length, file
End Sub
Sub wavfile_close (file As Offset)
Dim As Long file_length: file_length = ftell(file)
Dim As WAVFILE_HEADER header
Dim As Long data_length: data_length = file_length - Len(header)
fseek file, Len(header) - 4, SEEK_SET
fwrite Offset(data_length), Len(data_length), 1, file
Dim As Long riff_length: riff_length = file_length - 8
fseek file, 4, SEEK_SET
fwrite Offset(riff_length), Len(riff_length), 1, file
fclose file
End Sub
And because I know you like to have things done with QB64 code, here is a version that produces the exact same file but uses only built-in functions:
Code: (Select All) Option Explicit
$NoPrefix
$Console:Only
Const WAVFILE_SAMPLES_PER_SECOND = 44100
Type WAVFILE_HEADER
As String * 4 riff_tag
As Long riff_length
As String * 4 wave_tag, fmt_tag
As Long fmt_length
As Integer audio_format, num_channels
As Long sample_rate, byte_rate
As Integer block_align, bits_per_sample
As String * 4 data_tag
As Long data_length
End Type
Const NUM_SAMPLES = WAVFILE_SAMPLES_PER_SECOND * 2
Dim As Integer waveform(0 To NUM_SAMPLES - 1)
Dim As Double frequency: frequency = 440.0
Dim As Long volume: volume = 32000
Dim As Long i
For i = 0 To NUM_SAMPLES - 1
Dim As Double t: t = i / WAVFILE_SAMPLES_PER_SECOND
waveform(i) = volume * Sin(frequency * t * 2 * Pi)
Next
Dim As Long f: f = wavfile_open("sound.wav")
wavfile_write f, waveform()
wavfile_close f
Function wavfile_open& (filename As String)
Dim As WAVFILE_HEADER header
Dim As Long samples_per_second: samples_per_second = WAVFILE_SAMPLES_PER_SECOND
Dim As Long bits_per_sample: bits_per_sample = 16
header.riff_tag = "RIFF"
header.wave_tag = "WAVE"
header.fmt_tag = "fmt "
header.data_tag = "data"
header.riff_length = 0
header.fmt_length = 16
header.audio_format = 1
header.num_channels = 1
header.sample_rate = samples_per_second
header.byte_rate = samples_per_second * (bits_per_sample / 8)
header.block_align = bits_per_sample / 8
header.bits_per_sample = bits_per_sample
header.data_length = 0
If FileExists(filename) Then Kill filename
Dim As Long file: file = FreeFile
Open "B", file, filename
Put file, , header
wavfile_open = file
End Function
Sub wavfile_write (file As Long, wav_data() As Integer)
Put file, , wav_data()
End Sub
Sub wavfile_close (file As Long)
Dim As Long file_length: file_length = LOF(file)
Dim As WAVFILE_HEADER header
Dim As Long data_length: data_length = file_length - Len(header)
Put file, Len(header) - 3, data_length
Dim As Long riff_length: riff_length = file_length - 8
Put file, 5, riff_length
Close file
End Sub
P.S. I personally dislike the naming scheme and case used in the original code but chose to use the same style and names so that it would be easier for you to see the relation. I typically prefer Pascal case for everything that isn't a TYPE or CONSTANT declaration.
P.P.S I know that both code blocks produce the exact same file by doing a comparison in Notepad++. Also, both files play just fine in Windows. Had some issues at first with using strictly QB64 functions as I forgot that we use base 1 while C uses base 0.
Tread on those who tread on you
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
(09-12-2022, 12:32 PM)Kernelpanic Wrote: The latest version is here: MinGW 12.2.0
If you also want the assembler: NASM 2.15.05 Thank you for this link for MinGW. I had downloaded version 9 I think for 64-bit but couldn't do anything with it. But now I think the C/C++ compiler that comes with QB64 for Windows, or with a Linux distro is enough for me.
LOL "Universal" CRT? This must be a lot like "musl" for example on Void Linux, while a great many things are compatible with "libc" instead.
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
Learned something else: QB64 permits "DIM" statements inside a loop! I thought it was going to complain about "duplicate definition" for "t" although it's not an interpreter...
(09-04-2022, 08:21 PM)madscijr Wrote: If this is about reading the mouse, QB64 has its own way of reading the mouse. When in Rome...! (09-08-2022, 03:29 AM)madscijr Wrote: That makes sense. All we need is C, so... I'm trying to help on this topic, but I don't like some of your answers. It seems my knowledge is inferior to others here and therefore I'm the only one being replied to in this manner. This is my last post in this topic for this reason. I'm not a C/C++ programmer and I don't want to be. I like to help people, but if I keep getting this kind of replies then I might stop participating on this forum. Until now I have contained myself, tried to be laid back like the guys having way more reputation on this forum than me. But it cannot go without saying any longer.
"All we need is C" but I was going to reply "Without C++ you can't do anything with QB64 and what would you do then?" But I contained myself. I'm admitting it now because I like this place and the people in it. I'm not angry or anything but I'm not going to post on this topic any longer. >==>
Posts: 734
Threads: 30
Joined: Apr 2022
Reputation:
43
09-12-2022, 05:46 PM
(This post was last modified: 09-12-2022, 05:48 PM by SpriggsySpriggs.)
@mnrvovrfc
Sure, out of context those might seem impolite. Going back and reading the posts, I'm not seeing how those replies were rude; intentionally or otherwise. I hope you continue to interact on future forum threads, though. Your knowledge of C should prove invaluable on certain projects.
Tread on those who tread on you
Posts: 733
Threads: 103
Joined: Apr 2022
Reputation:
14
(09-12-2022, 05:34 PM)mnrvovrfc Wrote: Learned something else: QB64 permits "DIM" statements inside a loop! I thought it was going to complain about "duplicate definition" for "t" although it's not an interpreter...
(09-04-2022, 08:21 PM)madscijr Wrote: If this is about reading the mouse, QB64 has its own way of reading the mouse. When in Rome...! (09-08-2022, 03:29 AM)madscijr Wrote: That makes sense. All we need is C, so... I'm trying to help on this topic, but I don't like some of your answers. It seems my knowledge is inferior to others here and therefore I'm the only one being replied to in this manner. This is my last post in this topic for this reason. I'm not a C/C++ programmer and I don't want to be. I like to help people, but if I keep getting this kind of replies then I might stop participating on this forum. Until now I have contained myself, tried to be laid back like the guys having way more reputation on this forum than me. But it cannot go without saying any longer.
"All we need is C" but I was going to reply "Without C++ you can't do anything with QB64 and what would you do then?" But I contained myself. I'm admitting it now because I like this place and the people in it. I'm not angry or anything but I'm not going to post on this topic any longer. >==>
Sorry if you got the wrong idea from what I said,
I'm not sure how my statements would be interpreted as rude,
but no disrespect was intended.
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
09-12-2022, 08:48 PM
(This post was last modified: 09-12-2022, 08:51 PM by Kernelpanic.)
Quote:mnrvovrfc - I had downloaded version 9 I think for 64-bit but couldn't do anything with it. But now I think the C/C++ compiler that comes with QB64 for Windows, or with a Linux distro is enough for me.
Couldn't install it or don't know what to do with it?
You can also generate color outputs with the GCC. Nice!
Posts: 346
Threads: 24
Joined: Jul 2022
Reputation:
20
@MadSciJr
Quote:Tempodi, Spriggsy converted the C to pure QB64 and it works! (Sort of!)
Now the next challenge is, how do we convert the event-driven code to normal QB64?
sorry I have missed this code by Spriggsy! I see at #84 a code to manage WAV files.
Where can I get the Spriggsy's code about MIDI?
Waiting answers I thank you.
|