~rantlivelintkale/extended-drive.lv2

2dc0abfb829c1fe06847169e3f34426e19ce9015 — Veikka Valtteri Kallinen 6 months ago a76cd67
smooth controls
1 files changed, 36 insertions(+), 23 deletions(-)

M src/main.c
M src/main.c => src/main.c +36 -23
@@ 205,31 205,29 @@ static inline void h(float *x)
	*x = 0.5f * (fabsf(*x + 1.f) - fabsf(*x - 1.f));
}

static inline void clip(float *x, float *z, void (*f)(float *),
static inline float clip(const float x, float *z, void (*f)(float *),
		void (*F)(float *))
{
	const float num = *x - *z;
	float y;
	const float num = x - *z;
	if (fabsf(num) > 1e-3f) {
		float F0 = *x;
		float F0 = x;
		float F1 = *z;
		F(&F0);
		F(&F1);
		*z = *x;
		*x = (F0 - F1) / num;
		*z = x;
		y = (F0 - F1) / num;
	} else {
		float y = 0.5f * (*x + *z);
		y = 0.5f * (x + *z);
		f(&y);
		*z = *x;
		*x = y;
		*z = x;
	}
	return y;
}

static inline void mapping(float *x, float *z, const float soft)
static inline float mapping(const float x, float *z, const float soft)
{
	if (soft > 0.f)
		clip(x, z, s, S);
	else
		clip(x, z, h, H);
	return clip(x, z, s, S) * soft + clip(x, z, h, H) * (1.f - soft);
}

/*


@@ 350,6 348,8 @@ typedef struct {
	float dif_z[2];
	float dif_p;
	float dif_g;

	Lpf cf[9];
} Plugin;

/*


@@ 380,7 380,7 @@ static inline void wet_process(float *x, Clf *clf, const float soft)
	float buf[] = { 2.f * *x, 0.f };
	for (uint32_t i = 0; i < 2; i++) {
		ipf_filter(&buf[i], &clf->ipf[0]);
		mapping(&buf[i], &clf->z, soft);
		buf[i] = mapping(buf[i], &clf->z, soft);
		ipf_filter(&buf[i], &clf->ipf[1]);
	}
	*x = buf[0];


@@ 462,6 462,19 @@ static LV2_Handle instantiate(const LV2_Descriptor *descriptor,
		plugin->dif_g = 3.448275862e-5f * (1.f + eps * T) / T;
	}

	// Control smoothing filters
	{
		lpf_set(100.f, plugin->rate_r, &plugin->cf[0]);
		lpf_set(100.f, plugin->rate_r, &plugin->cf[1]);
		lpf_set(100.f, plugin->rate_r, &plugin->cf[2]);
		lpf_set(100.f, plugin->rate_r, &plugin->cf[3]);
		lpf_set(100.f, plugin->rate_r, &plugin->cf[4]);
		lpf_set(100.f, plugin->rate_r, &plugin->cf[5]);
		lpf_set(100.f, plugin->rate_r, &plugin->cf[6]);
		lpf_set(100.f, plugin->rate_r, &plugin->cf[7]);
		lpf_set(100.f, plugin->rate_r, &plugin->cf[8]);
	}

	return (LV2_Handle) plugin;
}



@@ 542,15 555,15 @@ static void run(LV2_Handle instance, uint32_t n_samples)
	}

	{
		float const filter = *plugin->filter;
		float const integration = *plugin->integration > 0.f ? 1.f : 0.f;
		float const bias = *plugin->bias > 0.f ? 1.f : 0.f;
		float const pre = db_co(*plugin->pre);
		float const soft = *plugin->soft;
		float const post = db_co(*plugin->post);
		float const mix = *plugin->mix;
		float const tone = *plugin->tone;
		float const mid = *plugin->mid;
		float const filter      = lpf_process(*plugin->filter, &plugin->cf[0]);
		float const integration = lpf_process(*plugin->integration > 0.f ? 1.f : 0.f, &plugin->cf[1]);
		float const bias        = lpf_process(*plugin->bias > 0.f ? 1.f : 0.f, &plugin->cf[2]);
		float const pre         = lpf_process(db_co(*plugin->pre), &plugin->cf[3]);
		float const soft        = lpf_process(*plugin->soft > 0.f ? 1.f : 0.f, &plugin->cf[4]);
		float const post        = lpf_process(db_co(*plugin->post), &plugin->cf[5]);
		float const mix         = lpf_process(*plugin->mix, &plugin->cf[6]);
		float const tone        = lpf_process(*plugin->tone, &plugin->cf[7]);
		float const mid         = lpf_process(*plugin->mid, &plugin->cf[8]);

		hpf_set(filter, plugin->rate_r, &plugin->hpf[0]);
		hpf_set(1000.f - 500.f * mid, plugin->rate_r, &plugin->hpf[1]);