Page 1 of 1

Considering to start programming with PureBasic

Posted: Sun Jan 28, 2018 4:35 pm
by Rudy
My first post on this forum, hello to everybody here. :)

It has been a while I did some programming, but I have an idea for a project and I need to do some coding. For this, I'm considering PureBasic. It involves audio synthesis, for now not in realtime. I also looked at things like SuperCollider, but I think writing it in a language like PureBasic makes it easier for other people who might be interested to use my software. Correct me if I'm wrong, but I'm especially drawn to PureBasic because I've read it produces small executables with little to no dependencies, with good execution speeds. So it should work on almost all computers?

Basically what I want to do: reading WAV-files, perform a whole lot of calculations on the data, writing the results as a WAV-file. I hope it's not too complicated to read and write WAV-files? Another question, if it's possible to say anything about it in general, is PureBasic faster with calculations on integers or floats?

Of course I've looked at some topics here on the forum and examples of code, to be honest it all looks a bit overwhelming. I do have some experience with programming, but that's a long time ago. Examples are: GWBasic, TurboBasic and TurboPascal. All of them in the DOS-era. So it has been ages. I just hope the learning curve is not too steep for an old dinosaur like me... :wink:

Re: Considering to start programming with PureBasic

Posted: Sun Jan 28, 2018 5:04 pm
by Mijikai
Since PB is not a interpreted language and even allows inline ASM - speed wont be a problem.

Re: Considering to start programming with PureBasic

Posted: Sun Jan 28, 2018 5:29 pm
by wilbert
Rudy wrote:Basically what I want to do: reading WAV-files, perform a whole lot of calculations on the data, writing the results as a WAV-file. I hope it's not too complicated to read and write WAV-files? Another question, if it's possible to say anything about it in general, is PureBasic faster with calculations on integers or floats?
PureBasic is a really nice language.

The wav format is not that difficult to handle but you will have to parse the files yourself if you want to access the sample data.
Myself together with J. Baker created an application with PureBasic called Macrotune which can output the audio it generates to a wav file.
http://www.posemotion.com/macrotune/
There are other examples on the forum as well of users who created an application using PureBasic which works with audio samples.

When it comes to floats vs integers, both are pretty fast and you can speed up time critical parts with ASM when needed.

Re: Considering to start programming with PureBasic

Posted: Sun Jan 28, 2018 8:40 pm
by J. Baker
If you used TurboBasic (PowerBasic) then you will be fine picking up PureBasic. Instead of CALL and SUB, you can write a Procedure() in PureBasic and call it by its procedural name that you have given it. This, of course, can be used multiple times throughout your code. Everything else is kind of similar, basic-wise, and shouldn't be hard to pick up on. ;)

Re: Considering to start programming with PureBasic

Posted: Sun Jan 28, 2018 9:12 pm
by Rudy
Thank you all for your reply. Right now I'm going through the documentation, there are a lot of commands in PureBasic, some 1400 or so? :shock: On one hand, that's good, on the other hand, maybe there a risk you code something and many lines later you discover there is a simple command for that? :)
J. Baker wrote:If you used TurboBasic ...
Yes, although it has been a while. But if it's all somewhat similar, that helps.
I'm seriously considering to give it a shot, so in that case, expect a lot more questions from me in the near-future. :wink:

Re: Considering to start programming with PureBasic

Posted: Sun Jan 28, 2018 10:08 pm
by Dude
Rudy wrote:I'm seriously considering to give it a shot
There's a demo version that you can try. Since you came from GWBasic, you'll find PureBasic easy enough to pick up. And we're all here to help if you need it. :)

Re: Considering to start programming with PureBasic

Posted: Sun Jan 28, 2018 10:15 pm
by Bitblazer
Welcome to PureBasic. I guess you already noiced two major important points by your posting.
  • the community exists and is active
    the community is helpful
Both crucial points if you want to get things done with a new language :)

Let me maybe add another crucial point: compatibility / extensibility
When i try to work with audio data like wav for a free project, i include the latest BASS library first. A few lines later, your project has always the same kind of audio buffer you work with and its suddenly able to process lots of audio formats with plenty of options and check the licensing in case your software goes commercial. Its quite fair IMHO.

Code: Select all

XIncludeFile "DShowMedia.pbi"
XIncludeFile "Bass/PB/bass.pbi"

If (BASS_Init(0, 128000, 0, 0, 0) <> 1)
  MessageRequester("Error", "BASS initialisation failed", #PB_MessageRequester_Ok)
  End 999
EndIf
I rarely work with audio files, so these lines are from an old tool done 2008, so i am hesitating to post the include files it uses, but if you have any problems, just send me a private message. You should get more current ones from the web though at the BASS website or forum. Welcome to PureBasic again :)

A tiny snippet how (stone old) software works with BASS and PureBasic

Code: Select all

  BassHSTREAM = BASS_StreamCreateFile(#False, @DataName$, 0, 0, #BASS_STREAM_DECODE)

  If (BassHSTREAM = 0)
;    BassErrorCode = BASS_ErrorGetCode()
    Result = -3
    Goto GetAudioFileInfo_CleanUp
  EndIf
  
  ChannelLength.q = BASS_ChannelGetLength(BassHSTREAM, #BASS_POS_BYTE)
  BTime.f = BASS_ChannelBytes2Seconds(BassHSTREAM, ChannelLength)
pretty easy imho.

ps: you can clearly see how old and unprofessional this snippet is - i even used GOTO :D

Re: Considering to start programming with PureBasic

Posted: Mon Jan 29, 2018 6:15 pm
by Rudy
Thanks to everybody for your comments and suggestions. It felt like a very warm welcome to this forum, and an invitation to join the PB club! :)