Skip to content

Commit

Permalink
protosynth: add feedback for fm-like nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Apr 14, 2024
1 parent ad3047b commit f92aa51
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 41 deletions.
43 changes: 22 additions & 21 deletions protosynth/protosynth_dependencies/saike_proto_synth_fx.jsfx-inc
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,18 @@ global(
);


function freq_shift_audio_rate(in, shift)
function freq_shift_audio_rate(in, shift, fb)
instance(
fs_l1, fs_r1, fs_l2, fs_r2,
fs_l1, fs_r1, fs_l2, fs_r2, ly,
dt2, t2,
)
local(ct2, st2)
global(tpiT, fs.ct1, fs.st1)
(
t2 += 1.5771 + tpiT * shift; // oscillating at srate / 4 (2.0 * $pi * 0.251)
t2 += 1.5771 + tpiT * (shift + fb * ly); // oscillating at srate / 4 (2.0 * $pi * 0.251)
(t2 > 628.32) ? t2 -= 628.32; // 200 * $pi;

fs_l1.quick_ellip(in * fs.ct1) * cos(t2) + fs_l2.quick_ellip(in * fs.st1) * sin(t2)
ly = fs_l1.quick_ellip(in * fs.ct1) * cos(t2) + fs_l2.quick_ellip(in * fs.st1) * sin(t2)
);

function poisson_noise(in_left, in_right, freq, polarity)
Expand Down Expand Up @@ -278,7 +278,7 @@ instance(lpf, lpf2, lpf3, lpf4, lpf5)
<?
function input(sample2)
(
printf("this.buf1.read_cheapo(fm_offset + (max(-fm_offset, fm_factor * %s)))", sample2);
printf("this.buf1.read_cheapo(fm_offset + (max(-fm_offset, fm_factor * (%s))))", sample2);
);

function input2(sample2, sample3)
Expand All @@ -292,7 +292,7 @@ instance(lpf, lpf2, lpf3, lpf4, lpf5)
);
?>

function process_phasemod(x1, x2, ifreq)
function process_phasemod(x1, x2, ifreq, feedback)
local(y, y1, y2, y3, fm_factor)
global(osc_feedback1, fm_offset, fm_scaling)
instance(last_x1, last_x2, write_ptr, lpf, lpf2, y4)
Expand All @@ -302,14 +302,15 @@ instance(last_x1, last_x2, write_ptr, lpf, lpf2, y4)

fm_factor = fm_scaling * ifreq;

y1 = <?input("this.buf2.read_cheapo(fm_offset + 1) + osc_feedback1 * y4")?>;
y2 = <?input("this.buf2.read_cheapo(fm_offset + 0.75) + osc_feedback1 * y1")?>;
y3 = <?input("this.buf2.read_cheapo(fm_offset + 0.5) + osc_feedback1 * y2")?>;
y4 = <?input("this.buf2.read_cheapo(fm_offset + 0.25) + osc_feedback1 * y3")?>;
y1 = <?input("this.buf2.read_cheapo(fm_offset + 1) + feedback * y4")?>;
y2 = <?input("this.buf2.read_cheapo(fm_offset + 0.75) + feedback * y1")?>;
y3 = <?input("this.buf2.read_cheapo(fm_offset + 0.5) + feedback * y2")?>;
y4 = <?input("this.buf2.read_cheapo(fm_offset + 0.25) + feedback * y3")?>;

this.elliptic_4x(y1);
this.elliptic_4x(y2);
this.elliptic_4x(y3);
this.elliptic_4x(y3);
y = this.elliptic_4x(y4);

last_x1 = x1;
Expand All @@ -318,20 +319,20 @@ instance(last_x1, last_x2, write_ptr, lpf, lpf2, y4)
y
);

function process_phasemod2(x1, x2, ifreq)
function process_phasemod2(x1, x2, ifreq, feedback)
local(y, fm_factor, xx2, y1, y2, y3)
global(osc_feedback1, fm_offset, fm_scaling)
global(fm_offset, fm_scaling)
instance(last_x1, last_x2, write_ptr, lpf, lpf2, lifreq, y4)
(
this.buf1.write_simple_buffer(x1);
fm_factor = fm_scaling * ifreq;

xx2 = lpf2.eval_linearSVF_LP(lpf.eval_linearSVF_LP(x2));

y1 = <?input2("last_x2", "osc_feedback1 * y4")?>;
y2 = <?input2("last_x2 * 0.75 + xx2 * 0.25", "osc_feedback1 * y1")?>;
y3 = <?input2("last_x2 * 0.5 + xx2 * 0.5", "osc_feedback1 * y2")?>;
y4 = <?input2("last_x2 * 0.25 + xx2 * 0.75", "osc_feedback1 * y3")?>;
y1 = <?input2("last_x2", "feedback * y4")?>;
y2 = <?input2("last_x2 * 0.75 + xx2 * 0.25", "feedback * y1")?>;
y3 = <?input2("last_x2 * 0.5 + xx2 * 0.5", "feedback * y2")?>;
y4 = <?input2("last_x2 * 0.25 + xx2 * 0.75", "feedback * y3")?>;

this.elliptic_4x(y1);
this.elliptic_4x(y2);
Expand All @@ -344,7 +345,7 @@ instance(last_x1, last_x2, write_ptr, lpf, lpf2, lifreq, y4)
y
);

function process_phasemod3(x1, x2, ifreq)
function process_phasemod3(x1, x2, ifreq, feedback)
local(y, fm_factor, xx2, y1, y2, y3)
global(osc_feedback1, fm_offset, fm_scaling)
instance(last_x1, last_x2, write_ptr, lpf, lpf2, lifreq, y4)
Expand All @@ -354,10 +355,10 @@ instance(last_x1, last_x2, write_ptr, lpf, lpf2, lifreq, y4)

xx2 = lpf2.eval_linearSVF_LP(lpf.eval_linearSVF_LP(x2));

y1 = <?input3("last_x2", "osc_feedback1 * y4")?>;
y2 = <?input3("last_x2 * 0.75 + xx2 * 0.25", "osc_feedback1 * y1")?>;
y3 = <?input3("last_x2 * 0.5 + xx2 * 0.5", "osc_feedback1 * y2")?>;
y4 = <?input3("last_x2 * 0.25 + xx2 * 0.75", "osc_feedback1 * y3")?>;
y1 = <?input3("last_x2", "feedback * y4")?>;
y2 = <?input3("last_x2 * 0.75 + xx2 * 0.25", "feedback * y1")?>;
y3 = <?input3("last_x2 * 0.5 + xx2 * 0.5", "feedback * y2")?>;
y4 = <?input3("last_x2 * 0.25 + xx2 * 0.75", "feedback * y3")?>;

this.elliptic_4x(y1);
this.elliptic_4x(y2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ instance(
change_amount_modulated,
display_value,
_me,
bidi_slider,
)
global(
x_offset, y_offset, blit_scale,
Expand Down Expand Up @@ -748,16 +749,26 @@ global(
cap_mode = me;
);

ix = x + 2;
loop(floor(0.5 * (w - 3)),
(ix - x) <= floor(x_norm * w) ? (
colormodel(color);
active ? (gfx_a = 0.6) : (gfx_a = 0.2)
bidi_slider ? (
ix = x + 2;
colormodel(color);
(x_norm > 0.5) ? (
gfx_rect(x + 0.5 * w, y + 2, 0.5 * x_norm * w - 2, 1);
) : (
gfx_set(0, 0, 0, 0.2);
gfx_rect(x + x_norm * w + 2, y + 2, floor((0.5 - x_norm) * w - 0.0001), 1);
);
) : (
ix = x + 2;
loop(floor(0.5 * (w - 3)),
(ix - x) <= floor(x_norm * w) ? (
colormodel(color);
active ? (gfx_a = 0.6) : (gfx_a = 0.2)
) : (
gfx_set(0, 0, 0, 0.2);
);
gfx_line(ix, y + 2, ix, y + h - 3);
ix += 2;
);
gfx_line(ix, y + 2, ix, y + h - 3);
ix += 2;
);

((cap_mode == me) || change_amount_modulated) ? (
Expand Down
77 changes: 65 additions & 12 deletions protosynth/saike_protosynth.jsfx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ slider163:f4_keyfollow=0<0,1,0.00001>-Output Key follow
par += 1; i += 1;
);
?>

slider239:fb1=0<-0.999,0.999,.0001>-fb1
slider240:fb2=0<-0.999,0.999,.0001>-fb2
slider241:fb3=0<-0.999,0.999,.0001>-fb3
slider242:fb4=0<-0.999,0.999,.0001>-fb4
slider243:fb21=0<-0.999,0.999,.0001>-fb21
slider244:fb22=0<-0.999,0.999,.0001>-fb22
slider245:fb31=0<-0.999,0.999,.0001>-fb31

slider246:glide_time=100<3,3000,0.001:log>-glide time
slider247:poisson_freq=500<20, 10000, 0.01:log>-poisson_freq

Expand Down Expand Up @@ -241,6 +250,14 @@ poisson_slider.init_slider_ui(247, 20, 10000, 1);
time_slider.init_slider_ui(248, 5, 2800, 1);
verb_mix_slider.init_slider_ui(249, 0, 1, 0);

<?
i = 0;
loop(7,
printf("f_fb_slider%d.init_slider_ui(%d, -0.999, 0.999, 0);", i, 239 + i);
printf("f_fb_slider%d.bidi_slider = 1;", i);
i += 1;
);
?>
<?
par2 = 164;
loop(i=0;8,
Expand Down Expand Up @@ -758,6 +775,7 @@ global(
mix_mode1, mix_mode2, mix_mode3, mix_mode4,
mix_mode21, mix_mode22,
mix_mode31,
fb1, fb2, fb3, fb4, fb21, fb22, fb31,
filter1_enabled, filter2_enabled, filter3_enabled,
current_f3_gain,
<?loop(i=1;N_OSCS, printf("osc%d_enabled, ", i); i += 1; );?>
Expand All @@ -781,10 +799,10 @@ instance(
: (mix_mode%d == 3) ? (min(max(o%d, o%d), min(o%d, o%d)))
: (mix_mode%d == 4) ? (t1 = o%d + o%d; t2 = o%d - o%d; min(max(t1, t2), -min(t1, t2)))
: (mix_mode%d == 5) ? (mix%d.process_stft_mixer(o%d, o%d); mix%d.out_left)
: (mix_mode%d == 6) ? (this.ofs%d.freq_shift_audio_rate(o%d, 16 * this.freq * o%d))
: (mix_mode%d == 7) ? (mix%d.process_phasemod(o%d, o%d, osc%d.current_ifreq))
: (mix_mode%d == 8) ? (mix%d.process_phasemod2(o%d, o%d, osc%d.current_ifreq))
: (mix_mode%d == 9) ? (mix%d.process_phasemod3(o%d, o%d, osc%d.current_ifreq));
: (mix_mode%d == 6) ? (this.ofs%d.freq_shift_audio_rate(o%d, 16 * this.freq * o%d, this.freq * fb%d))
: (mix_mode%d == 7) ? (mix%d.process_phasemod(o%d, o%d, osc%d.current_ifreq, fb%d))
: (mix_mode%d == 8) ? (mix%d.process_phasemod2(o%d, o%d, osc%d.current_ifreq, fb%d))
: (mix_mode%d == 9) ? (mix%d.process_phasemod3(o%d, o%d, osc%d.current_ifreq, fb%d));
",
mix_out,
mix_id, o1, o2,
Expand All @@ -793,10 +811,10 @@ instance(
mix_id, o1, o2, o1, o2,
mix_id, o1, o2, o1, o2,
mix_id, mix_id, o1, o2, mix_id,
mix_id, mix_id, o1, o2,
mix_id, mix_id, o1, o2, o1,
mix_id, mix_id, o1, o2, o1,
mix_id, mix_id, o1, o2, o1
mix_id, mix_id, o1, o2, mix_id,
mix_id, mix_id, o1, o2, o1, mix_id,
mix_id, mix_id, o1, o2, o1, mix_id,
mix_id, mix_id, o1, o2, o1, mix_id
);
);
?>
Expand Down Expand Up @@ -1026,7 +1044,7 @@ verb.reset_verb();
midi.reset_midi();
<?loop(i=0;MAX_VOICES, printf("v%d.process_midi(i, 0, 0, 0, -1, 0);", i, i); i += 1);?>

CURRENT_VERSION = 11;
CURRENT_VERSION = 12;
version = CURRENT_VERSION;

@serialize
Expand Down Expand Up @@ -1174,6 +1192,10 @@ f_morph_slider4.serialize_if(version, 8);
reverb_algorithm = 0;
);

(version < 12) ? (
fb1 = fb2 = fb3 = fb4 = fb21 = fb22 = fb31 = 0;
);

version = CURRENT_VERSION;

@slider
Expand Down Expand Up @@ -1788,6 +1810,8 @@ global(gfx_a, gfx_x, gfx_y, mouse_x, mouse_y, x_offset, y_offset, blit_scale, ca
);
);
);


);

function cline(x1, y1, x2, y2)
Expand All @@ -1807,27 +1831,40 @@ cy = start;
over_filter = 0;
over_osc = 0;

mnode = 1;
//input_size =
<?
loop(i=0;8,
printf("n1%d.node(cx, cy, block_size, block_size, 0, 0);", i);
printf("n1%d.over ? (over_osc = %d; (last_cap == 0 && mouse_cap == 1) ? osc%d_enabled = 1 - osc%d_enabled; );", i, i + 1, i + 1, i + 1);

printf("osc%d_enabled ? gfx_rect(cx, cy, block_size, block_size);", i + 1);
printf("cy += block_size + 2;");
i += 1;
);
?>

function has_feedback(v)
(
(v > 5) && (v < 10);
);

cx = left_side + block_size + spacing;
cy = start + 0.5 * (block_size + 2);
// LAST
<?
current_slider = 128; /* First mix slider */
loop(i=0;4,
printf("n2%d.mix_node(cx, cy, 2 * block_size + 2, block_size, %d);", i, current_slider);

printf("has_feedback(mix_mode%d) ? (", i + 1);
printf("f_fb_slider%d.active = 1;", mnode);
printf("f_fb_slider%d.color = 0.1;", mnode);
printf("f_fb_slider%d.text_slider_ui(%d, cx, cy + block_size + 1, 2 * block_size + 2, 5, \"\", \"Feedback\", sprintf(1, \"Feedbk (%%d)\", 100 * f_fb_slider%d.display_value));", mnode, uuid(), mnode);
printf(");", i);

printf("cy += 2 * (block_size + 2);");
i += 1;
i += 1; mnode += 1;
current_slider += 1;
);
?>
Expand All @@ -1838,8 +1875,15 @@ cy = start + 0.5 * 3 * (block_size + 2);
<?
loop(i=0;2,
printf("n3%d.mix_node(cx, cy, 2 * block_size + 2, block_size, %d);", i, current_slider);

printf("has_feedback(mix_mode2%d) ? (", i + 1);
printf("f_fb_slider%d.active = 1;", mnode);
printf("f_fb_slider%d.color = 0.1;", mnode);
printf("f_fb_slider%d.text_slider_ui(%d, cx, cy + block_size + 1, 2 * block_size + 2, 5, \"\", \"Feedback\", sprintf(1, \"Feedbk (%%d)\", 100 * f_fb_slider%d.display_value));", mnode, uuid(), mnode);
printf(");", i);

printf("cy += 4 * (block_size + 2);");
i += 1;
i += 1; mnode += 1;
current_slider += 1;
);
?>
Expand All @@ -1861,6 +1905,15 @@ cx = left_side + 7 * block_size + 4 * spacing;
cy = start + 3.5 * (block_size + 2);
n5.mix_node(cx, cy, 2 * block_size + 2, block_size, 134);

<?
i = 0;
printf("has_feedback(mix_mode2%d) ? (", i + 1);
printf("f_fb_slider%d.active = 1;", mnode);
printf("f_fb_slider%d.color = 0.1;", mnode);
printf("f_fb_slider%d.text_slider_ui(%d, cx, cy + block_size + 1, 2 * block_size + 2, 5, \"\", \"Feedback\", sprintf(1, \"Feedbk (%%d)\", 100 * f_fb_slider%d.display_value));", mnode, uuid(), mnode);
printf(");", i);
?>

cy += 4 * (block_size + 2);
cx += 2 * block_size + spacing;
cy = start + 3.5 * (block_size + 2);
Expand Down

0 comments on commit f92aa51

Please sign in to comment.