void ZamEQ2Plugin::d_run(const float** inputs, float** outputs, uint32_t frames)
{
	float srate = d_getSampleRate();

	lowshelf(0, 0, srate, freql, gainl);
        peq(1, 0, srate, freq1, gain1, q1);
        peq(2, 0, srate, freq2, gain2, q2);
        highshelf(3, 0, srate, freqh, gainh);

        for (uint32_t i = 0; i < frames; i++) {
                double tmp,tmpl, tmph;
                double in = inputs[0][i];
                in = sanitize_denormal(in);

                //lowshelf
                tmpl = (gainl == 0.f) ? in : run_filter(0, 0, in);

                //highshelf
                tmph = (gainh == 0.f) ? tmpl : run_filter(3, 0, tmpl);

                //parametric1
                tmp = (gain1 == 0.f) ? tmph : run_filter(1, 0, tmph);

		//parametric2
		tmpl = (gain2 == 0.f) ? tmp : run_filter(2, 0, tmp);

                outputs[0][i] = inputs[0][i];
                outputs[0][i] = (float) tmpl;
		outputs[0][i] *= from_dB(master);
	}
}
float ZamEQ2Plugin::run_filter(int i, int ch, double in)
{
	double out;
	in = sanitize_denormal(in);
	out = in * b0[ch][i] 	+ x1[ch][i] * b1[ch][i]
				+ x2[ch][i] * b2[ch][i]
				- y1[ch][i] * a1[ch][i]
				- y2[ch][i] * a2[ch][i] + 1e-20f;
	out = sanitize_denormal(out);
	x2[ch][i] = sanitize_denormal(x1[ch][i]);
	y2[ch][i] = sanitize_denormal(y1[ch][i]);
	x1[ch][i] = in;
	y1[ch][i] = out;

	return (float) out;
}
Example #3
0
static float runfilter(LV2_Handle instance, float in)
{
	ADelay* a = (ADelay*)instance;

	float out;
	in = sanitize_denormal(in);

	out = a->B0/a->A0*in + a->B1/a->A0*a->state[0] + a->B2/a->A0*a->state[1]
			-a->A1/a->A0*a->state[2] - a->A2/a->A0*a->state[3] + 1e-20;

	a->state[1] = a->state[0];
	a->state[0] = in;
	a->state[3] = a->state[2];
	a->state[2] = out;
	return out;
}
float ZaMultiCompX2Plugin::run_filter(int i, int ch, float in)
{
        in = sanitize_denormal(in);
        w1[ch][i] = sanitize_denormal(w1[ch][i]);
        w2[ch][i] = sanitize_denormal(w2[ch][i]);
	z1[ch][i] = sanitize_denormal(z1[ch][i]);
	z2[ch][i] = sanitize_denormal(z2[ch][i]);

        float out = in * a0[ch][i] 	+ w1[ch][i] * a1[ch][i] + w2[ch][i] * a2[ch][i]
					- z1[ch][i] * b1[ch][i] - z2[ch][i] * b2[ch][i];
	out = sanitize_denormal(out);
        w2[ch][i] = w1[ch][i];
        z2[ch][i] = z1[ch][i];
        w1[ch][i] = in;
	z1[ch][i] = out;
        return out;
}
Example #5
0
void ZamPianoPlugin::run(const float** inputs, float** outputs, uint32_t frames,
				const MidiEvent* midievent, uint32_t midicount)
{
	uint32_t i, j;
	bool signal;
	int gate = 1;
	
	for (i = 0; i < 88; i++) {
		N[i].pbright = pbright;
		N[i].phammer = phammer;
		N[i].pstiff = pstiff;
		N[i].pdetune = pdetune;
		N[i].prevgain = prevgain;
		N[i].prevroom = prevroom;
		N[i].ppanangle = ppanangle;
		N[i].pspatialwidth = pspatialwidth;
		for (j = 0; j < frames; j++) {
			intermed[i][0][j] = 0.f;
			intermed[i][1][j] = 0.f;
		}
	}

	for (i = 0; i < midicount; i++) {
		int type = midievent[i].data[0] & 0xF0;
		int chan = midievent[i].data[0] & 0x0F;
		int n = midievent[i].data[1];
		int v = midievent[i].data[2];
		if (type == 0x90 && chan == 0x0) {
			// NOTE ON
			note[n].state = STRIKE;
			note[n].vel = v / 127.f;
			gate = 0;
		}
		else if (type == 0x80 && chan == 0x0) {
			// NOTE OFF
			gate = 1;
			if (note[n].state != SILENT) {
				note[n].state = RELEASE;
			}
		}
	}

	for (i = 0; i < frames; i++) {
		outputs[0][i] = 0.f;
		outputs[1][i] = 0.f;
	}
	signal = false;
	int k;
	for (k = 0; k < 88; k++) {
		if (note[k].state == SILENT) {
			N[k].pgate = 1.;
			continue;
		}
		signal = true;
		if (note[k].state == STRIKE) {
			//printf("STRIKE: %d\n", k);
			N[k].pfreq = 220. * powf(2., (k-69)/12.);
			N[k].pgain = note[k].vel;
			N[k].pgate = 0.;
			N[k].compute(1, inputs, intermed[k]);
			N[k].pgate = 1.;
			note[k].state++;
		} else if (note[k].state < RELEASE) {
			//printf("SUSTAIN: %d %d\n", k, note[k].state);
			note[k].state++;
		} else if (note[k].state < DECAY) {
			//printf("RELEASE: %d %d\n", k, note[k].state);
			//N[k].pfreq = 440. * powf(2., (k-69)/12.);
			N[k].pgain = 0.;
			//N[k].pgate = 0.;
			//N[k].compute(1, inputs, intermed[k]);
			N[k].pgate = 1.;
			note[k].state++;
		} else if (note[k].state < SILENT) {
			//printf("DECAY: %d %d\n", k, note[k].state);
			note[k].state++;
		}
		N[k].compute(frames, inputs, intermed[k]);	
	}
	for (i = 0; i < 88; i++) {
		for (j = 0; j < frames; j++) {
			outputs[0][j] += intermed[i][0][j] * 0.1;
			outputs[1][j] += intermed[i][1][j] * 0.1;
		}
	}
	for (i = 0; i < frames; i++) {
		if (signal) {
			sanitize_denormal(outputs[0][i]);
			sanitize_denormal(outputs[1][i]);

		} else {
			outputs[0][i] = 0.f;
			outputs[1][i] = 0.f;
		}
	}
}
Example #6
0
void ZaMaximX2Plugin::run(const float** inputs, float** outputs, uint32_t frames)
{
	uint32_t i;
	float N = (float)MAX_SAMPLES;
	float M = (float)MAX_SAMPLES;
	float absx[2];
	float c[2];
	float xmax[2];
	float emax[2];
	float eavg[2];
	float g[2];
	float srate = getSampleRate();
	float alpha = 1.01;
	float a = 1. - exp(log((alpha - 1.) / (alpha)) / (N + 1.));
	float beta = 0.f;
	for (i = 0; i < M; i++) {
		beta += powf(1. - a, N + 1. - i);
	}
	beta /= M;

	float maxx;
	float inL, inR;

	for (i = 0; i < frames; i++) {
		inL = inputs[0][i];
		inR = inputs[1][i];
		absx[0] = fabsf(inL);
		c[0] = MAX(absx[0], (absx[0]-beta*emaxn[0][pose[0]]) / (1. - beta));
		pushsample(&cn[0][0], sanitize_denormal(c[0]), &posc[0]);
		xmax[0] = maxsample(&cn[0][0]);

		if (xmax[0] < emaxn[0][pose[0]]) {
			a = 1000 / (release * srate);
		}
		emax[0] = a*xmax[0] + (1. - a)*emaxn[0][pose[0]];
		eavg[0] = avgall(&emaxn[0][0]);
		if (eavg[0] == 0.f) {
			g[0] = 1.;
		} else {
			g[0] = MIN(1., from_dB(thresdb) / eavg[0]);
		}

		absx[1] = fabsf(inR);
		c[1] = MAX(absx[1], (absx[1]-beta*emaxn[1][pose[1]]) / (1. - beta));
		pushsample(&cn[1][0], sanitize_denormal(c[1]), &posc[1]);
		xmax[1] = maxsample(&cn[1][0]);

		if (xmax[1] < emaxn[1][pose[1]]) {
			a = 1000 / (release * srate);
		} else {
			a = 1. - exp(log((alpha-1.) / (alpha)) / (N + 1.));
		}
		emax[1] = a*xmax[1] + (1. - a)*emaxn[1][pose[1]];
		eavg[1] = avgall(&emaxn[1][0]);
		if (eavg[1] == 0.f) {
			g[1] = 1.;
		} else {
			g[1] = MIN(1., from_dB(thresdb) / eavg[1]);
		}

		maxx = MAX(xmax[0], xmax[1]);
		gainred = MAX(-to_dB(g[0]), -to_dB(g[1]));
		outlevel = sanitize_denormal(to_dB(maxx)) + (ceiling - thresdb);

		outputs[0][i] = inL;
		outputs[1][i] = inR;
		outputs[0][i] = clip(normalise(z[0][posz[0]] * g[0], 0.));
		outputs[1][i] = clip(normalise(z[1][posz[1]] * g[1], 0.));

		pushsample(&z[0][0], sanitize_denormal(inL), &posz[0]);
		pushsample(&emaxn[0][0], sanitize_denormal(emax[0]), &pose[0]);

		pushsample(&z[1][0], sanitize_denormal(inR), &posz[1]);
		pushsample(&emaxn[1][0], sanitize_denormal(emax[1]), &pose[1]);

		emax_old[0] = sanitize_denormal(emax[0]);
		eavg_old[0] = sanitize_denormal(eavg[0]);
		emax_old[1] = sanitize_denormal(emax[1]);
		eavg_old[1] = sanitize_denormal(eavg[1]);
	}
}
void ZaMultiCompX2Plugin::d_run(const float** inputs, float** outputs, uint32_t frames)
{
	float srate = d_getSampleRate();
	float maxxL = maxL;
	float maxxR = maxR;

        int tog1 = (toggle[0] > 0.5f) ? 1 : 0;
        int tog2 = (toggle[1] > 0.5f) ? 1 : 0;
        int tog3 = (toggle[2] > 0.5f) ? 1 : 0;

        int listen1 = (listen[0] > 0.5f) ? 1 : 0;
        int listen2 = (listen[1] > 0.5f) ? 1 : 0;
        int listen3 = (listen[2] > 0.5f) ? 1 : 0;

        set_lp_coeffs(xover1, ONEOVERROOT2, srate, 0, 0);
        set_lp_coeffs(xover1, ONEOVERROOT2, srate, 1, 0);
        set_hp_coeffs(xover1, ONEOVERROOT2, srate, 2, 0);
        set_hp_coeffs(xover1, ONEOVERROOT2, srate, 3, 0);
        set_lp_coeffs(xover2, ONEOVERROOT2, srate, 4, 0);
        set_lp_coeffs(xover2, ONEOVERROOT2, srate, 5, 0);
        set_hp_coeffs(xover2, ONEOVERROOT2, srate, 6, 0);
        set_hp_coeffs(xover2, ONEOVERROOT2, srate, 7, 0);

        set_lp_coeffs(xover1, ONEOVERROOT2, srate, 0, 1);
        set_lp_coeffs(xover1, ONEOVERROOT2, srate, 1, 1);
        set_hp_coeffs(xover1, ONEOVERROOT2, srate, 2, 1);
        set_hp_coeffs(xover1, ONEOVERROOT2, srate, 3, 1);
        set_lp_coeffs(xover2, ONEOVERROOT2, srate, 4, 1);
        set_lp_coeffs(xover2, ONEOVERROOT2, srate, 5, 1);
        set_hp_coeffs(xover2, ONEOVERROOT2, srate, 6, 1);
        set_hp_coeffs(xover2, ONEOVERROOT2, srate, 7, 1);

        for (uint32_t i = 0; i < frames; ++i) {
                float tmp1[2], tmp2[2], tmp3[2], tmp4[2], tmp5[2], tmp6[2];
		float fil1[2], fil2[2], fil3[2], fil4[2];
		float outL[MAX_COMP+1] = {0.f};
		float outR[MAX_COMP+1] = {0.f};
		float inl = sanitize_denormal(inputs[0][i]);
		float inr = sanitize_denormal(inputs[1][i]);
		inl = (fabs(inl) < DANGER) ? inl : 0.f;
		inr = (fabs(inr) < DANGER) ? inr : 0.f;

		int listenmode = 0;

		// Interleaved channel processing
                fil1[0] = run_filter(0, 0, inl);
                fil1[1] = run_filter(0, 1, inr);
                tmp1[0] = run_filter(1, 0, fil1[0]);
                tmp1[1] = run_filter(1, 1, fil1[1]);
		if (tog1)
			run_comp(0, tmp1[0], tmp1[1], &outL[0], &outR[0]);

		tmp2[0] = tog1 ? outL[0] * from_dB(makeup[0]) : tmp1[0];
                tmp2[1] = tog1 ? outR[0] * from_dB(makeup[0]) : tmp1[1];

                fil2[0] = run_filter(2, 0, inl);
                fil2[1] = run_filter(2, 1, inr);
                tmp3[0] = run_filter(3, 0, fil2[0]);
                tmp3[1] = run_filter(3, 1, fil2[1]);
                fil3[0] = run_filter(4, 0, tmp3[0]);
                fil3[1] = run_filter(4, 1, tmp3[1]);
                tmp4[0] = run_filter(5, 0, fil3[0]);
                tmp4[1] = run_filter(5, 1, fil3[1]);
		if (tog2)
			run_comp(1, tmp4[0], tmp4[1], &outL[1], &outR[1]);

                tmp3[0] = tog2 ? outL[1] * from_dB(makeup[1]) : tmp4[0];
                tmp3[1] = tog2 ? outR[1] * from_dB(makeup[1]) : tmp4[1];

                fil4[0] = run_filter(6, 0, inl);
                fil4[1] = run_filter(6, 1, inr);
                tmp5[0] = run_filter(7, 0, fil4[0]);
                tmp5[1] = run_filter(7, 1, fil4[1]);
		if (tog3)
			run_comp(2, tmp5[0], tmp5[1], &outL[2], &outR[2]);

                tmp6[0] = tog3 ? outL[2] * from_dB(makeup[2]) : tmp5[0];
                tmp6[1] = tog3 ? outR[2] * from_dB(makeup[2]) : tmp5[1];


		outputs[0][i] = outputs[1][i] = 0.f;
		if (listen1) {
			listenmode = 1;
			outputs[0][i] += outL[0] * tog1*from_dB(makeup[0])
					+ (1.-tog1) * tmp1[0];
			outputs[1][i] += outR[0] * tog1*from_dB(makeup[0])
					+ (1.-tog1) * tmp1[1];
		}
		if (listen2) {
			listenmode = 1;
			outputs[0][i] += outL[1] * tog2*from_dB(makeup[1])
					+ (1.-tog2) * tmp4[0];
			outputs[1][i] += outR[1] * tog2*from_dB(makeup[1])
					+ (1.-tog2) * tmp4[1];
		}
		if (listen3) {
			listenmode = 1;
			outputs[0][i] += outL[2] * tog3*from_dB(makeup[2])
					+ (1.-tog3) * tmp5[0];
			outputs[1][i] += outR[2] * tog3*from_dB(makeup[2])
					+ (1.-tog3) * tmp5[1];
		}
		if (!listenmode) {
                	outputs[0][i] = tmp2[0] + tmp3[0] + tmp6[0];
                	outputs[1][i] = tmp2[1] + tmp3[1] + tmp6[1];
		}
                outputs[0][i] = sanitize_denormal(outputs[0][i]);
                outputs[1][i] = sanitize_denormal(outputs[1][i]);
                outputs[0][i] *= from_dB(globalgain);
                outputs[1][i] *= from_dB(globalgain);

		tmp1[0] = outputs[0][i];
		tmp1[1] = outputs[1][i];
		run_limit(tmp1[0], tmp1[1], &outL[3], &outR[3]);
		outputs[0][i] = outL[3];
		outputs[1][i] = outR[3];

		if (resetl) {
			maxL = fabsf(outputs[0][i]);
			resetl = false;
		} else {
			maxxL = (fabsf(outputs[0][i]) > maxxL) ? fabsf(outputs[0][i]) : sanitize_denormal(maxxL);
		}
		if (resetr) {
			maxR = fabsf(outputs[1][i]);
			resetr = false;
		} else {
			maxxR = (fabsf(outputs[1][i]) > maxxR) ? fabsf(outputs[1][i]) : sanitize_denormal(maxxR);
		}
        }
	outl = (maxxL <= 0.f) ? -160.f : to_dB(maxxL+limit);
	outr = (maxxR <= 0.f) ? -160.f : to_dB(maxxR+limit);
}
void ZaMultiCompX2Plugin::run_comp(int k, float inL, float inR, float *outL, float *outR)
{
	float srate = d_getSampleRate();
        float width=(knee-0.99f)*6.f;
        float attack_coeff = exp(-1000.f/(attack * srate));
        float release_coeff = exp(-1000.f/(release * srate));
	int stereolink = (stereodet > 0.5f) ? STEREOLINK_MAX : STEREOLINK_AVERAGE;

        float slewfactor = 80.0;//1.f + knee/2.f;
        float cdb=0.f;
        float Lgain = 1.f;
        float Rgain = 1.f;
        float Lxg, Lyg;
        float Rxg, Ryg;
        float Lxl, Lyl, Ly1;
        float Rxl, Ryl, Ry1;

        Lyg = Ryg = 0.f;
	inL = sanitize_denormal(inL);
	inR = sanitize_denormal(inR);
        Lxg = (inL==0.f) ? -160.f : to_dB(fabs(inL));
        Rxg = (inR==0.f) ? -160.f : to_dB(fabs(inR));
        Lxg = sanitize_denormal(Lxg);
        Rxg = sanitize_denormal(Rxg);

        Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb[k]+width/2.f)*(Lxg-thresdb[k]+width/2.f)/(2.f*width);
        Lyg = sanitize_denormal(Lyg);
        Ryg = Rxg + (1.f/ratio-1.f)*(Rxg-thresdb[k]+width/2.f)*(Rxg-thresdb[k]+width/2.f)/(2.f*width);
        Ryg = sanitize_denormal(Ryg);

        if (2.f*(Lxg-thresdb[k])<-width) {
                Lyg = Lxg;
        } else if (2.f*fabs(Lxg-thresdb[k])<=width && Lyg >= old_yg[0][k]) {
	        attack_coeff = exp(-1000.f/(attack*slewfactor * srate));
        } else if (2.f*fabs(Lxg-thresdb[k])<=width && Lyg < old_yg[0][k]) {
                Lyg = thresdb[k] + (Lxg-thresdb[k])/ratio;
                Lyg = sanitize_denormal(Lyg);
        } else if (2.f*(Lxg-thresdb[k])>width) {
                Lyg = thresdb[k] + (Lxg-thresdb[k])/ratio;
                Lyg = sanitize_denormal(Lyg);
        }


        if (2.f*(Rxg-thresdb[k])<-width) {
                Ryg = Rxg;
        } else if (2.f*fabs(Rxg-thresdb[k])<=width && Ryg >= old_yg[1][k]) {
	        attack_coeff = exp(-1000.f/(attack*slewfactor * srate));
        } else if (2.f*fabs(Rxg-thresdb[k])<=width && Ryg < old_yg[1][k]) {
                Ryg = thresdb[k] + (Rxg-thresdb[k])/ratio;
        	Ryg = sanitize_denormal(Ryg);
        } else if (2.f*(Rxg-thresdb[k])>width) {
                Ryg = thresdb[k] + (Rxg-thresdb[k])/ratio;
        	Ryg = sanitize_denormal(Ryg);
        }


        if (stereolink == STEREOLINK_MAX) {
                Lxl = Rxl = fmaxf(Lxg - Lyg, Rxg - Ryg);
        } else {
                Lxl = Rxl = (Lxg - Lyg + Rxg - Ryg) / 2.f;
        }

        old_y1[0][k] = sanitize_denormal(old_y1[0][k]);
        old_y1[1][k] = sanitize_denormal(old_y1[1][k]);
        old_yl[0][k] = sanitize_denormal(old_yl[0][k]);
        old_yl[1][k] = sanitize_denormal(old_yl[1][k]);


        Ly1 = fmaxf(Lxl, release_coeff * old_y1[0][k]+(1.f-release_coeff)*Lxl);
        Lyl = attack_coeff * old_yl[0][k]+(1.f-attack_coeff)*Ly1;
        Ly1 = sanitize_denormal(Ly1);
        Lyl = sanitize_denormal(Lyl);

        cdb = -Lyl;
        Lgain = from_dB(cdb);

        Ry1 = fmaxf(Rxl, release_coeff * old_y1[1][k]+(1.f-release_coeff)*Rxl);
        Ryl = attack_coeff * old_yl[1][k]+(1.f-attack_coeff)*Ry1;
        Ry1 = sanitize_denormal(Ry1);
        Ryl = sanitize_denormal(Ryl);

        cdb = -Ryl;
        Rgain = from_dB(cdb);

        if (stereolink == STEREOLINK_MAX)
		gainr[k] = fmaxf(Lyl, Ryl);
	else
        	gainr[k] = (Lyl + Ryl) / 2.f;

	*outL = inL;
	*outL *= Lgain;
	*outR = inR;
	*outR *= Rgain;

        old_yl[0][k] = Lyl;
        old_yl[1][k] = Ryl;
        old_y1[0][k] = Ly1;
        old_y1[1][k] = Ry1;
        old_yg[0][k] = Lyg;
        old_yg[1][k] = Ryg;
}
void ZaMultiCompX2Plugin::run_limit(float inL, float inR, float *outL, float *outR)
{
	float srate = d_getSampleRate();
        float width=0.01;
	float threshdb = -0.5;
        float attack_coeff = exp(-1000.f/(0.001 * srate));
        float release_coeff = exp(-1000.f/(50.0 * srate));

        float cdb=0.f;
        float Lgain = 1.f;
        float Rgain = 1.f;
        float Lxg, Lyg;
        float Rxg, Ryg;
        float Lxl, Lyl, Ly1;
        float Rxl, Ryl, Ry1;

        Lyg = Ryg = 0.f;
	inL = sanitize_denormal(inL);
	inR = sanitize_denormal(inR);
        Lxg = (inL==0.f) ? -160.f : to_dB(fabs(inL));
        Rxg = (inR==0.f) ? -160.f : to_dB(fabs(inR));
        Lxg = sanitize_denormal(Lxg);
        Rxg = sanitize_denormal(Rxg);

        Lyg = Lxg + (1.f/100.0-1.f)*(Lxg-threshdb+width/2.f)*(Lxg-threshdb+width/2.f)/(2.f*width);
        Lyg = sanitize_denormal(Lyg);
        Ryg = Rxg + (1.f/100.0-1.f)*(Rxg-threshdb+width/2.f)*(Rxg-threshdb+width/2.f)/(2.f*width);
        Ryg = sanitize_denormal(Ryg);

        if (2.f*(Lxg-threshdb) < -width) {
                Lyg = Lxg;
        } else {
                Lyg = threshdb + (Lxg-threshdb)/100.0;
                Lyg = sanitize_denormal(Lyg);
        }

        if (2.f*(Rxg-threshdb) < -width) {
                Ryg = Rxg;
        } else {
                Ryg = threshdb + (Rxg-threshdb)/100.0;
        	Ryg = sanitize_denormal(Ryg);
        }

        Lxl = Rxl = fmaxf(Lxg - Lyg, Rxg - Ryg);

        old_l1[0] = sanitize_denormal(old_l1[0]);
        old_l1[1] = sanitize_denormal(old_l1[1]);
        old_ll[0] = sanitize_denormal(old_ll[0]);
        old_ll[1] = sanitize_denormal(old_ll[1]);

        Ly1 = fmaxf(Lxl, release_coeff * old_l1[0]+(1.f-release_coeff)*Lxl);
        Lyl = attack_coeff * old_ll[0]+(1.f-attack_coeff)*Ly1;
        Ly1 = sanitize_denormal(Ly1);
        Lyl = sanitize_denormal(Lyl);

        cdb = -Lyl;
        Lgain = from_dB(cdb);

        Ry1 = fmaxf(Rxl, release_coeff * old_l1[1]+(1.f-release_coeff)*Rxl);
        Ryl = attack_coeff * old_ll[1]+(1.f-attack_coeff)*Ry1;
        Ry1 = sanitize_denormal(Ry1);
        Ryl = sanitize_denormal(Ryl);

        cdb = -Ryl;
        Rgain = from_dB(cdb);

	*outL = inL;
	*outL *= Lgain;
	*outR = inR;
	*outR *= Rgain;

	limit = fmaxf(Lyl, Ryl);

        old_ll[0] = Lyl;
        old_ll[1] = Ryl;
        old_l1[0] = Ly1;
        old_l1[1] = Ry1;
}
Example #10
0
static void
run(LV2_Handle instance, uint32_t n_samples)
{
	ZamEXCITE* zamexcite = (ZamEXCITE*)instance;
  
	const float* const input_l = zamexcite->input_l;
	const float* const input_r = zamexcite->input_r;
	float* const output_l = zamexcite->output_l;
	float* const output_r = zamexcite->output_r;
  
	float attack = *(zamexcite->attack);
	float release = *(zamexcite->release);
	float knee = *(zamexcite->knee);
	float ratio = *(zamexcite->ratio);
	float threshold = from_dB(*(zamexcite->threshold));
	float makeup = from_dB(*(zamexcite->makeup));
	float* const gainr_l = zamexcite->gainr_l;
	float* const gainr_r = zamexcite->gainr_r;
	int stereolink = (*(zamexcite->stereolink) > 1.f) ? STEREOLINK_MAX : (*(zamexcite->stereolink) > 0.f) ? STEREOLINK_AVERAGE : STEREOLINK_UNCOUPLED;
	float width=(knee-0.99f)*6.f;
	float cdb=0.f;
	float attack_coeff = exp(-1000.f/(attack * zamexcite->srate));
	float release_coeff = exp(-1000.f/(release * zamexcite->srate));
	float thresdb = to_dB(threshold);

	float drygain = from_dB(*(zamexcite->drygain));
	int delaysamples = min(MAXDELAYSAMPLES, (int) (*(zamexcite->finedelay) * zamexcite->srate / 1000000));
	
	float togglelisten = (*(zamexcite->listen) > 0.1) ? 0.f : 1.f;

	zamexcite->delaysamples = delaysamples;
	/*if (zamexcite->delaychanged != delaysamples) {	
		for (int i = 0; i < delaysamples; ++i) {
			zamexcite->delaybuf_l[i] = 0.f;
			zamexcite->delaybuf_r[i] = 0.f;
		}
		zamexcite->delaychanged = delaysamples;
	}
*/
	double fConst0 = 3.141592653589793 / zamexcite->srate;
	double  fSlow0 = tan((fConst0 * *(zamexcite->hpfreq)));
	double  fSlow1 = (1.0 / pow(fSlow0,2));
	double  fSlow2 = (2 * (1 - fSlow1));
	double  fSlow3 = (1.0 / fSlow0);
	double  fSlow4 = (1 + ((fSlow3 - 1.414213562373095) / fSlow0));
	double  fSlow5 = (1.0 / (1 + ((1.414213562373095 + fSlow3) / fSlow0)));
	double  fSlow6 = (2 * (0 - fSlow1));

	float Lgain = 1.f;
	float Rgain = 1.f;
	float Lxg, Lyg;
	float Rxg, Ryg;
	float Lxl, Lyl, Ly1;
	float Rxl, Ryl, Ry1;
 
	float tmpl, tmpr, intl, intr, tmpinl, tmpinr;
	float *posl = &zamexcite->delaybuf_l[zamexcite->pos];
	float *posr = &zamexcite->delaybuf_r[zamexcite->pos];
	for (uint32_t i = 0; i < n_samples; ++i) {
		*posl = input_l[i];
		*posr = input_r[i];
		posl++;
		posr++;
		zamexcite->pos++;
		if (zamexcite->pos > delaysamples) {
			zamexcite->pos = 0;
			posl = &zamexcite->delaybuf_l[0];
			posr = &zamexcite->delaybuf_r[0];
		}

		tmpinl=*posl;
		tmpinr=*posr;

		sanitize_denormal(tmpinl);
		sanitize_denormal(tmpinr);
		
		zamexcite->fRec0l[0] = ((double)tmpinl - (fSlow5 * ((fSlow4 * zamexcite->fRec0l[2]) + (fSlow2 * zamexcite->fRec0l[1]))));
		intl = (float)(fSlow5 * (((fSlow1 * zamexcite->fRec0l[0]) + (fSlow6 * zamexcite->fRec0l[1])) + (fSlow1 * zamexcite->fRec0l[2])));

		zamexcite->fRec0r[0] = ((double)tmpinr - (fSlow5 * ((fSlow4 * zamexcite->fRec0r[2]) + (fSlow2 * zamexcite->fRec0r[1]))));
		intr = (float)(fSlow5 * (((fSlow1 * zamexcite->fRec0r[0]) + (fSlow6 * zamexcite->fRec0r[1])) + (fSlow1 * zamexcite->fRec0r[2])));

		sanitize_denormal(intl);
		sanitize_denormal(intr);

		Lyg = Ryg = 0.f;
		Lxg = (intl==0.f) ? -160.f : to_dB(fabs(intl));
		Rxg = (intr==0.f) ? -160.f : to_dB(fabs(intr));
		sanitize_denormal(Lxg);
		sanitize_denormal(Rxg);
    
    
		if (2.f*(Lxg-thresdb)<-width) {
			Lyg = Lxg;
		} else if (2.f*fabs(Lxg-thresdb)<=width) {
			Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);
		} else if (2.f*(Lxg-thresdb)>width) {
			Lyg = thresdb + (Lxg-thresdb)/ratio;
		}
    
		sanitize_denormal(Lyg);
    
		if (2.f*(Rxg-thresdb)<-width) {
			Ryg = Rxg;
		} else if (2.f*fabs(Rxg-thresdb)<=width) {
			Ryg = Rxg + (1.f/ratio-1.f)*(Rxg-thresdb+width/2.f)*(Rxg-thresdb+width/2.f)/(2.f*width);
		} else if (2.f*(Rxg-thresdb)>width) {
			Ryg = thresdb + (Rxg-thresdb)/ratio;
		}
    
		sanitize_denormal(Ryg);

		if (stereolink == STEREOLINK_UNCOUPLED) {
			Lxl = Lxg - Lyg;
			Rxl = Rxg - Ryg;
		} else if (stereolink == STEREOLINK_MAX) {
			Lxl = Rxl = fmaxf(Lxg - Lyg, Rxg - Ryg);
		} else {
			Lxl = Rxl = (Lxg - Lyg + Rxg - Ryg) / 2.f;
		}

		sanitize_denormal(zamexcite->oldL_y1);
		sanitize_denormal(zamexcite->oldR_y1);
		sanitize_denormal(zamexcite->oldL_yl);
		sanitize_denormal(zamexcite->oldR_yl);


		Ly1 = fmaxf(Lxl, release_coeff * zamexcite->oldL_y1+(1.f-release_coeff)*Lxl);
		Lyl = attack_coeff * zamexcite->oldL_yl+(1.f-attack_coeff)*Ly1;
		sanitize_denormal(Ly1);
		sanitize_denormal(Lyl);
    
		cdb = -Lyl;
		Lgain = from_dB(cdb);

		*gainr_l = Lyl;


		Ry1 = fmaxf(Rxl, release_coeff * zamexcite->oldR_y1+(1.f-release_coeff)*Rxl);
		Ryl = attack_coeff * zamexcite->oldR_yl+(1.f-attack_coeff)*Ry1;
		sanitize_denormal(Ry1);
		sanitize_denormal(Ryl);
    
		cdb = -Ryl;
		Rgain = from_dB(cdb);

		*gainr_r = Ryl;

		tmpl = (intl * Lgain * makeup);
		tmpr = (intr * Rgain * makeup);

		sanitize_denormal(tmpl);
		sanitize_denormal(tmpr);

		sanitize_denormal(drygain);
		
		float outl = tmpl + (input_l[i] * drygain)*togglelisten;
		float outr = tmpr + (input_r[i] * drygain)*togglelisten;
		
		output_l[i] = outl;
		output_r[i] = outr;

		//post
		zamexcite->oldL_yl = Lyl;
		zamexcite->oldR_yl = Ryl;
		zamexcite->oldL_y1 = Ly1;
		zamexcite->oldR_y1 = Ry1;
		

		zamexcite->fRec0l[2] = zamexcite->fRec0l[1];
		zamexcite->fRec0l[1] = zamexcite->fRec0l[0];
		//zamexcite->fRec1l[2] = zamexcite->fRec1l[1];
		//zamexcite->fRec1l[1] = zamexcite->fRec1l[0];

		zamexcite->fRec0r[2] = zamexcite->fRec0r[1];
		zamexcite->fRec0r[1] = zamexcite->fRec0r[0];
		//zamexcite->fRec1r[2] = zamexcite->fRec1r[1];
		//zamexcite->fRec1r[1] = zamexcite->fRec1r[0];

	}
}
Example #11
0
void ZamCompPlugin::run(const float** inputs, float** outputs, uint32_t frames)
{
    float srate = getSampleRate();
    float width = (6.f * knee) + 0.01;
    float slewwidth = 1.8f;
    float cdb=0.f;
    float attack_coeff = exp(-1000.f/(attack * srate));
    float release_coeff = exp(-1000.f/(release * srate));

    int attslew = 0;
    int relslew = 0;
    float max = 0.f;
    float lgaininp = 0.f;
    float rgaininp = 0.f;
    float Lgain = 1.f;
    float Rgain = 1.f;
    float Lxg, Lxl, Lyg, Lyl, Ly1;
    float checkwidth = 0.f;
    uint32_t i;

    for (i = 0; i < frames; i++) {
        relslew = 0;
        attslew = 0;
        Lyg = 0.f;
        Lxg = (inputs[0][i]==0.f) ? -160.f : to_dB(fabs(inputs[0][i]));
        Lxg = sanitize_denormal(Lxg);

        Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);

        checkwidth = 2.f*fabs(Lxg-thresdb);
        if (2.f*(Lxg-thresdb) < -width) {
            Lyg = Lxg;
        } else if (checkwidth <= width) {
            Lyg = thresdb + (Lxg-thresdb)/ratio;
            Lyg = sanitize_denormal(Lyg);
            if (checkwidth <= slewwidth) {
                if (Lyg >= oldL_yg) {
                    attslew = 1;
                } else {
                    relslew = 1;
                }
            }
        } else if (2.f*(Lxg-thresdb) > width) {
            Lyg = thresdb + (Lxg-thresdb)/ratio;
            Lyg = sanitize_denormal(Lyg);
        }

        attack_coeff = attslew ? exp(-1000.f/((attack + 2.0*(slewfactor - 1)) * srate)) : attack_coeff;
        // Don't slew on release
        //release_coeff = relslew ? exp(-1000.f/((release + 2.0*(slewfactor - 1)) * srate)) : release_coeff;

        Lxl = Lxg - Lyg;

        oldL_y1 = sanitize_denormal(oldL_y1);
        oldL_yl = sanitize_denormal(oldL_yl);
        Ly1 = fmaxf(Lxl, release_coeff * oldL_y1+(1.f-release_coeff)*Lxl);
        Lyl = attack_coeff * oldL_yl+(1.f-attack_coeff)*Ly1;
        Ly1 = sanitize_denormal(Ly1);
        Lyl = sanitize_denormal(Lyl);

        cdb = -Lyl;
        Lgain = from_dB(cdb);

        gainred = Lyl;

        lgaininp = inputs[0][i] * Lgain;
        outputs[0][i] = lgaininp * from_dB(makeup);

        max = (fabsf(lgaininp) > max) ? fabsf(lgaininp) : sanitize_denormal(max);

        oldL_yl = Lyl;
        oldL_y1 = Ly1;
        oldL_yg = Lyg;
    }
    outlevel = (max == 0.f) ? -45.f : to_dB(max) - thresdb;
}
Example #12
0
static void
run(LV2_Handle instance, uint32_t n_samples)
{
	AComp* acomp = (AComp*)instance;

	const float* const input0 = acomp->input0;
	const float* const input1 = acomp->input1;
	float* const output = acomp->output;

	float srate = acomp->srate;
	float width = (6.f * *(acomp->knee)) + 0.01;
	float cdb=0.f;
	float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate));
	float release_coeff = exp(-1000.f/(*(acomp->release) * srate));

	float max = 0.f;
	float lgaininp = 0.f;
	float Lgain = 1.f;
	float Lxg, Lxl, Lyg, Lyl, Ly1;
	int usesidechain = (*(acomp->sidechain) < 0.5) ? 0 : 1;
	uint32_t i;
	float ingain;
	float in0;
	float in1;
	float ratio = *(acomp->ratio);
	float thresdb = *(acomp->thresdb);

	for (i = 0; i < n_samples; i++) {
		in0 = input0[i];
		in1 = input1[i];
		ingain = usesidechain ? in1 : in0;
		Lyg = 0.f;
		Lxg = (ingain==0.f) ? -160.f : to_dB(fabs(ingain));
		Lxg = sanitize_denormal(Lxg);

		Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);

		if (2.f*(Lxg-thresdb) < -width) {
			Lyg = Lxg;
		} else {
			Lyg = thresdb + (Lxg-thresdb)/ratio;
			Lyg = sanitize_denormal(Lyg);
		}

		Lxl = Lxg - Lyg;

		acomp->old_y1 = sanitize_denormal(acomp->old_y1);
		acomp->old_yl = sanitize_denormal(acomp->old_yl);
		Ly1 = fmaxf(Lxl, release_coeff * acomp->old_y1+(1.f-release_coeff)*Lxl);
		Lyl = attack_coeff * acomp->old_yl+(1.f-attack_coeff)*Ly1;
		Ly1 = sanitize_denormal(Ly1);
		Lyl = sanitize_denormal(Lyl);

		cdb = -Lyl;
		Lgain = from_dB(cdb);

		*(acomp->gainr) = Lyl;

		lgaininp = in0 * Lgain;
		output[i] = lgaininp * from_dB(*(acomp->makeup));

		max = (fabsf(output[i]) > max) ? fabsf(output[i]) : sanitize_denormal(max);

		acomp->old_yl = Lyl;
		acomp->old_y1 = Ly1;
		acomp->old_yg = Lyg;
	}
	*(acomp->outlevel) = (max == 0.f) ? -45.f : to_dB(max);
}