Skip to content

Commit

Permalink
Release JSAdditiv v1.3
Browse files Browse the repository at this point in the history
1.3
replace zdf with rbj filters
fix note clicking 
fix volume knob clicking
1.2
Fix support large wave files
Fix import wave samplerate
Support file drag and drop
  • Loading branch information
tiagolr committed Dec 27, 2023
1 parent ccfd834 commit 724521d
Show file tree
Hide file tree
Showing 4 changed files with 478 additions and 476 deletions.
117 changes: 45 additions & 72 deletions Synth/tilr_JSAdditiv.jsfx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
desc: JSAdditiv
author: tilr
version: 1.2
version: 1.3
changelog:
1.3
replace zdf with rbj filters
fix note clicking
fix volume knob clicking
1.2
Fix support large wave files
Fix import wave samplerate
Support file drag and drop
Expand All @@ -12,7 +17,6 @@ provides:
tilr_JSAdditiv/add.gfxlib.jsfx-inc
tilr_JSAdditiv/add.mouselib.jsfx-inc
tilr_JSAdditiv/add.wavetable.jsfx-inc
tilr_JSAdditiv/add.zdf_filter.jsfx-inc
[data] tilr_JSAdditiv/Complex 1.wav
[data] tilr_JSAdditiv/Complex 2.wav
[data] tilr_JSAdditiv/Complex 3.wav
Expand All @@ -38,6 +42,7 @@ provides:
[data] tilr_JSAdditiv/Square 2.wav
[data] tilr_JSAdditiv/Stairs.wav
[data] tilr_JSAdditiv/Triangle.wav
tilr_JSAdditiv/add.rbj_filter.jsfx-inc
screenshot: https://raw.githubusercontent.com/tiagolr/JSAdditiv/master/doc/ss.png
about:
# JSAdditiv
Expand Down Expand Up @@ -84,7 +89,7 @@ slider26:pitch_rel=500<1, 5000, 1:log>-Pitch Release
import add.wavetable.jsfx-inc
import add.array.jsfx-inc
import add.adsr.jsfx-inc
import add.zdf_filter.jsfx-inc
import add.rbj_filter.jsfx-inc
import add.gfxlib.jsfx-inc
import add.mouselib.jsfx-inc
import add.fft_real_synth.jsfx-inc
Expand Down Expand Up @@ -120,6 +125,20 @@ function db2gain (db) local (val) (
function normalize_vol_slider(val) ( val * 60 / 100 - 60 );
function note2freq(n) ( 440 * pow(2, (n - 69) / 12); );

function rc_set(rc)
instance(a) (
a = 1 / (rc * srate + 1);
);
function rc_lp(sample)
instance(lp, a) (
lp += a * (sample - lp);
);
function smooth()
instance (lp, smooth) (
lp = smooth;
smooth = this.rc_lp(this);
);

function normalize_wave(buf, len)
local (_min, _max, i)
(
Expand Down Expand Up @@ -189,7 +208,7 @@ function resynthesize() (
semi_normalize_wave(wavebuf, four.size * 2); // correct signal strenght after summing frequencies
);

function read_file(filehandle)
function read_file(filehandle)
local (len)
(
filehandle > 0 ? (
Expand Down Expand Up @@ -226,58 +245,12 @@ function read_file_string(str) (
read_file(filehandle);
);

// copy filter coeficients from buffer1 to buffer2
function filter_copy_coefs(buf1, buf2) (
buf2[2] = buf1[2];
buf2[3] = buf1[3];
buf2[4] = buf1[4];
);

// wraps filter function using buffers
function filter_setf(buf, freq, q) (
filter.zdf_setf(freq, q);
buf[2] = filter.g;
buf[3] = filter.r2;
buf[4] = filter.h;
);

// wraps filter function using buffers
function filter_lp(buf, sample) local(lp) (
filter.s1 = buf[0];
filter.s2 = buf[1];
filter.g = buf[2];
filter.r2 = buf[3];
filter.h = buf[4];
lp = filter.zdf_svf_lp(sample);
buf[0] = filter.s1;
buf[1] = filter.s2;
lp;
);

// wraps filter function using buffers
function filter_bp(buf, sample) local(bp) (
filter.s1 = buf[0];
filter.s2 = buf[1];
filter.g = buf[2];
filter.r2 = buf[3];
filter.h = buf[4];
bp = filter.zdf_svf_bp(sample);
buf[0] = filter.s1;
buf[1] = filter.s2;
bp;
);

// wraps filter function using buffers
function filter_hp(buf, sample) local(hp) (
filter.s1 = buf[0];
filter.s2 = buf[1];
filter.g = buf[2];
filter.r2 = buf[3];
filter.h = buf[4];
hp = filter.zdf_svf_hp(sample);
buf[0] = filter.s1;
buf[1] = filter.s2;
hp;
function copy_filter_coefs (f1, f2) (
f2[0] = f1[0]; // a1
f2[1] = f1[1]; // a2
f2[2] = f1[2]; // b0
f2[3] = f1[3]; // b1
f2[4] = f1[4]; // b2
);

function on_slider() (
Expand All @@ -296,6 +269,10 @@ function on_slider() (
// FIX - read initial wave from string instead of slider
read_file_string("tilr_JSAdditiv/Sine 1.wav");

// Init smoothing
gain.rc_set(0.0033);
gain.smooth = db2gain(normalize_vol_slider(vol));

@serialize
file_var(0, osc_free);
file_mem(0, wavebuf, wavelen + four.size * 4);
Expand Down Expand Up @@ -395,6 +372,7 @@ while (midirecv(offset, msg1, note, vel)) (
);

@sample
gain.smooth();

ptr = poly.array_first();
while(ptr >= 0) ( // for each note/voice
Expand Down Expand Up @@ -430,34 +408,29 @@ while(ptr >= 0) ( // for each note/voice
flt_shape != 0 ? (
filterbuf = filter_env + ptr[0] * 7; // envelope buffer
adsr_process(filterbuf);
filterbuf_l = filter_arr_l + ptr[0] * 11; // filter buffer left
filterbuf_r = filter_arr_r + ptr[0] * 11; // filter buffer right
multiplier = pow(20000/flt_freq, filterbuf[0] * flt_amt / 100);

filter_setf(filterbuf_l, flt_freq * multiplier, flt_q);
filter_copy_coefs(filterbuf_l, filterbuf_r);
filterbuf_l = filter_arr_l + ptr[0] * 11; // filter buffer left
filterbuf_r = filter_arr_r + ptr[0] * 11; // filter buffer left

flt_shape == 1 ? (
outl = filter_lp(filterbuf_l, outl);
outr = filter_lp(filterbuf_r, outr);
flt_shape == 1 ? (
rbj_lp(filterbuf_l, flt_freq * multiplier, flt_q);
) : flt_shape == 2 ? (
outl = filter_bp(filterbuf_l, outl);
outr = filter_bp(filterbuf_r, outr);
rbj_bp(filterbuf_l, flt_freq * multiplier, flt_q);
) : (
outl = filter_hp(filterbuf_l, outl);
outr = filter_hp(filterbuf_r, outr);
rbj_hp(filterbuf_l, flt_freq * multiplier, flt_q);
);
copy_filter_coefs(filterbuf_l, filterbuf_r);
outl = rbj_df1(filterbuf_l, outl);
outr = rbj_df1(filterbuf_r, outr);
);

spl0 += outl * gain;
spl1 += outr * gain;
spl0 += outl * gain.smooth;
spl1 += outr * gain.smooth;

ptr = poly.array_next(ptr);
);

spl0 += outl * gain;
spl1 += outr * gain;

@gfx 520 270

gfx_clear = COLOR_BG;
Expand Down
1 change: 0 additions & 1 deletion Synth/tilr_JSAdditiv/add.gfxlib.jsfx-inc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ local (harm_w, amp, i, mouse_active, hx, ph, yamp, phase, real, img, yphase)
);
phase_mode && mouse_active && mouse_in_rect(hx, y, harm_w, h) ? (
yphase = mouse.control ? 0 : (mouse.y - y) / h * -2 - 1;
yphasee = yphase;
amp = harmonic_amplitude(buf[i], buf[i+1]);
buf[i+1] = amp * cos(yphase*$pi); // real
buf[i] = amp * sin(yphase*$pi); // img
Expand Down
Loading

0 comments on commit 724521d

Please sign in to comment.