Real Time Synthesis - W.I.P

BlitzMax Forums/BlitzMax Programming/Real Time Synthesis - W.I.P

Taron(Posted 2016) [#1]
Hi all, as I was experimenting around with physical modeling ideas, I realized I could do a traditional synthesis for shits'n'giggles, too.

This is just a messy start, but who knows how far I will get and how soon, so I figure I best share it now already.

This is using openAL out of the original blitzmax, making it troublesome to translate it to a BlitzMax NG version, but if somebody does that successfully and make sound work at x64, please, please, post it here, too!



Small explanation (I might later break it down in a careful tutorial, too?!)

After all initializations, there's a process for the audio buffer filling, which should later on be in its own thread. But I currently haven't made this thing thread safe <caugh>, so...it's just a fliphooked process.

The "tone" type has a not so simple saw wave generator, followed by a 2 pole filter of my own design (LOL, so primitive, I apologize).

Then there's a simple dial type for the interface and the rest you can look over fairly easily, I think. It's all very rushed and messy, but it works. 8}

PIANO KEYS (US Keyboard):
 W E   T Y U   O P
A S D F G H J K L : "

PAGE UP/DOWN to change octaves!


Brucey(Posted 2016) [#2]
Didn't need to change much for NG. Just those two pointers, and a couple of casts.
Tested on OS X and it plays nicely. (apart from the al device/context shutdown issue that is an OS X system problem, and not specifically related to BlitzMax).



Taron(Posted 2016) [#3]
Thanks, Brucey, but I still don't get any sound out of it anymore in either x32 or x64?

I really should maybe start NG from scratch again, or so... it's so odd?!

But, honestly, awesome, thanks for checking into it already so quickly! 8D


GW(Posted 2016) [#4]
Very Cool Taron! Thanks for sharing. Blitzmax needs more Dsp examples.
As far as NG goes, Why not use freeaudio?

This compiles and runs in NG without any problems for me.



Taron(Posted 2016) [#5]
Well, for once you should write:
'------------------------------------
Global frets:Float[25]

You went beyond the array limit, you know! ;o)
UH, that sounds GREAT! WICKED! 8D
First at to figure out the [SPACE] thing!

I will most certainly investigate into a freeaudio option. THANK YOU!

However, I delete all of NG and copied everything fresh into place, built all modules and so on, but even at x32, openAL still won't make a noise for me.
Again, in the original bmax it's no problem at all. 8{
What might I be doing wrong? Any remote clues?
I'm so confused...


GW(Posted 2016) [#6]
You went beyond the array limit, you know!

Oops!

First at to figure out the [SPACE] thing!

That's there for me trying to figure out palm-muting.

I'm not sure why OAL wont work for you. did you check all the return codes?

Brucey's example doesn't play any audio for me either btw.


Taron(Posted 2016) [#7]
Oddly comforting to hear (not to hear...lol). I swear, though, the very, very first time I compiled my physical modeling experiment "Woody" in NG at x32, it worked just fine, sound and all. Then I switched to x64 and since then openAL would never spit out a sound anymore. <shrugs>


Brucey(Posted 2016) [#8]
Hallo. There was an issue with NG when passing a Null argument to a parameter defined as $z or $w.
The fix has been committed to the github repository.

The example above now plays openal audio on Windows.


Taron(Posted 2016) [#9]
I need to look around to find out how to deal with that. I'm so sorry, I feel like an idiot, but setup_install.script and all that leave me dumbfounded. 8{
I'm kinda hoping to get some tips without asking, because I'm sure I find out all there is to know by just looking properly and I'd be ashamed to ask first...

Oh, ok, so now I signed up for Github and am in the process of installing Github Desktop... I SHALL figure out all this goodness! xD

Meantime, thanks Brucey. All this stuff has to be so natural to you, it's weird if a seasoned coder like me turns out to be a total noob about what you do. I'm in awe of what you do!


Hmmm...I feel foolish. I still can't handle git, but I downloaded this: https://github.com/bmx-ng/bmx-ng
And simply replaced the files in my BlitzMax NG folder accordingly. Rebuilt all modules. But I must be like rather ape like with it, since that didn't make a difference thus far. At least it didn't break! (amazing)


Brucey(Posted 2016) [#10]
For now, you can replace Null in the call to alcOpenDevice() with, for example "DirectSound", and that should work.


Taron(Posted 2016) [#11]
<sigh> ...you make me hate myself, Brucey. Just so you know, I am trying, even if I end up like this again...Identifier 'DirectSound' not found.

I will keep importing potential candidates that might give meaning to DirectSound. What a chase that is every time. Like some odd kung-fu training where you just have to stand in the rain for a week just to discover whether you really want it yourself, hahahaha.... xD

I'm sorry, man. I will keep my head up!


Derron(Posted 2016) [#12]
bmx-ng/bmx-ng is a place for releases of complete packages.

If your intent is to update specific parts - or if you cannot await new complete releases:
- bmx-ng/brl.mod for most current NG-compatible brl.mod
- bmx-ng/pub.mod for most current NG-compatible pub.mod
- bmx-ng/bcc for most current NG-compiler BCC
- bmx-ng/bmk for most current NG-variant of BMK (should work with vanilla too)

Remember: if you update BCC, recompile all modules
Remember2: if you deploy BMK to your BlitzMax-bin-dir, do not forget the .bmk files (see readme of BMK - or the github "starting page" of that bmk-repo - so at least core.bmk and make.bmk)


@ git client and signup
If you do not intend to collaborate/change things, you should not need to have an githubaccount (if you have OSS parts, feel free to use it now to store them in your own github repos).
Just use the "clone or download"-button to download the most current revision (without all the hidden .git-folders and the complete revision history).

Therefor you also do not need to play with "git" and "git pull".

bye
Ron


Taron(Posted 2016) [#13]
Ron, you rock! Thanks for this fantastic set of info! 8D

I'm ready for almost anything to make this work, because x64 compiles will change my life significantly over here! Not only because of hopefully getting MIDI to work, but having a 64bit compile of Verve would open up new worlds and I may not have to switch to C++ with the whole thing.

SO: THANK YOU! I'll dive in right away!


Brucey(Posted 2016) [#14]
Identifier 'DirectSound' not found.

alcOpenDevice() takes a String as an argument, so you want to use it thus :
alcOpenDevice("DirectSound")

Other examples of audio devices on Windows include "MMSYSTEM" and "DirectSound3D".
You may also be able to use soundcard-specific names.


Taron(Posted 2016) [#15]
I feel nothing but happiness right now, Brucey and Ron!
After having compiled BCC and BMK(properly replacing the exes in the /bin) and having rebuilt all modules (for every c or cpp it opens a cmd prompt now, which is a bit annoying), the synth compiles perfectly in x32 AND x64 with sound and all!

Here's an update with stereo delay and a few improvements:
BlitzMax NG version!!! For all those who try to compile this in the ordinary BlitzMax version (PAH! Sorry...lol)



Taron(Posted 2016) [#16]
May I ask one of you to help me with the Midi input solution (x64)?
I'm sure I'm going about this utterly wrong. Just to clarify:

- I downloaded the bah.mod/rtmidi.mod
- it appears to have been building just fine in NG
- I tried to compile the /examples/midi_in.bmx
- ...it won't create an exe and, of course, fails to link to it then. But doesn't tell me what's wrong?! (neither in release nor debug!)


Derron(Posted 2016) [#17]
If you think it is an error in BCC, check the used commands by using "-v" with bmk (bmk makeapp -r -v myfile.bmx).

This then outputs the command used to execute BCC.

Now with this params known, open up bcc.bmx and within MaxIDE add these params to "program - command line".

When now doing a debug build+run of bcc.bmx, it will execute it with these params and it will try to compile that file.
If BCC now struggles (aka "crashes") you have good chances to have maxide catch this error and show to you where it happened.


Edit: Just tried with up-to-date bcc and *.mod on linux - and there it compiled without flaws.


bye
Ron


Taron(Posted 2016) [#18]
omg...

Ron, I apologize! As I'm getting comfy with github, I've been looking around and found out that my bah midi was at version 1.02, while there's a 1.04 already. I downloaded it, built the module... and it flipping works!

I'm a tiny little bit scared right now that my head just might explode for excitement! Maha...oh man.

Now, I'm not sure how many of you out there might get a chance to have the same fun with what I'm going to do that I will most likely have, because I'll hook up midi to the synth, oh yes! I kind of can't believe that BlitzMax would ever allow for something like this, hehehe... this is crazy!

Again, I apologize for being a bit dreadful about getting to hear, but the information you two have given to me by now is worth so much, way beyond the current matter, which is hereby RESOLVED!

I'm so terribly excited. ^^
...give me a few hours (probably) and I'll have a proper little synth ready for a midi keyboard! 8D


Derron(Posted 2016) [#19]
Glad I (amongst others) was able to help. Do not ask Brucey how often I stand at his door (not literally) asking for things I could resolve on my own. Think he already has some kind of "template system" when replying to my mails (I often forget some basics and wonder why things then don't work).


bye
Ron


RustyKristi(Posted 2016) [#20]
Yep, I got the same issues before. I didn't know my working file is outdated and when I finally did a clone most of them are fixed instantly! :))

Big kudos to these guys for their extreme patience.


Taron(Posted 2016) [#21]
Oh yes! I haven't spent much time here for years and you guys remind me how great a place this can be! 8D

I've got a preliminary version running already, making a threaded built with midi and audio in one process and gfx and gui in the other. It's running sweet!
A few more things to beautify and then I'll add a new version. I'm baffled as to how fantastic this works. It's virtually unlimited voices and not one hick-up thus far! It really makes me wonder what weird stuff Steinberg was doing with the vst solution?! <shrugs> ...I'm afraid, sooner or later I might find out. But for now: WOHOO!


GW(Posted 2016) [#22]
I wrote a chiptune tracker synth in Bmax a while back (inspired by Musagi) and I've found Bmax to can handle the job very well, even single threaded. Screens.
Using NG should in most cases give an even bigger performance boost. In vanilla Bmax, threading is just not an option, but NG does threading very well without any performance hit.
Note that you can also use Midi input from the OS using 'SendMidiOut'.


Taron(Posted 2016) [#23]
Well, this is not a chiptune synth, making it a little hungrier, but thus far I haven't run into any choppy moments either. The buffers are fairly large, though. For stereo I had to go twice the size to prevent it from chopping up on my machine. Later on I will make those things customizable on the gui, too.
I'm still getting a silly crash with my thread solution, though, because it ain't safe the way I do it. But it's totally avoidable. Quite interesting to play with that, though.
Anyway, it's already a fantastic sandbox for dsp coding, I think!
And it's somehow amazing that I can play it with my midi keyboard, haha, feels so surreal.

A few more things I gotta do before posting the update. Not sure, if I get to those today, though. Had a few distractions...

Dang, I'd love to see your chiptune tracker om action, though! I'm sure it's fun! 8}

I'm playing around with the idea of adding a pattern feature, too, allowing to record midi. Just for fun, though...


Xerra(Posted 2016) [#24]
Love Taron's enthusiasm. We need more of that here.


AdamStrange(Posted 2016) [#25]
but thus far I haven't run into any choppy moments either.

mmmm. have you tried repeatedly pressing multiple keys. once the voice usage goes past 5-8 you get stutters, dropout etc in the sound


Taron(Posted 2016) [#26]
That depends on your machine, Adam! If it stutters early like that, you must increase the BUFFER size! (I have yet to get to stutters and played well of 30 voices! And I only got a 2.6Ghz Xeon (6core). Slow by current standards and well outdated.

Xerra, thanks, even after 30 years of programming, the magical powers of it only continue to increase it seems. Once you feel this for your own purposes, there's no way not to be thrilled, I believe. 8}


Taron(Posted 2016) [#27]
Still damn near impossible to program with the maxIDE, here's a still thread unsafe version with MIDI. Haven't had a crash for a whole doodle session, so, hehe...



I still have to consider a totally different approach to how I get my oscilloscope data. I'm sure it's just a ridiculous brainfart of mine. Feel free to put me to shame with an intelligent solution! 8}


AdamStrange(Posted 2016) [#28]
i'm on a 2011 2.7 i7 here.

Just running the midi version. not looking at the code as just run - note off not implemented yet?


AdamStrange(Posted 2016) [#29]
mmmm, just been looking at the code.

in the midi process function you really should only be dealing with the hi nibble of the message byte (the top four bits). the lo nibble (bottom four bytes is the midi channel)
so
if message[i] = 144

should be something like
truemessage = message[i] shr 4
if truemessage = 9 <-- 9 or 1001 is note on

Also. the note off issue is something widely known in that: some keyboards ONLY send noteon (1001) and not followed by note off (1000). a second noteon (1001) is used as the noteoff


Taron(Posted 2016) [#30]
Ah, it's just been a super quick throw-in and with my keyboard it works perfectly!
I made some super impatient observations and implemented them, thus not going by any "book" for that matter...

But, yeah, awesome, feel free to jump in at any time, but please, share your improvements, if you don't mind! That is what I love about here! 8)
I'm thrilled already, that it works to begin with! But, again, I don't have a note off issue in the midi/audio section. There's a note off issue with the display, but it has got nothing to do with midi, it's my idiot approach to avoid thread clashing. <blush>

In a more elegant version it should probably clean up like so:
		For Local i:Int = 0 Until nBytes
			local status:byte = message[i]
			Select i
				Case 0 
					status:&$f0
					If (status>=$90 and status<$a0) 
					 	note_on = True;
					 	disp_note_off=False 
					Else if (status>=$80 and status<$90)
						note_off = True
					EndIf 
					'...followed by controller messages 
				Case 1
					note = status&$7f		
				Case 2
				    velocity = status&$7f
			EndSelect 
			ms:+message[i]
		Next			



But I actually like your solution even more! That's very pretty! And a MUCH wiser approach to deal with the channels, too, very elegant!

Later on I'll see how much of this I may implement:
https://www.midi.org/specifications/item/table-1-summary-of-midi-message

It's quite nice. :o)


Taron(Posted 2016) [#31]
How about this:


I made the midi processing a bit cleaner and added a mod wheel for vibrato. It's just temporarily fixed to a max, of course, but it plays really nicely! :o)


Taron(Posted 2016) [#32]
Little question for Brucey and/or Derron:
What IDE are you using to code for NG?

I've just started to setup sublime text 3, which is a gorgeous editor, but I still have to learn how to write build commands and so on. Also, there's a way to get some code intelligence like finding definitions and so on, but all this still escapes me. SO, yeah, I really wonder? Because I cannot imagine you're using the maxIDE?!


Brucey(Posted 2016) [#33]
I'm using an NG-configured MaxIDE (i.e. lots of extra build options).

I generally have two open at the same time - a legacy MaxIDE for bcc editing and debug, and the one (mentioned above) for NG itself.


Derron(Posted 2016) [#34]
I use "geany" with my compiler-addon (to have some icons and a dropdown for options) for normal coding.
MaxIDE when it comes to debugging.


bye
Ron


GW(Posted 2016) [#35]
I use the NG ide for small programs and I use BLide for larger projects.

btw, the NG ide really needs a custom Icon and name. It hard to make out the difference between NG and vanilla ide when both are open.


Derron(Posted 2016) [#36]
Feel free to suggest a logo, I created an issue for it on github a year ago.
Then just recompile Brucey's MaxIDE variant and use that logo you decided for.

@ Blide
Windows only.

@ Editor
Maybe the one really interested in this subject should create a new thread to avoid thread-derailing.


bye
Ron


GW(Posted 2016) [#37]

I made new icon then. Ugly, but does the job.


Taron(Posted 2016) [#38]
Thanks, Ron! I was anticipating a mild derailment, of course, haha, but it's really worthy of it's own thread!

BLide is the closest to a respectable IDE for BlitzMax, still not up to par compared to visual studio, of course. But Sublime is really a beautiful editor, I just wished it was possible to hook up the code intel and all the build options for NG properly (the latter is possible, but I don't know how, yet!).

The maxIDE and NG version, they are travesties when it comes to text editing, it's so horrible. I get fits when trying to work with those. No column selection, double click selections interrupted by underscore (and I like naming variables blah_something). No "go to declaration or definition" no autocomplete... ah well.

Anyway, thanks for all the replies and I'm actually astounded! Ron I understand most, which is my current situation, though, I haven't hooked up BLide to compile NG, yet- not to mention no x64 compiling-, but I'm also mildly scared not to be able to reset it back to normal, hahaha...silly me.