December 21, 2022
In one of our REAPER development branches (and thus the latest +dev builds), there's now support for generating EEL2 code on the fly (for EEL reascripts, JSFX, video processors), using EEL2. I find this immensely pleasing.
To use this functionality, you can create an embedded script, using <? script code ?>, and that script has a separate variable/memory space, and can generate code using printf().
EEL2 often requires a lot of repetitive code to produce fast DSP code.
So for example, our loudness meter has a sinc filter that gets coefficients generated. Here's a before and after:
function sinc_gen_slice(cs, o*) instance(sinc_gen_val slice_pos) global() ( slice_pos = cs; - o.v00 = sinc_gen_val(); o.v01 = sinc_gen_val(); o.v02 = sinc_gen_val(); o.v03 = sinc_gen_val(); - o.v04 = sinc_gen_val(); o.v05 = sinc_gen_val(); o.v06 = sinc_gen_val(); o.v07 = sinc_gen_val(); - o.v08 = sinc_gen_val(); o.v09 = sinc_gen_val(); o.v10 = sinc_gen_val(); o.v11 = sinc_gen_val(); - o.v12 = sinc_gen_val(); o.v13 = sinc_gen_val(); o.v14 = sinc_gen_val(); o.v15 = sinc_gen_val(); + <? loop(x=0;sinc_sz, printf("o.v%02d = sinc_gen_val();%s",x,(x&3)==3?"\n": " "); x += 1) ?> );
There's some extra logic in there to produce identical output (including newlines) which isn't necessary, but added so I could test the output to make sure it didn't differ. The nice thing is, not only is this more readable and smaller, if you want to increase the filter size, you can without a ton of tedious and error-prone copy/paste.
Update, other tricks. If you want to make this code optional, you can do:
/* <? printf("%s/","*"); printf("code which will only be executed on new jsfx/etc"); printf("/%s","*"); ?> */and if you want either/or (new code vs legacy), you can do:
/* <? printf("%s/","*"); _suppress=1; printf("code which will only be executed on new jsfx"); printf("/%s","*"); ?> */ legacy code which will only be executed on old jsfx /* <? _suppress=0; ?> */(Forgot to mention earlier, you can set _suppress to have the preprocessor not output regular text)
Posted by saike on Thu 05 Jan 2023 at 19:01 from 84.106.132.x
Posted by John on Wed 19 Apr 2023 at 04:25 from 46.118.187.x
Add comment: