static LADSPA_Handle instantiateSurroundEncoder( const LADSPA_Descriptor *descriptor, unsigned long s_rate) { SurroundEncoder *plugin_data = (SurroundEncoder *)malloc(sizeof(SurroundEncoder)); LADSPA_Data *buffer = NULL; unsigned int buffer_pos; unsigned int buffer_size; biquad *hc = NULL; biquad *lc = NULL; #line 32 "surround_encoder_1401.xml" buffer_size = (int)(0.0072f * s_rate); buffer_pos = 0; buffer = calloc(buffer_size, sizeof(LADSPA_Data)); lc = malloc(sizeof(biquad)); hc = malloc(sizeof(biquad)); biquad_init(lc); biquad_init(hc); ls_set_params(lc, 100.0f, -70.0f, 1.0f, s_rate); hs_set_params(hc, 7000.0f, -70.0f, 1.0f, s_rate); plugin_data->buffer = buffer; plugin_data->buffer_pos = buffer_pos; plugin_data->buffer_size = buffer_size; plugin_data->hc = hc; plugin_data->lc = lc; return (LADSPA_Handle)plugin_data; }
static void runAddingLcrDelay(LADSPA_Handle instance, unsigned long sample_count) { LcrDelay *plugin_data = (LcrDelay *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* L delay (ms) (float value) */ const LADSPA_Data ldel = *(plugin_data->ldel); /* L level (float value) */ const LADSPA_Data llev = *(plugin_data->llev); /* C delay (ms) (float value) */ const LADSPA_Data cdel = *(plugin_data->cdel); /* C level (float value) */ const LADSPA_Data clev = *(plugin_data->clev); /* R delay (ms) (float value) */ const LADSPA_Data rdel = *(plugin_data->rdel); /* R level (float value) */ const LADSPA_Data rlev = *(plugin_data->rlev); /* Feedback (float value) */ const LADSPA_Data feedback = *(plugin_data->feedback); /* High damp (%) (float value) */ const LADSPA_Data high_d = *(plugin_data->high_d); /* Low damp (%) (float value) */ const LADSPA_Data low_d = *(plugin_data->low_d); /* Spread (float value) */ const LADSPA_Data spread = *(plugin_data->spread); /* Dry/Wet level (float value) */ const LADSPA_Data wet = *(plugin_data->wet); /* L input (array of floats of length sample_count) */ const LADSPA_Data * const in_l = plugin_data->in_l; /* R input (array of floats of length sample_count) */ const LADSPA_Data * const in_r = plugin_data->in_r; /* L output (array of floats of length sample_count) */ LADSPA_Data * const out_l = plugin_data->out_l; /* R output (array of floats of length sample_count) */ LADSPA_Data * const out_r = plugin_data->out_r; LADSPA_Data * buffer = plugin_data->buffer; unsigned int buffer_mask = plugin_data->buffer_mask; unsigned int buffer_pos = plugin_data->buffer_pos; biquad * filters = plugin_data->filters; float fs = plugin_data->fs; float last_cd = plugin_data->last_cd; float last_cl = plugin_data->last_cl; float last_ld = plugin_data->last_ld; float last_ll = plugin_data->last_ll; float last_rd = plugin_data->last_rd; float last_rl = plugin_data->last_rl; #line 58 "lcr_delay_1436.xml" unsigned long pos; const float sc_r = 1.0f / (float)sample_count; const float spr_t = 0.5f + spread * 0.01f; const float spr_o = 0.5f - spread * 0.01f; float fb = feedback * 0.01f; float ll, cl, rl, ld, cd, rd; float ll_d, cl_d, rl_d, ld_d, cd_d, rd_d; float left, right; float fbs; /* Feedback signal */ if (fb < -0.99f) { fb = -0.99f; } else if (fb > 0.99f) { fb = 0.99f; } ls_set_params(filters, fs * 0.0001f * powf(2.0f, low_d * 0.12f), -0.5f * low_d, 0.5f, fs); hs_set_params(filters + 1, fs * (0.41f - 0.0001f * powf(2.0f, high_d * 0.12f)), -70.0f, 0.9f, fs); ll = last_ll; /* Start value of Left Level */ ll_d = (llev * 0.01f - last_ll) * sc_r; /* Delta for Left Level */ cl = last_cl; cl_d = (clev * 0.01f - last_cl) * sc_r; rl = last_rl; rl_d = (rlev * 0.01f - last_rl) * sc_r; ld = last_ld; ld_d = (ldel * fs * 0.001f - last_ld) * sc_r; cd = last_cd; cd_d = (cdel * fs * 0.001f - last_cd) * sc_r; rd = last_rd; rd_d = (rdel * fs * 0.001f - last_rd) * sc_r; for (pos = 0; pos < sample_count; pos++) { /* Increment linear interpolators */ ll += ll_d; rl += rl_d; cl += cl_d; ld += ld_d; rd += rd_d; cd += cd_d; /* Write input into delay line */ buffer[buffer_pos] = in_l[pos] + in_r[pos]; /* Add feedback, must be done afterwards for case where C delay = 0 */ fbs = buffer[(buffer_pos - f_round(cd)) & buffer_mask] * fb; fbs = flush_to_zero(fbs); fbs = biquad_run(filters, fbs); fbs = biquad_run(filters + 1, fbs); buffer[buffer_pos] += fbs; /* Outputs from left and right delay beffers + centre mix */ left = buffer[(buffer_pos - f_round(ld)) & buffer_mask] * ll + buffer[(buffer_pos - f_round(cd)) & buffer_mask] * cl; right = buffer[(buffer_pos - f_round(rd)) & buffer_mask] * rl + buffer[(buffer_pos - f_round(cd)) & buffer_mask] * cl; /* Left and right channel outs */ buffer_write(out_l[pos], in_l[pos] * (1.0f - wet) + (left * spr_t + right * spr_o) * wet); buffer_write(out_r[pos], in_r[pos] * (1.0f - wet) + (left * spr_o + right * spr_t) * wet); buffer_pos = (buffer_pos + 1) & buffer_mask; } plugin_data->last_ll = ll; plugin_data->last_cl = cl; plugin_data->last_rl = rl; plugin_data->last_ld = ld; plugin_data->last_cd = cd; plugin_data->last_rd = rd; plugin_data->buffer_pos = buffer_pos; }
static void runAddingGate(LADSPA_Handle instance, unsigned long sample_count) { Gate *plugin_data = (Gate *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* LF key filter (Hz) (float value) */ const LADSPA_Data lf_fc = *(plugin_data->lf_fc); /* HF key filter (Hz) (float value) */ const LADSPA_Data hf_fc = *(plugin_data->hf_fc); /* Threshold (dB) (float value) */ const LADSPA_Data threshold = *(plugin_data->threshold); /* Attack (ms) (float value) */ const LADSPA_Data attack = *(plugin_data->attack); /* Hold (ms) (float value) */ const LADSPA_Data hold = *(plugin_data->hold); /* Decay (ms) (float value) */ const LADSPA_Data decay = *(plugin_data->decay); /* Range (dB) (float value) */ const LADSPA_Data range = *(plugin_data->range); /* Output select (-1 = key listen, 0 = gate, 1 = bypass) (float value) */ const LADSPA_Data select = *(plugin_data->select); /* Input (array of floats of length sample_count) */ const LADSPA_Data * const input = plugin_data->input; /* Output (array of floats of length sample_count) */ LADSPA_Data * const output = plugin_data->output; float env = plugin_data->env; float fs = plugin_data->fs; float gate = plugin_data->gate; biquad * hf = plugin_data->hf; int hold_count = plugin_data->hold_count; biquad * lf = plugin_data->lf; int state = plugin_data->state; #line 55 "gate_1410.xml" unsigned long pos; float cut = DB_CO(range); float t_level = DB_CO(threshold); float a_rate = 1000.0f / (attack * fs); float d_rate = 1000.0f / (decay * fs); float post_filter, apost_filter; int op = f_round(select); ls_set_params(lf, lf_fc, -40.0f, 0.6f, fs); hs_set_params(hf, hf_fc, -50.0f, 0.6f, fs); for (pos = 0; pos < sample_count; pos++) { post_filter = biquad_run(lf, input[pos]); post_filter = biquad_run(hf, post_filter); apost_filter = fabs(post_filter); if (apost_filter > env) { env = apost_filter; } else { env = apost_filter * ENV_TR + env * (1.0f - ENV_TR); } if (state == CLOSED) { if (env >= t_level) { state = OPENING; } } else if (state == OPENING) { gate += a_rate; if (gate >= 1.0f) { gate = 1.0f; state = OPEN; hold_count = f_round(hold * fs * 0.001f); plugin_data->hold_count = hold_count; } } else if (state == OPEN) { if (hold_count <= 0) { if (env < t_level) { state = CLOSING; } } else { hold_count--; } } else if (state == CLOSING) { gate -= d_rate; if (env >= t_level) { state = OPENING; } else if (gate <= 0.0f) { gate = 0.0f; state = CLOSED; } } if (op == 0) { buffer_write(output[pos], input[pos] * (cut * (1.0f - gate) + gate)); } else if (op == -1) { buffer_write(output[pos], post_filter); } else { buffer_write(output[pos], input[pos]); } } plugin_data->env = env; plugin_data->gate = gate; plugin_data->state = state; plugin_data->hold_count = hold_count; }