File: ringmodulator.jsfx

package info (click to toggle)
jsusfx 0.4.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,912 kB
  • sloc: ansic: 19,352; cpp: 9,314; php: 403; yacc: 338; python: 163; makefile: 124; lex: 113; sh: 6
file content (382 lines) | stat: -rw-r--r-- 9,404 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
// (C) 2008-2009, Lubomir I. Ivanov
//
// NO WARRANTY IS GRANTED. THIS PLUG-IN IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
// WARRANTY OF ANY KIND. NO LIABILITY IS GRANTED, INCLUDING, BUT NOT LIMITED TO,
// ANY DIRECT OR INDIRECT,  SPECIAL,  INCIDENTAL OR CONSEQUENTIAL DAMAGE ARISING
// OUT OF  THE  USE  OR INABILITY  TO  USE  THIS PLUG-IN,  COMPUTER FAILTURE  OF
// MALFUNCTION INCLUDED.  THE USE OF THE SOURCE CODE,  EITHER  PARTIALLY  OR  IN
// TOTAL, IS ONLY GRANTED,  IF USED IN THE SENSE OF THE AUTHOR'S INTENTION,  AND
// USED WITH ACKNOWLEDGEMENT OF THE AUTHOR. FURTHERMORE IS THIS PLUG-IN A  THIRD
// PARTY CONTRIBUTION,  EVEN IF INCLUDED IN REAPER(TM),  COCKOS INCORPORATED  OR
// ITS AFFILIATES HAVE NOTHING TO DO WITH IT.  LAST BUT NOT LEAST, BY USING THIS
// PLUG-IN YOU RELINQUISH YOUR CLAIM TO SUE IT'S AUTHOR, AS WELL AS THE CLAIM TO
// ENTRUST SOMEBODY ELSE WITH DOING SO.
// 
// Released under GPL:
// <http://www.gnu.org/licenses/>.

//=================================================
desc:Ring Modulator
//=================================================

slider1:0<0,1,1{Stereo,Mono}>Processing
slider2:0<0,1,1{Off,On}>Mod Input Diode (Waveshaper)
slider3:40<0,100,0.01>Mod Frequency (Scale)
slider4:0<0,100,0.01>Feedback (%)
slider5:10<0,100,0.01>Non-Linearities (%)
slider6:100<0,100,0.01>Mix (%)
slider7:0<-40,40,0.01>Output (-inf/+40dB)
slider8:0<0,1,1{Off,On}>Oversample (x2)

//=================================================
@init
//=================================================
//2*pi
pi2 = 2*$pi;

//sim resistance
r = 0.85;

//fir restoration filter
c1 = 1;
c2 = -0.75;
c3 = 0.17;
fgain = 4;

//fir bandlimit
bl_c1 = 0.52;
bl_c2 = 0.54;
bl_c3 = -0.02;

//=================================================
@slider
//=================================================
mono = slider1;

os = slider8;

sx = 16+slider3*1.20103;
tgt_f = floor(exp(sx*log(1.059))*8.17742);

fb = slider4/100;
tgt_mix = slider6/100;
diode = slider2;
nl = slider5;

slider7 == -40 ? outgain = 0 : outgain = 10^(slider7/20);

//=================================================
@block
//=================================================
//interpolate 'f'
d_f = (tgt_f-src_f)/samplesblock;
tf = src_f;
src_f = tgt_f;

//interpolate 'mix'
d_mix = (tgt_mix-src_mix)/samplesblock;
tmix = src_mix;
src_mix = tgt_mix;

@sample
//=================================================
// set mod signal
//=================================================
//a couple of pseudo non-linearities for 'f' and 'fb'
nl > 0 ? (
nl_f = rand(4*nl)-2*nl;
nl_fb = (rand(2*nl)-nl)*0.001;
) : (
nl_f = nl_fb = 0;
);

//interpolate 'f'
tf += d_f;

//interpolate 'mix'
tmix += d_mix;

//mod signal gen
sina = pi2*(tf-nl_f)/srate;
sinout = sin(sinp);
sinp = sinp+sina;
sinp >= pi2 ? sinp -= pi2;

//diode - positive semi-periods
diode == 0 ? (
  m_out = sinout;
) : (
  //os - diode-ed signal?
  os == 0 ? (
    //abs()
    d_sin = abs(sinout)*2-0.20260;
  ) : (
    //power series in
    ps_sin_out1 = 0.5*(sinout+ps_sin_out2);
    ps_sin_out2 = 0.5*ps_sin_out1;
    //abs()
    ps_d_sin1 = abs(ps_sin_out1)*2-0.20260;
    ps_d_sin2 = abs(ps_sin_out2)*2-0.20260;
    //bandlimit    
    sin_bl3_1 = sin_bl2_1;
    sin_bl3_2 = sin_bl2_2;
    sin_bl2_1 = sin_bl1_1;
    sin_bl2_2 = sin_bl1_2;
    sin_bl1_1 = ps_d_sin1;
    sin_bl1_2 = ps_d_sin2;
    sin_bl_out1 = (sin_bl1_1*bl_c1 + sin_bl2_1*bl_c2 + sin_bl3_1*bl_c3);
    sin_bl_out2 = (sin_bl1_2*bl_c1 + sin_bl2_2*bl_c2 + sin_bl3_2*bl_c3);
    //power series out
    o_sin_out1 = 0.5*(sin_bl_out1+o_sin_out2);
    o_sin_out2 = 0.5*(sin_bl_out2+o_sin_out1);  
    //fir restoration
    s3 = s2;  
    s2 = s1;
    s1 = o_sin_out1;
    d_sin = (s1*c1+s2*c2+s3*c3)*fgain;   
  );
  m_out = d_sin
);

//no feedback?
fb == 0 ? nl_fb = 0;

//=================================================
//fx mono
//=================================================
mono == 1 ? (

//-------------------------------------------------
//input
//-------------------------------------------------
in_l = (spl0+spl1)/2;

//-------------------------------------------------
//os - no 
//-------------------------------------------------
os == 0 ? (

//feedback ala Paul Kellet
fp_l = (in_l+(fb-nl_fb)*fp_l)*sinout*r;
//multiply carrier with mod
s_out_l = m_out*in_l;
//apply feedback
s_out_l += fp_l;

fx_outl = s_out_l;

) : (

//-------------------------------------------------
//os - yes 
//-------------------------------------------------

//power series in
ps_fx_out1l = 0.5*(in_l+ps_fx_out2l);
ps_fx_out2l = 0.5*ps_fx_out1l;

//------------------------
//fx
//------------------------
fp_l_os_1 = (ps_fx_out1l+(fb-nl_fb)*fp_l_os_1)*sinout*r;
s_out_l_os_1 = m_out*ps_fx_out1l;
s_out_l_os_1 += fp_l_os_1;

fp_l_os_2 = (ps_fx_out2l+(fb-nl_fb)*fp_l_os_2)*sinout*r;
s_out_l_os_2 = m_out*ps_fx_out2l;
s_out_l_os_2 += fp_l_os_2;

//------------------------
//bandlimit
//------------------------
bl3_1 = bl2_1;
bl3_2 = bl2_2;

bl2_1 = bl1_1;
bl2_2 = bl1_2;

bl1_1 = s_out_l_os_1;
bl1_2 = s_out_l_os_2;

bl_out1 = (bl1_1*bl_c1 + bl2_1*bl_c2 + bl3_1*bl_c3);
bl_out2 = (bl1_2*bl_c1 + bl2_2*bl_c2 + bl3_2*bl_c3);

//------------------------
//power series out
//------------------------
o_fx_out1l = 0.5*(bl_out1+o_fx_out2l);
o_fx_out2l = 0.5*(bl_out2+o_fx_out1l);  

//fir restoration
s3l = s2l;  
s2l = s1l;
s1l = o_fx_out1l;

fx_outl = (s1l*c1+s2l*c2+s3l*c3)*fgain;

);

//------------------------
//mixer
//------------------------
out_l = fx_outl*(tmix)+in_l*(1-tmix);
spl1 = spl0 = out_l*r*outgain;

):(
//=================================================
//fx stereo
//=================================================

in_l = spl0;
in_r = spl1;

//-------------------------------------------------
//os - no 
//-------------------------------------------------
os == 0 ? (

fp_l = (in_l+(fb-nl_fb)*fp_l)*sinout*r;
s_out_l = m_out*in_l;
s_out_l += fp_l;
out_l = s_out_l*(tmix)+in_l*(1-tmix);
fx_outl = out_l*r*outgain;

fp_r = (in_r+(fb-nl_fb)*fp_r)*sinout*r;
s_out_r = m_out*in_r;
s_out_r += fp_r;
out_r = s_out_r*(tmix)+in_r*(1-tmix);
fx_outr = out_r*r*outgain;

) : (

//-------------------------------------------------
//os - yes 
//-------------------------------------------------

//power series in
ps_fx_out1l = 0.5*(in_l+ps_fx_out2l);
ps_fx_out2l = 0.5*ps_fx_out1l;

ps_fx_out1r = 0.5*(in_r+ps_fx_out2r);
ps_fx_out2r = 0.5*ps_fx_out1r;

//------------------------
//fx
//------------------------
fp_l_os_1 = (ps_fx_out1l+(fb-nl_fb)*fp_l_os_1)*sinout*r;
s_out_l_os_1 = m_out*ps_fx_out1l;
s_out_l_os_1 += fp_l_os_1;

fp_l_os_2 = (ps_fx_out2l+(fb-nl_fb)*fp_l_os_2)*sinout*r;
s_out_l_os_2 = m_out*ps_fx_out2l;
s_out_l_os_2 += fp_l_os_2;

fp_r_os_1 = (ps_fx_out1r+(fb-nl_fb)*fp_r_os_1)*sinout*r;
s_out_r_os_1 = m_out*ps_fx_out1r;
s_out_r_os_1 += fp_r_os_1;

fp_r_os_2 = (ps_fx_out2r+(fb-nl_fb)*fp_r_os_2)*sinout*r;
s_out_r_os_2 = m_out*ps_fx_out2r;
s_out_r_os_2 += fp_r_os_2;

//------------------------
//bandlimit
//------------------------
bl3_l1 = bl2_l1;
bl3_r1 = bl2_r1;
bl3_l2 = bl2_l2;
bl3_r2 = bl2_r2;

bl2_l1 = bl1_l1;
bl2_r1 = bl1_r1;
bl2_l2 = bl1_l2;
bl2_r2 = bl1_r2;

bl1_l1 = s_out_l_os_1;
bl1_r1 = s_out_r_os_1;
bl1_l2 = s_out_l_os_2;
bl1_r2 = s_out_r_os_2;

bl_out1l = (bl1_l1*bl_c1 + bl2_l1*bl_c2 + bl3_l1*bl_c3);
bl_out1r = (bl1_r1*bl_c1 + bl2_r1*bl_c2 + bl3_r1*bl_c3);
bl_out2l = (bl1_l2*bl_c1 + bl2_l2*bl_c2 + bl3_l2*bl_c3);
bl_out2r = (bl1_r2*bl_c1 + bl2_r2*bl_c2 + bl3_r2*bl_c3);

//------------------------
//power series out
//------------------------
o_fx_out1l = 0.5*(bl_out1l+o_fx_out2l);
o_fx_out2l = 0.5*(bl_out2l+o_fx_out1l);  

o_fx_out1r = 0.5*(bl_out1r+o_fx_out2r);
o_fx_out2r = 0.5*(bl_out2r+o_fx_out1r);  

//------------------------
//fir restoration
//------------------------
s3l = s2l;  
s2l = s1l;
s1l = o_fx_out1l;
fx_outl = (s1l*c1+s2l*c2+s3l*c3)*fgain;

s3r = s2r;  
s2r = s1r;
s1r = o_fx_out1r;
fx_outr = (s1r*c1+s2r*c2+s3r*c3)*fgain;

);

//------------------------
//mixer
//------------------------
out_l = fx_outl*(tmix)+in_l*(1-tmix);
out_r = fx_outr*(tmix)+in_r*(1-tmix);
spl0 = out_l*r*outgain;
spl1 = out_r*r*outgain;

);

//=================================================
@gfx 100 10
//=================================================
//draw 'f'
gfx_x=gfx_y=5;
gfx_lineto(gfx_x, gfx_y,0);
gfx_r=gfx_b=0.5;
gfx_g=0.7;
gfx_a=1;
gfx_drawchar($'M');
gfx_drawchar($'O');
gfx_drawchar($'D');
gfx_drawchar($' ');
gfx_drawchar($'F');
gfx_drawchar($' ');
gfx_drawchar($'=');
gfx_drawchar($' ');
gfx_drawnumber(tgt_f,0);
gfx_drawchar($' ');
gfx_drawchar($'H');
gfx_drawchar($'z');
//draw diode picture
diode == 0 ? gfx_r=gfx_g=gfx_b=0.4;
padx = 385;
pady = 7;
gfx_y = gfx_y+8;
gfx_x = padx-50;
gfx_drawchar($'M');
gfx_drawchar($'O');
gfx_drawchar($'D');
gfx_drawchar($'~');
gfx_x = padx;
gfx_y = pady;
gfx_lineto(padx,pady+20,0);
gfx_lineto(padx+15,pady+10,0);
gfx_lineto(padx,pady,0);
gfx_x = padx+15;
gfx_y = pady;
gfx_lineto(padx+15,pady+20,0);
gfx_x = padx-10;
gfx_y = pady+10;
gfx_lineto(padx,pady+10,0);
gfx_x = padx+15;
gfx_lineto(padx+30,pady+10,0);