Old 07-24-2014, 01:39 PM   #1
Smashed Transistors
Human being with feelings
 
Smashed Transistors's Avatar
 
Join Date: Jul 2014
Location: Là bas les huîtres (FR)
Posts: 424
Default Synthesis Toolbox : Oscilloscope

This is an oscilloscope adapted from the old moonsynthi code.

Features:
  • Synch by zerocrossing (with low pass and DC removal)
  • Automatic gain up to 30dB
  • Automatic limiter
  • Time scale from 1 sample per pixel to 20 samples per pixel (includes smoothing)
  • Graphic antialiasing, including horizontal lines.
  • Freezes/unfreezes when clicking in graphic area

Comments and "modern JSFX" suggestions are more than welcome



Code:
desc: Scope
slider1:0<0,4,1{1 sample per px,2 samples per px,4 samples per px,10 samples per px,20 samples per px}>Time scale
slider2:0.01<0.001,0.1>Sync speed
//______________________________________________________________________________
//                                                                      Features
// Automatic gain up to 30dB
// Automatic limiter
// Time scale from 1 sample per pixel to 20 samples per pixel (inc smoothing)
// Graph antialiasing, including horizontal lines.
// Freezes when clicking in graphic area
//______________________________________________________________________________
//                                                                         TO DO
//______________________________________________________________________________
@init
LB = srate|0;
tInL = 0; 
tInR = LB;
coef = 2 * LB;
scale = coef + 20;
scale[0] = 1;    coef[0] = 1;
scale[1] = 2;    coef[1] = 1/2;
scale[2] = 4;    coef[2] = 1/4;
scale[3] = 10;   coef[3] = 1/10;
scale[4] = 20;   coef[4] = 1/20;

cSamp = 0;
maxGain = 31.6227766; // <-> 30dB
maxGain1 = 1 / maxGain;

//______________________________________________________________________________
@slider
//______________________________________________________________________________
@block
//______________________________________________________________________________
@sample
!frozen ?
(
  sc += 1;      //sample counter for subsampling (time scaling smoothing)
  a0 += spl0;   //sample accumulators for time scaling smoothing
  a1 += spl1;
  sc >= scale[scaleType] ?
  (
    tInL[cSamp] = a0 * coef[scaleType];
    tInR[cSamp] = a1 * coef[scaleType];
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
//                                                                    SCOPE sync
//                              zero crossing on a0 (wih low pass and dc remove) 
    low  += slider2 * (a0 - low);
    low2 += slider2 * (low  - low2);
    dc   += slider2 * (low2 - dc);
    spl0f = low2 - dc;
    (spl0f > 0 && aspl0f <= 0) ? ( 
      syncPos = cSamp;
    );
    aspl0f = spl0f;  
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    cSamp = (cSamp + 1) % LB;
    sc = 0;  a0 = 0; a1 = 0;
    scaleType = slider1; // to avoid side effects when changing slider1
  );
);
//______________________________________________________________________________
@gfx 0 200
h1_4 = gfx_h * 0.25;
h3_4 = gfx_h * 0.75;
h1_2 = gfx_h * 0.5;

// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
old_mouse_cap == 0 && mouse_cap != 0 ? frozen = !frozen;
old_mouse_cap = mouse_cap;
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
// Grad every 10 samples
scaleType == 0 ? (
  gfx_r = 0.1; gfx_g = 0.1; gfx_b = 0.05;
  x = 0;
  while(
    gfx_y = 0; gfx_x = x;
    gfx_lineto(x, gfx_h, 0);
    x += 10 * coef[scaleType];
    x < gfx_w;
  );
);
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
// Grad every 100 samples
gfx_r = 0.2; gfx_g = 0.15; gfx_b = 0.05;
x = 0;
while(
  gfx_y = 0; gfx_x = x;
  gfx_lineto(x, gfx_h, 0);
  x += 100 * coef[scaleType];
  x < gfx_w;
);
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
// Grad every 1000 samples
gfx_r = 0.35; gfx_g = 0.1; gfx_b = 0;
x = 0;
while(
  gfx_y = 0; gfx_x = x;
  gfx_lineto(x, gfx_h, 0);
  x += 1000 * coef[scaleType];
  x < gfx_w;
);
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
gfx_r = 0.0; gfx_g = 0.0; gfx_b = 0.2;
gfx_x = 0; gfx_y = h1_4; gfx_lineto(gfx_w, gfx_y, 0);
gfx_x = 0; gfx_y = h3_4; gfx_lineto(gfx_w, gfx_y, 0);
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
i0 = (syncPos - gfx_w + LB) % LB;// syncPos <-> relative to latest zero crossing
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
//                                                                     auto gain
vmax = maxGain1; 
i = i0;
loop(gfx_w - 1,
  i += 1;
  abs(tInL[i % LB]) > vmax ? vmax = abs(tInL[i % LB]);
  abs(tInR[i % LB]) > vmax ? vmax = abs(tInR[i % LB]);
);
gain = 1 / vmax;
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
yOffset = h1_4;
dispGain = gain * h1_4; //display scale
gfx_r = 0.0; gfx_g = 1.0; gfx_b = 0.0;
t = tInL;
loop(2,
  gfx_x = 0; i = i0;
  gfx_y = h1_4 - gain * t[i];
  loop(gfx_w - 1,
    i += 1;
    i >= LB ? i = 0;
    y = yOffset - dispGain * t[i];
    abs(y - gfx_y) > 1.2 ?
      gfx_lineto(gfx_x + 1, y, 1)
    : (
      y0 = floor(y);
      yf = y - y0;
      gfx_x += 1;
      gfx_y = y0 + 1;        
      gfx_setpixel(0, yf, 0);                      
      gfx_y = y0;      
      gfx_setpixel(0, 1-yf, 0);
    );
  );
  t += LB;
  yOffset += h1_2;
);
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
gfx_r = 1; gfx_g = 1; gfx_b = 1;
gfx_x = 0; gfx_y = gfx_h - 1 - gfx_texth;
gfx_drawstr("Gain= ");
gain < 1                  ? (gfx_r = 1; gfx_g = 0; gfx_b = 0; )
: gain + 0.001 >= maxGain ? (gfx_r = 0; gfx_g = 0; gfx_b = 1; );
gfx_drawnumber(20 * log10(gain), 5);
gfx_drawstr("dB");
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
frozen ? (
  gfx_x = 0; gfx_y = 0; gfx_r = 0; gfx_g = 1; gfx_b = 1;
  gfx_drawstr("Frozen");
);
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Last edited by Smashed Transistors; 01-28-2015 at 02:17 PM.
Smashed Transistors is offline   Reply With Quote
Old 07-25-2014, 08:54 AM   #2
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
Default

Many thanx but where to download the script ?
vanhaze is offline   Reply With Quote
Old 07-25-2014, 09:18 AM   #3
beingmf
Human being with feelings
 
beingmf's Avatar
 
Join Date: Jul 2007
Location: Jazz City
Posts: 5,065
Default

Quote:
Originally Posted by vanhaze View Post
Many thanx but where to download the script ?
Copy > paste
__________________
Windows 10x64 | AMD Ryzen 3700X | ATI FirePro 2100 | Marian Seraph AD2, 4.3.8 | Yamaha Steinberg MR816x
"If I can hear well, then everything I do is right" (Allen Sides)
beingmf is offline   Reply With Quote
Old 07-25-2014, 12:17 PM   #4
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
Default

Oops... how silly of me to have forgotten about that.

Thx !
vanhaze is offline   Reply With Quote
Old 07-25-2014, 12:45 PM   #5
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
Default

I get this error message.

(attachment)

Am i doing something wrong ?

Last edited by vanhaze; 01-09-2016 at 02:50 PM.
vanhaze is offline   Reply With Quote
Old 07-25-2014, 12:56 PM   #6
Smashed Transistors
Human being with feelings
 
Smashed Transistors's Avatar
 
Join Date: Jul 2014
Location: Là bas les huîtres (FR)
Posts: 424
Default

On your snapshot there is a / after @init

maybe a problem with copy past.

Here it is as an attachment.

Last edited by Smashed Transistors; 08-03-2014 at 05:16 AM.
Smashed Transistors is offline   Reply With Quote
Old 07-25-2014, 01:07 PM   #7
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
Default

Thank you, works now !!

One side note which i do not understand:

I am on mac.
When i delete the .txt extension from your file, the plugin isn't seen by Reaper.
So i have to keep the .txt in the name.
But the strange thing is that all the "stock" JS Plugins do not have a.txt extension in their name, but they ARE all seen in Reaper.

I am on OSX 10.9.4 , Reaper 4.71 , 64bit version.

Rob.
vanhaze is offline   Reply With Quote
Old 07-25-2014, 01:16 PM   #8
Smashed Transistors
Human being with feelings
 
Smashed Transistors's Avatar
 
Join Date: Jul 2014
Location: Là bas les huîtres (FR)
Posts: 424
Default

Can't say, on my win PC it is in the list whatever the extension (as long as it is not .jsfx-inc).
Smashed Transistors is offline   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 07:34 AM.


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