Old 05-13-2018, 10:30 AM   #1
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 3,069
Default JS "Psuedo Objects" by Index???

I guess I'm not completely sure how to even word the question.

What I'm wanting to do right now is to find and manipulate the RMS envelope for multiple audio inputs. But I'd like to avoid redundant code as much as possible, and perhaps more importantly, I'd like to not spend CPU ticks on processing empty channels. I'd like to be able to tell it how many channels are actually running and dynamically create the psuedo-objects as necessary.

thing[0].RMS_set(rms_ms); gave me a syntax error. Is there a way to do this without having to mess with the memory buffer array? I can see how to do that, but...
ashcat_lt is online now   Reply With Quote
Old 05-13-2018, 11:06 AM   #2
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,311
Default

Nope, can't do it. Memory shuffling is the only way.
IXix is offline   Reply With Quote
Old 05-13-2018, 11:57 AM   #3
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,311
Default

That is to say, if you want dynamic anything then you have to do it in memory. Pseudo-objects/namespaces and functions can help make the memory manipulation (much) easier but there's no way to dynamically create them or store any kind of pointer to them. That'd make it too easy.
IXix is offline   Reply With Quote
Old 05-13-2018, 01:35 PM   #4
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 227
Default

Yeah - the pseudo-object syntax is more or less a templating syntax. It's a neat way to make the language more powerful, but it's not actual objects/pointers.

As IXix says, you need to use the memory for this. I use a hacky pre-processor, which helps keep track of offsets etc. (so this code gets turned into constants).

It might not be relevant to you, but for performance, I have used a hybrid approach a couple of times. I have structures in the memory buffer which I use in @block and @init, but then (when needed) I copy them into a fixed set of pseudo-objects. So something like:

Code:
@block

// Do something with my_struct_list as an array
current_struct = my_struct_list;
loop(my_struct_count,
    ... something ...

    current_struct += 2; // let's say 2 fields in struct, so each array element is 2 slots long
);

// Variable length array, packed into fixed variables using templating/pseudo-object
my_struct0.is_active = (my_struct_count > 0);
my_struct0.foo = my_struct_list[0 + 0]; // 1st field of 1st struct
my_struct0.bar = my_struct_list[0 + 1]; // 2nd field of 1st struct
my_struct1.is_active = (my_struct_count > 1);
my_struct1.foo = my_struct_list[2 + 0]; // 1st field of 2nd struct
my_struct1.bar = my_struct_list[2 + 1]; // 2nd field of 2nd struct
... etc.

@sample

function do_the_thing(struct*) (
    my_struct0.is_active ? (
        spl0 += struct.foo; // whatever
        1; // continue to the next one
    ) : 0 // Stop after this one
);

do_the_thing(my_struct0)
&& do_the_thing(my_struct1)
&& do_the_thing(my_struct2)
...
For Spectrum Matcher (where there were a *lot* of filters), instead of switching each filter on/off individually as in the example above, I had blocks of (32, 16, 8, 4, 2, 1) which were switched on/off together - with these I could have anywhere between 1 and 63 filters, with only 6 conditional statements.

That's not pretty - it has a lot of almost-identical code. However, I've seen speedups of up to 3x, depending on what the code's doing.
__________________
JSFX set | Bandcamp | say thanks (donations)
geraintluff is online now   Reply With Quote
Old 05-13-2018, 01:43 PM   #5
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 3,069
Default

That's what I was afraid of, so I went ahead with the memory mess.

Thanks for the quick responses!
ashcat_lt is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.