View Single Post
Old 04-12-2012, 02:48 PM   #36
cyco130
Human being with feelings
 
Join Date: Apr 2012
Posts: 4
Default

Wow! This is incredibly cool. I was trying to use C preprocessor for this kind of semi-object-oriented stuff but 16 chars limit prevented me from using token pasting effectively. Just when I was considering to write my own preprocessor I saw this thread. And it all happened today!

Here's a small but useful js function, just to show that this new addition opens up some very cool possibilities that may not be immediately recognizable:

Code:
@init
    function malloc(size)
        local(result)
    (
        result = heapTop;
        heapTop += ceil(size);
        result;
    );
    
    // Allocate 200 ms delay buffers for each channel
    delayBufferL = malloc(srate * 0.200);
    delayBufferR = malloc(srate * 0.200);
    
    // Report memory usage
    freembuf(heapTop);
Automatic memory management for JS

One can also declare heapTop as an instance variable to avoid polluting the global namespace. I love it!

Now this addition begs for an include file functionality (in case it doesn't exist already), with a dedicated Effects\Include folder so we can immediately start rolling reusable DSP libraries for interpolated delay buffers, biquad filters etc.

Last edited by cyco130; 04-12-2012 at 04:11 PM. Reason: Corrected freemembuf -> freembuf in the code
cyco130 is offline   Reply With Quote