tula's DSP modules

Post any examples or modules that you want to share here
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

tula's DSP modules

Post by tulamide »

I thought that, while exploring the DSP editor, I could just as well share the modules, I come up with. Of course, they will be very simple (yet), and of no use for anybody who can write some DSP code. But I think of those people who, like me, just can't get it and therefore need ready-made modules. Those people might find some use of my modules.

I don't expect this to become an insane number of modules, and I also don't know when I will have a new one ready. However, whenever I can provide something, I'll post it here.

If the DSP gurus find errors or inefficient code (NOT assembler, please, just a better DSP code writing), feel free to comment. I am happy to learn!
"There lies the dog buried" (German saying translated literally)
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Polarity Inverter

Post by tulamide »

This first one is probably the most easiest code ever. In fact, you could do it just with stream math and it might even be the better choice. But it was my first module, so here it is.

The Polarity Inverter does exactly that. Don't confuse this with phase shift. Some audio engineers might tell you that a phase shift of 180° would be equal to polarity inversion, but that's not really true. It would only work for never changing waveforms with a defined center point, like sine, triangle or square. It won't work for complex waveforms like noise or even the sum on a master buss.

Note: It has an on/off switch, but off does actually mean bypass. The signal is still evaluated and passed through unaltered, so it still uses some CPU load.
Attachments
polarity_inverter.fsm
Fixed version. No selector involved. Thanks to Martin for pointing me to it!
(10.53 KiB) Downloaded 1169 times
polarity_inverter.fsm
Initial version
(10.59 KiB) Downloaded 1178 times
Last edited by tulamide on Fri Jan 12, 2018 5:39 am, edited 1 time in total.
"There lies the dog buried" (German saying translated literally)
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Zero Crossing Detector

Post by tulamide »

This one is again as simple as I could keep it. The zero crossing is detected right after it happened, not when it is about to happen. This might be important for applications like Samplers.

Also, no interpolation is involved. It just looks at two adjacent samples and if either one is positive while the other is negative, a zero crossing has occured. It therefore does not detect negative to exactly zero or positive to exactly zero, since the crossing has not yet occured.

To the DSP gurus: I would love to do a streamboolean version of it, but I just don't know how they are used. If somebody could put together a quick example of how to use an incoming streamboolean in the DSP editor to alter the output based on the true or false notifications - that would be great!
Attachments
zero_crossing.fsm
(4.29 KiB) Downloaded 1150 times
"There lies the dog buried" (German saying translated literally)
User avatar
Spogg
Posts: 3368
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England
Contact:

Re: tula's DSP modules

Post by Spogg »

Doing this is a great idea!

I hope others chip in and we can all learn something.

In many cases there are many ways to achieve a similar result, but not all methods are as efficient as others. This is what interests me; the best way to get a desired result.

Cheers

Spogg
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: tula's DSP modules

Post by RJHollins »

Thanks T.

Are there any DSP sites that you're researching from ?
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: tula's DSP modules

Post by KG_is_back »

tulamide wrote:To the DSP gurus: I would love to do a streamboolean version of it, but I just don't know how they are used. If somebody could put together a quick example of how to use an incoming streamboolean in the DSP editor to alter the output based on the true or false notifications - that would be great!


I highly discourage you from using streambooleans, especially when receiving them from user-end.

In reality streambooleans are just regular streams with different icon. You have absolutely no guarantee that what comes from the user of your module actually provides true boolean (aka all bits on for true and all bits off for false). This is especially confusing when you connect green boolean to them. For regular stream, green boolean true gets converted to float 1. You would expect stream boolean to convert incoming green values to "all-bits-off" for zero/false input and "all-bits-on" for non-zero/true input, just like the green boolean does... ooh no no no :twisted: It behaves exactly like stream - converts everything to float and passes that - if you connect green boolean to it, it will pass 1 for input true.

Only use streamboolean within inside of your modules where you have full control over what passes trough them. Never trust user or stock components/prims to provide correct streamboolean format. Another solution is to add module/code that will convert potential incoming shenanigans to correct format:

Code: Select all

streamboolin in;
streamboolout out;
out=(in!=0); //this converts 0 to FALSE (aka does nothing, because 0=FALSE) and any non-zero value to TRUE
Attachments
dont_use_streambooleans.fsm
(1.17 KiB) Downloaded 1173 times
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: tula's DSP modules

Post by tulamide »

Thanks a ton, KG!
That's very valuable, important information! I will follow your advice.
"There lies the dog buried" (German saying translated literally)
BobF
Posts: 598
Joined: Mon Apr 20, 2015 9:54 pm

Re: tula's DSP modules

Post by BobF »

Hello tulamide,

Really looking good! Wish I had the time to develope some programming skills.

Keep up the great work, BobF.....
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Polarity Inverter

Post by martinvicanek »

Tula, about your inverter: nothing wrong with the code, however you could avoid the switch, which will interrupt audio and recompile te entire schematic on switching. My proposal would be this:
inverter1.png
inverter1.png (16.23 KiB) Viewed 25540 times

or, if you don't mind the little hack, this:
inverter2.png
inverter2.png (15.39 KiB) Viewed 25540 times
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Polarity Inverter

Post by tulamide »

martinvicanek wrote:Tula, about your inverter: nothing wrong with the code, however you could avoid the switch, which will interrupt audio and recompile te entire schematic on switching. My proposal would be this:
inverter1.png

or, if you don't mind the little hack, this:
inverter2.png

I love solution 2! It shows once again, what is doable if you have a "behind-the-scenes-view". Of course, a boolean converted to float is 0 or 1, and so it makes sense immediatly.

Is the selector always causing the stream section to recompile? It it the reason, so many people had issues with recompiling? If I remember correctly, the multiplexer does not cause a recompile?

Thank you very much, I will update the module!
"There lies the dog buried" (German saying translated literally)
Post Reply