Exemple #1
0
void FormantFilter_drawFilterFunctions (FormantFilter me, Graphics g, double bandwidth,
                                        int toFreqScale, int fromFilter, int toFilter, double zmin, double zmax,
                                        int dbScale, double ymin, double ymax, int garnish) {
	if (! checkLimits (me, FilterBank_HERTZ, toFreqScale, & fromFilter, & toFilter,
	                   & zmin, & zmax, dbScale, & ymin, & ymax)) {
		return;
	}

	if (bandwidth <= 0) {
		Melder_warning (U"Bandwidth must be greater than zero.");
	}

	long n = 1000;
	autoNUMvector<double>a (1, n);

	Graphics_setInner (g);
	Graphics_setWindow (g, zmin, zmax, ymin, ymax);

	for (long j = fromFilter; j <= toFilter; j++) {
		double df = (zmax - zmin) / (n - 1);
		double fc = my y1 + (j - 1) * my dy;
		long ibegin, iend;

		for (long i = 1; i <= n; i++) {
			double f = zmin + (i - 1) * df;
			double z = scaleFrequency (f, toFreqScale, FilterBank_HERTZ);
			if (z == NUMundefined) {
				a[i] = NUMundefined;
			} else {
				a[i] = NUMformantfilter_amplitude (fc, bandwidth, z);
				if (dbScale) {
					a[i] = to_dB (a[i], 10, ymin);
				}
			}
		}

		setDrawingLimits (a.peek(), n, ymin, ymax,	&ibegin, &iend);

		if (ibegin <= iend) {
			double fmin = zmin + (ibegin - 1) * df;
			double fmax = zmax - (n - iend) * df;
			Graphics_function (g, a.peek(), ibegin, iend, fmin, fmax);
		}
	}


	Graphics_unsetInner (g);

	if (garnish) {
		double distance = dbScale ? 10 : 1;
		char32 const *ytext = dbScale ? U"Amplitude (dB)" : U"Amplitude";
		Graphics_drawInnerBox (g);
		Graphics_marksBottom (g, 2, 1, 1, 0);
		Graphics_marksLeftEvery (g, 1, distance, 1, 1, 0);
		Graphics_textLeft (g, 1, ytext);
		Graphics_textBottom (g, 1, GetFreqScaleText (toFreqScale));
	}
}
Exemple #2
0
void MelFilter_drawFilterFunctions (MelFilter me, Graphics g,
                                    int toFreqScale, int fromFilter, int toFilter, double zmin, double zmax,
                                    int dbScale, double ymin, double ymax, int garnish) {
	if (! checkLimits (me, FilterBank_MEL, toFreqScale, & fromFilter, & toFilter,
	                   & zmin, & zmax, dbScale, & ymin, & ymax)) {
		return;
	}
	long n = 1000;
	autoNUMvector<double> a (1, n);

	Graphics_setInner (g);
	Graphics_setWindow (g, zmin, zmax, ymin, ymax);

	for (long j = fromFilter; j <= toFilter; j++) {
		double df = (zmax - zmin) / (n - 1);
		double fc_mel = my y1 + (j - 1) * my dy;
		double fc_hz = MELTOHZ (fc_mel);
		double fl_hz = MELTOHZ (fc_mel - my dy);
		double fh_hz = MELTOHZ (fc_mel + my dy);
		long ibegin, iend;

		for (long i = 1; i <= n; i++) {
			// Filterfunction: triangular on a linear frequency scale AND a linear amplitude scale.
			double f = zmin + (i - 1) * df;
			double z = scaleFrequency (f, toFreqScale, FilterBank_HERTZ);
			if (z == NUMundefined) {
				a[i] = NUMundefined;
			} else {
				a[i] = NUMtriangularfilter_amplitude (fl_hz, fc_hz, fh_hz, z);
				if (dbScale) {
					a[i] = to_dB (a[i], 10, ymin);
				}
			}

		}

		setDrawingLimits (a.peek(), n, ymin, ymax,	&ibegin, &iend);

		if (ibegin <= iend) {
			double fmin = zmin + (ibegin - 1) * df;
			double fmax = zmax - (n - iend) * df;
			Graphics_function (g, a.peek(), ibegin, iend, fmin, fmax);
		}
	}

	Graphics_unsetInner (g);

	if (garnish) {
		double distance = dbScale ? 10 : 1;
		char32 const *ytext = dbScale ? U"Amplitude (dB)" : U"Amplitude";
		Graphics_drawInnerBox (g);
		Graphics_marksBottom (g, 2, 1, 1, 0);
		Graphics_marksLeftEvery (g, 1, distance, 1, 1, 0);
		Graphics_textLeft (g, 1, ytext);
		Graphics_textBottom (g, 1, GetFreqScaleText (toFreqScale));
	}
}
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]);
	}
}
Exemple #4
0
float RSL_get_linear_value(Volume *v,float srange,float azim,
                           float elev,float limit)
{
    /* Compute bilinear value from four surrounding values
     * in Volume v.  The four surrounding values
     * are at a constant range.
     *
     * Limit is an angle used only to reject values
     * in the azimuth plane.
    */
    float  db_value;
    double value = 0;
    double up_value, down_value;
    double delta_angle;
    Sweep  *up_sweep,*down_sweep;

    get_surrounding_sweep(&down_sweep,&up_sweep,v,elev);

    /* Calculate interpolated value in sweep above
    * requested point.
    */
    if(up_sweep == NULL)
    {
        up_value = -1;
    }
    else
    {
        up_value = get_linear_value_from_sweep(up_sweep,srange,azim,limit);
    }

    /* Calculate interpolated value in sweep below requested point.
    */
    if(down_sweep == NULL)
    {
        down_value = -1;
    }
    else
    {
        down_value = get_linear_value_from_sweep(down_sweep,srange,azim,limit);
    }
    /* Using the interpolated values calculated at the elevation
     * angles in the above and below sweeps, interpolate a value
     * for the elvation angle at the requested point.
     */
    if((up_value != -1) && (down_value != -1))
    {
        delta_angle = angle_diff(up_sweep->h.elev,down_sweep->h.elev);

        value =((angle_diff(elev,up_sweep->h.elev)/delta_angle) * down_value) +
               ((angle_diff(elev,down_sweep->h.elev)/delta_angle) * up_value);
    }
    else if((up_value == -1) && (down_value == -1))
    {
        value = -1;
    }
    else if(up_value != -1)
    {
        value = up_value;
    }
    else
    {
        value = down_value;
    }

    /* Convert back to dB value and return. */
    if(value > 0)
    {
        db_value = (float)to_dB(value);
        return db_value;
    }
    else
    {
        return BADVAL;
    }
}
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;
}
Exemple #8
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];

	}
}
Exemple #9
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;
}
Exemple #10
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);
}