float ZaMaximX2Plugin::normalise(float in, float gainr) { if (ceiling < thresdb) { return in; } return from_dB(-(thresdb - ceiling + gainr)) * in; }
void ZamHeadX2Plugin::run(const float** inputs, float** outputs, uint32_t frames) { float m, s; uint32_t i; int nprocessed; active = swap; if (!signal) { memcpy(outputs[0], inputs[0], frames * sizeof(float)); memcpy(outputs[1], inputs[1], frames * sizeof(float)); return; } assert(frames < 8192); for (i = 0; i < frames; i++) { m = (inputs[0][i] + inputs[1][i]) * 0.5; s = (inputs[0][i] - inputs[1][i]) * 0.5 * width; tmpins[0][i] = m - s; tmpins[1][i] = m + s; } nprocessed = clv[active]->clv_convolve(tmpins, tmpouts, 2, 2, frames, from_dB(6.0)); if (nprocessed <= 0) { memcpy(outputs[0], inputs[0], frames * sizeof(float)); memcpy(outputs[1], inputs[1], frames * sizeof(float)); } else { memcpy(outputs[0], tmpouts[0], frames * sizeof(float)); memcpy(outputs[1], tmpouts[1], frames * sizeof(float)); } }
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); } }
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]); } }
static void run(LV2_Handle instance, uint32_t n_samples) { ADelay* adelay = (ADelay*)instance; const float* const input = adelay->input; float* const output = adelay->output; float srate = adelay->srate; uint32_t i; float in; int delaysamples; unsigned int tmp; float inv; float xfade; int recalc; if (*(adelay->inv) < 0.5) { inv = -1.f; } else { inv = 1.f; } recalc = 0; if (*(adelay->inv) != adelay->invertold) { recalc = 1; } if (*(adelay->sync) != adelay->syncold) { recalc = 1; } if (*(adelay->time) != adelay->timeold) { recalc = 1; } if (*(adelay->divisor) != adelay->divisorold) { recalc = 1; } if (*(adelay->lpf) != adelay->lpfold) { lpfRbj(adelay, *(adelay->lpf), srate); } if (*(adelay->gain) != adelay->gainold) { recalc = 1; } if (recalc) { if (*(adelay->sync) > 0.5f && adelay->bpmvalid) { *(adelay->delaytime) = adelay->beatunit * 1000.f * 60.f / (adelay->bpm * *(adelay->divisor)); } else { *(adelay->delaytime) = *(adelay->time); } delaysamples = (int)(*(adelay->delaytime) * srate) / 1000; adelay->tap[adelay->next] = delaysamples; } xfade = 0.f; for (i = 0; i < n_samples; i++) { in = input[i]; adelay->z[adelay->posz] = in; // + feedb / 100. * fbstate; adelay->fbstate = 0.f; int p = adelay->posz - adelay->tap[adelay->active]; // active line if (p<0) p += MAX_DELAY; adelay->fbstate += adelay->z[p]; if (recalc) { xfade += 1.0f / (float)n_samples; adelay->fbstate *= (1.-xfade); int p = adelay->posz - adelay->tap[adelay->next]; // next line if (p<0) p += MAX_DELAY; adelay->fbstate += adelay->z[p] * xfade; } output[i] = from_dB(*(adelay->gain)) * ((100.-*(adelay->wetdry)) / 100. * in + *(adelay->wetdry) / 100. * -inv * runfilter(adelay, adelay->fbstate)); if (++(adelay->posz) >= MAX_DELAY) { adelay->posz = 0; } } adelay->lpfold = *(adelay->lpf); adelay->divisorold = *(adelay->divisor); adelay->gainold = *(adelay->gain); adelay->invertold = *(adelay->inv); adelay->timeold = *(adelay->time); adelay->syncold = *(adelay->sync); adelay->wetdryold = *(adelay->wetdry); adelay->delaytimeold = *(adelay->delaytime); adelay->delaysamplesold = delaysamples; if (recalc) { tmp = adelay->active; adelay->active = adelay->next; adelay->next = tmp; } if (adelay->atombpm) { LV2_Atom_Event* ev = lv2_atom_sequence_begin(&(adelay->atombpm)->body); while(!lv2_atom_sequence_is_end(&(adelay->atombpm)->body, (adelay->atombpm)->atom.size, ev)) { if (ev->body.type == adelay->uris.atom_Blank || ev->body.type == adelay->uris.atom_Object) { const LV2_Atom_Object* obj = (LV2_Atom_Object*)&ev->body; if (obj->body.otype == adelay->uris.time_Position) { update_bpm(adelay, obj); } } ev = lv2_atom_sequence_next(ev); } } }
void ZamSFZPlugin::d_run(const float**, float** outputs, uint32_t frames, const MidiEvent* midievent, uint32_t midicount) { float srate = d_getSampleRate(); int slowfactor = (int) srate / (speed * 2400); // 1-20 ~ 20-1 uint32_t i; if (loading == true) { for (i = 0; i < frames; i++) { outputs[0][i] = 0.f; outputs[1][i] = 0.f; } } else { for (i = 0; i < midicount; i++) { int type = midievent[i].data[0] & 0xF0; int chan = midievent[i].data[0] & 0x0F; int num = midievent[i].data[1]; int vel = midievent[i].data[2]; if (type == 0x90 && chan == 0x0) { // NOTE ON int newvoice = -1; //printf("ON: Note %d\n", num); //printf("ON: begin attack\n"); for (int k = 0; k < 128; k++) if (!voice[k].playing) newvoice = k; if (newvoice == -1) newvoice = 0; //steal #0 curvoice = &voice[newvoice]; curvoice->envpos = 1; // begin attack curvoice->playing = true; curvoice->notenum = num; curvoice->vi = vel / 127.f; curvoice->curamp = curvoice->vi; curvoice->rampstate = 0; } else if (type == 0x80 && chan == 0x0) { // NOTE OFF //printf("OFF: Note\n"); //find voice with current notenum nvoices = 0; for (int k = 0; k < 128; k++) { if (voice[k].playing && voice[k].notenum == num) { voice[k].envpos = MAX_ENV / 2 + 1; // begin release; } if (!voice[k].playing && voice[k].notenum == num) { voice[k].notenum = -1; } } } } bool signal; float wavel; float waver; float outl; float outr; for (i = 0; i < frames; i++) { signal = false; outl = outr = 0.f; int k; Voice* j; // process envelope positions per sample for (k = 0; k < 128; k++) { j = &voice[k]; if (j->playing) { if (j->envpos <= 0) { //silence j->playing = false; j->notenum = -1; j->envpos = 0; j->slowcount = 0; j->curamp = 0.f; j->vi = 0.f; j->rampstate = 0; } else if (j->envpos > 0 && (int) j->envpos < MAX_ENV / 2) { //attack j->curamp = j->vi * env_y[j->envpos]; //printf("att: %d envpos=%d curamp=%.2f\n",k,j->envpos, j->curamp); j->slowcount++; j->envpos += ((j->slowcount % slowfactor) == 0) ? 1 : 0; } else if (j->envpos > MAX_ENV / 2) { //release j->curamp = j->vi * env_y[j->envpos]; //printf("rel: %d envpos=%d curamp=%.2f\n",k,j->envpos, j->curamp); j->slowcount++; j->envpos += ((j->slowcount % slowfactor) == 0) ? 1 : 0; if (j->envpos == MAX_ENV) { //end of release j->playing = false; j->notenum = -1; j->envpos = 0; j->slowcount = 0; j->curamp = 0.f; j->vi = 0.f; j->rampstate = 0; //printf("killed, n=%d\n",k); } } else if (j->envpos >= j->maxsamples || j->rampstate >= j->maxsamples) { j->playing = false; j->notenum = -1; j->envpos = 0; j->slowcount = 0; j->curamp = 0.f; j->vi = 0.f; j->rampstate = 0; } else { //sustain j->curamp = j->vi * env_y[MAX_ENV/2]; //printf("sustain...\n"); } } } for (k = 0; k < 128; k++) { if (voice[k].curamp < 0.f && voice[k].playing) printf("WTF NEG\n"); if (!voice[k].playing) { voice[k].rampstate = 0; continue; } signal = true; voice[k].rampstate++; if (voice[k].rampstate >= voice[k].maxsamples) { wavel = waver = 0.f; voice[k].rampstate = 0; voice[k].playing = false; voice[k].notenum = -1; voice[k].envpos = 0; voice[k].slowcount = 0; voice[k].curamp = 0.f; voice[k].vi = 0.f; } else { int n = voice[k].notenum; int v = voice[k].vi * 127.; int l = 0; for (int k = 0; k < sfz.layers[n].max; k++) { if (sfz.layers[n].l[k].lovel <= v && v <= sfz.layers[n].l[k].hivel) { l = k; break; } } int pos = voice[k].rampstate; wavel = sfz.sample[n][l][0][pos]; waver = sfz.sample[n][l][1][pos]; } outl += wavel*voice[k].curamp/2.; outr += waver*voice[k].curamp/2.; } if (signal) { //outl; //outr; outputs[0][i] = outl*from_dB(gain); outputs[1][i] = outr*from_dB(gain); } else { outputs[0][i] = 0.f; outputs[1][i] = 0.f; } } } }
double get_linear_value_from_sweep(Sweep *sweep,float srange,float azim, float limit) { float ccw_db_value,cw_db_value; double ccw_value,cw_value,value; double delta_angle; Ray *ccw_ray,*cw_ray; get_surrounding_ray(&ccw_ray,&cw_ray,sweep,azim); /* Assume that ccw_ray and cw_ray will be non_NULL */ if((azim - ccw_ray->h.azimuth) > limit) { ccw_value = -1; } else { ccw_db_value = RSL_get_value_from_ray(ccw_ray,srange); /* Check to make sure this is a valid value */ if (ccw_db_value == BADVAL) { ccw_value = 0; } else { ccw_value = from_dB(ccw_db_value); } } if((cw_ray->h.azimuth - azim) > limit) { cw_value = -1; } else { cw_db_value = RSL_get_value_from_ray(cw_ray,srange); /* Check to make sure this is a valid value */ if (cw_db_value == BADVAL) { cw_value = 0; } else { cw_value = from_dB(cw_db_value); } } if((cw_value != -1) && (ccw_value != -1)) { /* Both the clockwise ray and the counterclockwise * ray is valid. */ delta_angle = angle_diff(ccw_ray->h.azimuth,cw_ray->h.azimuth); value=((angle_diff(azim,cw_ray->h.azimuth)/delta_angle)*ccw_value) + ((angle_diff(azim,ccw_ray->h.azimuth)/delta_angle) * cw_value); } else if((cw_value == -1) && (ccw_value == -1)) { /* Neither ray is valid. */ value = -1; } else if(cw_value != -1) { /* cw_ray is only ray that is within limit. */ value = cw_value; } else { /* ccw_ray is only ray that is within limit. */ value = ccw_value; } return value; }
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; }
void Dynamics::gain(double gain_dB) { double gainFactor = from_dB(gain_dB); gainIntern(gainFactor); this->writeFile("_gain"); }
/** * Main process function of the plugin. */ static void run(LV2_Handle instance, uint32_t n_samples) { Nrepel *self = (Nrepel *)instance; //handy variables int k; unsigned int pos; //Inform latency at run call *(self->report_latency) = (float)self->input_latency; //Reset button state (if on) if (*(self->reset_profile) == 1.f) { reset_noise_profile(self); } //Softbypass targets in case of disabled or enabled if (*(self->enable) == 0.f) { //if disabled self->wet_dry_target = 0.f; } else { //if enabled self->wet_dry_target = 1.f; } //Interpolate parameters over time softly to bypass without clicks or pops self->wet_dry += self->tau * (self->wet_dry_target - self->wet_dry) + FLT_MIN; //Parameters values /*exponential decay coefficients for envelopes and adaptive noise profiling These must take into account the hop size as explained in the following paper FFT-BASED DYNAMIC RANGE COMPRESSION*/ if (*(self->release) != 0.f) //This allows to turn off smoothing with 0 ms in order to use masking only { self->release_coeff = expf(-1000.f / (((*(self->release)) * self->samp_rate) / self->hop)); } else { self->release_coeff = 0.f; //This avoids incorrect results when moving sliders rapidly } self->amount_of_reduction_linear = from_dB(-1.f * *(self->amount_of_reduction)); self->thresholds_offset_linear = from_dB(*(self->noise_thresholds_offset)); self->whitening_factor = *(self->whitening_factor_pc) / 100.f; //main loop for processing for (pos = 0; pos < n_samples; pos++) { //Store samples int the input buffer self->in_fifo[self->read_ptr] = self->input[pos]; //Output samples in the output buffer (even zeros introduced by latency) self->output[pos] = self->out_fifo[self->read_ptr - self->input_latency]; //Now move the read pointer self->read_ptr++; //Once the buffer is full we can do stuff if (self->read_ptr >= self->fft_size) { //Reset the input buffer position self->read_ptr = self->input_latency; //----------STFT Analysis------------ //Adding and windowing the frame input values in the center (zero-phasing) for (k = 0; k < self->fft_size; k++) { self->input_fft_buffer[k] = self->in_fifo[k] * self->input_window[k]; } //----------FFT Analysis------------ //Do transform fftwf_execute(self->forward); //-----------GET INFO FROM BINS-------------- get_info_from_bins(self->fft_p2, self->fft_magnitude, self->fft_phase, self->fft_size_2, self->fft_size, self->output_fft_buffer); /////////////////////SPECTRAL PROCESSING////////////////////////// /*This section countains the specific noise reduction processing blocks but it could be replaced with any spectral processing (I'm looking at you future tinkerer) Parameters for the STFT transform can be changed at the top of this file */ //If the spectrum is not silence if (!is_empty(self->fft_p2, self->fft_size_2)) { //If adaptive noise is selected the noise is adapted in time if (*(self->adaptive_state) == 1.f) { //This has to be revised(issue 8 on github) adapt_noise(self->fft_p2, self->fft_size_2, self->noise_thresholds_p2, self->auto_thresholds, self->prev_noise_thresholds, self->s_pow_spec, self->prev_s_pow_spec, self->p_min, self->prev_p_min, self->speech_p_p, self->prev_speech_p_p); self->noise_thresholds_availables = true; } /*If selected estimate noise spectrum is based on selected portion of signal *do not process the signal */ if (*(self->noise_learn_state) == 1.f) { //MANUAL //Increase window count for rolling mean self->noise_window_count++; get_noise_statistics(self->fft_p2, self->fft_size_2, self->noise_thresholds_p2, self->noise_window_count); self->noise_thresholds_availables = true; } else { //If there is a noise profile reduce noise if (self->noise_thresholds_availables == true) { //Detector smoothing and oversubtraction preprocessing(self->thresholds_offset_linear, self->fft_p2, self->noise_thresholds_p2, self->noise_thresholds_scaled, self->smoothed_spectrum, self->smoothed_spectrum_prev, self->fft_size_2, self->bark_z, self->absolute_thresholds, self->SSF, self->release_coeff, self->spreaded_unity_gain_bark_spectrum, self->spl_reference_values, self->alpha_masking, self->beta_masking, *(self->masking), *(self->adaptive_state), self->amount_of_reduction_linear, self->transient_preserv_prev, &self->tp_window_count, &self->tp_r_mean, &self->transient_present, *(self->transient_protection)); //Supression rule spectral_gain(self->fft_p2, self->noise_thresholds_p2, self->noise_thresholds_scaled, self->smoothed_spectrum, self->fft_size_2, *(self->adaptive_state), self->Gk, *(self->transient_protection), self->transient_present); //apply gains denoised_calulation(self->fft_size, self->output_fft_buffer, self->denoised_spectrum, self->Gk); //residual signal residual_calulation(self->fft_size, self->output_fft_buffer, self->residual_spectrum, self->denoised_spectrum, self->whitening_factor, self->residual_max_spectrum, &self->whitening_window_count, self->max_decay_rate); //Ensemble the final spectrum using residual and denoised final_spectrum_ensemble(self->fft_size, self->final_spectrum, self->residual_spectrum, self->denoised_spectrum, self->amount_of_reduction_linear, *(self->residual_listen)); soft_bypass(self->final_spectrum, self->output_fft_buffer, self->wet_dry, self->fft_size); } } } /////////////////////////////////////////////////////////// //----------STFT Synthesis------------ //------------FFT Synthesis------------- //Do inverse transform fftwf_execute(self->backward); //Normalizing value for (k = 0; k < self->fft_size; k++) { self->input_fft_buffer[k] = self->input_fft_buffer[k] / self->fft_size; } //------------OVERLAPADD------------- //Windowing scaling and accumulation for (k = 0; k < self->fft_size; k++) { self->output_accum[k] += (self->output_window[k] * self->input_fft_buffer[k]) / (self->overlap_scale_factor * self->overlap_factor); } //Output samples up to the hop size for (k = 0; k < self->hop; k++) { self->out_fifo[k] = self->output_accum[k]; } //shift FFT accumulator the hop size memmove(self->output_accum, self->output_accum + self->hop, self->fft_size * sizeof(float)); //move input FIFO for (k = 0; k < self->input_latency; k++) { self->in_fifo[k] = self->in_fifo[k + self->hop]; } //------------------------------- } //if } //main loop }
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]; } }
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; }
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); }