Anybody messing around with JS? Let's share plugins and ideas and stuff!

TyphoidHippo

1Trillion K Platinum User
JS is, by far, the most impressive thing I've ever seen in a DAW - and this is coming from a life-long Cubase user with lots of PT sprinkled throughout. I just wrote a basic limiter in like 10 minutes. This is seriously badass!

I'm trying to post the code here in a readable way.... do we have a code tag or something similar that leaves whitespace intact? None of these buttons look like they'll be of any help...
 
JS is, by far, the most impressive thing I've ever seen in a DAW - and this is coming from a life-long Cubase user with lots of PT sprinkled throughout. I just wrote a basic limiter in like 10 minutes. This is seriously badass!

I'm trying to post the code here in a readable way.... do we have a code tag or something similar that leaves whitespace intact? None of these buttons look like they'll be of any help...

no code tags here :-) Can you post some links to what you are writing about?
 
Well, that's lame! I suppose quote tags are better than nothing...my beautiful brace alignment :( lol

and sure - it's a plugin scripting framework built into reaper
REAPER | JS Programming
I read through that and had this limiter up and running in literally like ten minutes:
// Ghetto Smash!
// (C) 2012 TyphoidHippo (like that means anything, lol)

desc: Lame-o brickwall - woohoo for loudzorz!

slider1: 0.0 < 0.0, 65.0, 0.001> Threshold
slider2:-0.2 <-65.0, 0.0, 0.001> Ceiling

@init
@slider
gGAIN = pow(10.0, slider1 / 20.0);
gCEIL = pow(10.0, slider2 / 20.0);
gFMAX = 2.0 ^ 31.0;
gSCALE = gGAIN * gCEIL;

@sample

//Left
spl0 *= gSCALE;

abs0 = abs(spl0);
abs0 > gCEIL ?
(
clip = abs0 - gCEIL;
spl0 = (gCEIL + clip / (gFMAX + clip)) * (spl0 < 0.0 ? -1.0 : 1.0);
);

//Right, only if stereo
num_ch > 1 ?
(
spl1 *= gSCALE;

abs1 = abs(spl1);
abs1 > gCEIL ?
(
clip = abs1 - gCEIL;
spl1 = (gCEIL + clip / (gFMAX + clip)) * (spl1 < 0.0 ? -1.0 : 1.0)
);
);

I know you've dome some coding so it's probably immediately obvious how the whole syntax works, it's just like you write a decription, define what sliders you want and their min/max and increment values, then write callbacks for initialization, slider adjustments and each sample you process. All variables are doubles and there's some keywords for things like the sample values and number of channels. There's even a real-time debugger and editor built into Reaper. Totally EFFing awesome :)
 
Last edited:
Thanks for the reference. Yes - scary - I immediately understood :-) My first question was answered in the first line of the site "JS is a scripting language which is compiled on the fly". This is pretty cool - would be nice for quick and dirty protos to test ideas.

Well, that's lame! I suppose quote tags are better than nothing...my beautiful brace alignment :( lol

and sure - it's a plugin scripting framework built into reaper
REAPER | JS Programming
 
Yea, it really is great for quickly testing ideas and ironing out algorithms - I've been playing around with generating harmonics to a given signal today. Do you know anything about the math involved in that? I've never really messed with it before and I'm using algorithms that basically just call sin(sampleValue + Pi/2 (or Pi/4)). It is working and I'm getting some cool results, but I can't wrap my head around what this is doing or why this is all it takes to generate harmonics like this. I have a solid base in trig and vector and matrix maths that make heavy use of trig for orientations and the like - but why exactly is trigonometry involved in harmonics like this? I'm kinda confused...
 
I've written some JS plugins to generate randomized drum and synth lines. It's a really cool feature! I've found that it isn't the most intuitive language I've ever programmed in, but it gets the job done.
 
Yea, it really is great for quickly testing ideas and ironing out algorithms - I've been playing around with generating harmonics to a given signal today. Do you know anything about the math involved in that? I've never really messed with it before and I'm using algorithms that basically just call sin(sampleValue + Pi/2 (or Pi/4)). It is working and I'm getting some cool results, but I can't wrap my head around what this is doing or why this is all it takes to generate harmonics like this. I have a solid base in trig and vector and matrix maths that make heavy use of trig for orientations and the like - but why exactly is trigonometry involved in harmonics like this? I'm kinda confused...

I just noticed your post after re-reading the thread.

The algorithm I use for sin waves is
splX = sin(2*$pi*freq*i);
Where splX is the sample you want to set, i increases by 1/srate each sample, and freq is the frequency of the tone I'm generating (e.g. 440 Hz for A)

The basic math of it is, that if you graph sin(x), it draws a standard sin wave. As x increases, your amplitude fluctuates at a consistent frequency. In fact, if you use 440 for freq in the above example, it will go from 0 to 1 to 0 to -1 back to 0 440 times in a second, generating an A tone.

You can also do some fun stuff to shape the wave.
To turn your sin wave into a square wave, you just need to only allow 1 and -1 as your sample values.
i.e.
splX = sin(2*$pi*freq*i);
(splX > 0 ) ?
(
splX = 1;
) : (
splX = -1;
);

To make a sawtooth wave, start your sample at 1 and decrease it until you hit 0:
prev = get the previous sample somehow
splX = prev - freq/srate;
splX <= 0 ? splX = 1.0;

To make a triangle wave, take your sawtooth wave, and let it go down to -1 (but take the absolute value!)
prev = get the previous sample somehow
spl = prev - 2*freq/srate;
spl < -1 ? spl = 1.0;
spl >= 0 ? splX = spl : splX = -1 * spl;

(also, BOO! why doesn't the forum support
Code:
 tags!)
 
I wondered what all those JS plugs were? SI that all they are is just custom written plug ins by reaper users?
 
The bulk of the default ones were (at least initially) written by the guys who created JS. It was originally a stand-alone Linux program. They even had plans to build dedicated hardware. (The CrusFX was going to be a wooden box with a small Linux computer in it running JS).

Then it got picked up by Reaper.
 
Back
Top