Page 1 of 1

First and last stupid Ruby question for the year...I hope

Posted: Fri Dec 27, 2019 4:06 am
by deraudrl
Forgive me, my only previous exposure to Ruby was in Sketchup macros...

I encountered this snippet inside a toolbox module named 'Delay'. (The question of how it differs from the otherwise identical 'Delay' primitive just above it is best left for another time.)

Code: Select all

streamin in;
streamout out;
streamin delay;
float mem[44100];
float index;

stage(2)
{
   out = mem[index];
}

stage(3)
{
   mem[index] = in;
   index = index + 1;
   index = (index<delay)&index;
}

The last couple of lines look like they're just doing a standard increment-and-wrap, except the expression

index = (index<delay)&index;

screams "SYNTAX ERROR!!" in pretty much any language I've ever encountered. I can live with the idea that 'False' evaluates to 0 in a numeric context, but for this to work, it has to assume that 'True' evaluates to all 1s and 'index' is being treated as an array of bits. (I'm afraid to even ask why 'index' is declared "float".)

Re: First and last stupid Ruby question for the year...I hop

Posted: Fri Dec 27, 2019 4:21 am
by tulamide
Well, this isn't Ruby code. It's DSP code (a script specific to FS, but shares some ideas from C).

Although you didn't identify the correct language, you found out very well, what this is about. Indeed, what you discovered is a bitmask, with all implications you described. It has to be treated that way, because DSP code runs with SSE, which means up to 4 streams are processed in parallel and therefore only a bitmask can introduce some kind of conditional branching. You can read more about its use in the User Guide.

EDIT: The User Guide also explains why index is declared as a float ;)

Re: First and last stupid Ruby question for the year...I hop

Posted: Fri Dec 27, 2019 6:08 am
by deraudrl
(massive forehead slap) D'oh!

Still trying to get my head around the mono/poly/mono4 business...

I've done SIMD before, but only on older special-purpose hardware, not SSE. All those applications processed the multiple data streams identically.