static void runAddingFadDelay(LADSPA_Handle instance, unsigned long sample_count) { FadDelay *plugin_data = (FadDelay *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Delay (seconds) (float value) */ const LADSPA_Data delay = *(plugin_data->delay); /* Feedback (dB) (float value) */ const LADSPA_Data fb_db = *(plugin_data->fb_db); /* 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; LADSPA_Data * buffer = plugin_data->buffer; unsigned long buffer_mask = plugin_data->buffer_mask; unsigned long buffer_size = plugin_data->buffer_size; LADSPA_Data last_in = plugin_data->last_in; int last_phase = plugin_data->last_phase; float phase = plugin_data->phase; long sample_rate = plugin_data->sample_rate; #line 51 "fad_delay_1192.xml" long int pos; float increment = (float)buffer_size / ((float)sample_rate * f_max(fabs(delay), 0.01)); float lin_int, lin_inc; int track; int fph; LADSPA_Data out; const float fb = DB_CO(fb_db); for (pos = 0; pos < sample_count; pos++) { fph = f_round(floor(phase)); last_phase = fph; lin_int = phase - (float)fph; out = LIN_INTERP(lin_int, buffer[(fph+1) & buffer_mask], buffer[(fph+2) & buffer_mask]); phase += increment; lin_inc = 1.0f / (floor(phase) - last_phase + 1); lin_inc = lin_inc > 1.0f ? 1.0f : lin_inc; lin_int = 0.0f; for (track = last_phase; track < phase; track++) { lin_int += lin_inc; buffer[track % buffer_size] = out * fb + LIN_INTERP(lin_int, last_in, input[pos]); } last_in = input[pos]; buffer_write(output[pos], out); if (phase >= buffer_size) { phase -= buffer_size; } } // Store current phase in instance plugin_data->phase = phase; plugin_data->last_phase = last_phase; plugin_data->last_in = last_in; }
static void runFadDelay(LV2_Handle instance, uint32_t sample_count) { FadDelay *plugin_data = (FadDelay *)instance; const float delay = *(plugin_data->delay); const float fb_db = *(plugin_data->fb_db); const float * const input = plugin_data->input; float * const output = plugin_data->output; float * buffer = plugin_data->buffer; float phase = plugin_data->phase; int last_phase = plugin_data->last_phase; float last_in = plugin_data->last_in; unsigned long buffer_size = plugin_data->buffer_size; unsigned long buffer_mask = plugin_data->buffer_mask; long sample_rate = plugin_data->sample_rate; long int pos; float increment = (float)buffer_size / ((float)sample_rate * f_max(fabs(delay), 0.01)); float lin_int, lin_inc; int track; int fph; float out; const float fb = DB_CO(fb_db); for (pos = 0; pos < sample_count; pos++) { fph = f_round(floor(phase)); last_phase = fph; lin_int = phase - (float)fph; out = LIN_INTERP(lin_int, buffer[(fph+1) & buffer_mask], buffer[(fph+2) & buffer_mask]); phase += increment; lin_inc = 1.0f / (floor(phase) - last_phase + 1); lin_inc = lin_inc > 1.0f ? 1.0f : lin_inc; lin_int = 0.0f; for (track = last_phase; track < phase; track++) { lin_int += lin_inc; buffer[track % buffer_size] = out * fb + LIN_INTERP(lin_int, last_in, input[pos]); } last_in = input[pos]; buffer_write(output[pos], out); if (phase >= buffer_size) { phase -= buffer_size; } } // Store current phase in instance plugin_data->phase = phase; plugin_data->last_phase = last_phase; plugin_data->last_in = last_in; }
static void runPointerCastDistortion(LADSPA_Handle instance, unsigned long sample_count) { PointerCastDistortion *plugin_data = (PointerCastDistortion *)instance; /* Effect cutoff freq (Hz) (float value) */ const LADSPA_Data cutoff = *(plugin_data->cutoff); /* Dry/wet mix (float value) */ const LADSPA_Data wet = *(plugin_data->wet); /* 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; biquad * filt = plugin_data->filt; float fs = plugin_data->fs; #line 40 "pointer_cast_1910.xml" unsigned long pos; const float filt_scale = cutoff < 50.0f ? cutoff / 50.0f : 1.0f; lp_set_params(filt, cutoff, 1.0f, fs); for (pos = 0; pos < sample_count; pos++) { pcast val; float sign, filt_val, dist_val; filt_val = biquad_run(filt, input[pos]) * filt_scale; sign = filt_val < 0.0f ? -1.0f : 1.0f; val.fp = fabs(filt_val); dist_val = sign * (LADSPA_Data)val.in / (LADSPA_Data)INT_MAX + (input[pos] - filt_val); buffer_write(output[pos], LIN_INTERP(wet, input[pos], dist_val)); } }
void Compressor::process(int frames, float* ip, float *op) { const float ga = _attack < 2.0f ? 0.0f : as[f_round(_attack * 0.001f * (float)(A_TBL-1))]; const float gr = as[f_round(_release * 0.001f * (float)(A_TBL-1))]; const float rs = (_ratio - 1.0f) / _ratio; const float mug = db2lin(_makeupGain); const float knee_min = db2lin(_threshold - _knee); const float knee_max = db2lin(_threshold + _knee); const float ef_a = ga * 0.25f; const float ef_ai = 1.0f - ef_a; for (int pos = 0; pos < frames; pos++) { const float la = fabs(ip[pos * 2]); const float ra = fabs(ip[pos * 2 + 1]); const float lev_in = f_max(la, ra); sum += lev_in * lev_in; if (amp > env_rms) env_rms = env_rms * ga + amp * (1.0f - ga); else env_rms = env_rms * gr + amp * (1.0f - gr); round_to_zero(&env_rms); if (lev_in > env_peak) env_peak = env_peak * ga + lev_in * (1.0f - ga); else env_peak = env_peak * gr + lev_in * (1.0f - gr); round_to_zero(&env_peak); if ((count++ & 3) == 3) { amp = rms.process(sum * 0.25f); sum = 0.0f; if (qIsNaN(env_rms)) // This can happen sometimes, but I don't know why env_rms = 0.0f; env = LIN_INTERP(rms_peak, env_rms, env_peak); if (env <= knee_min) gain_t = 1.0f; else if (env < knee_max) { const float x = -(_threshold - _knee - lin2db(env)) / _knee; gain_t = db2lin(-_knee * rs * x * x * 0.25f); } else gain_t = db2lin((_threshold - lin2db(env)) * rs); } gain = gain * ef_a + gain_t * ef_ai; op[pos * 2] = ip[pos * 2] * gain * mug; op[pos * 2+1] = ip[pos * 2 + 1] * gain * mug; } // printf("gain %f\n", gain); // amplitude = lin2db(env); // gain_red = lin2db(gain); }
static void runAddingCombSplitter(LADSPA_Handle instance, unsigned long sample_count) { CombSplitter *plugin_data = (CombSplitter *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Band separation (Hz) (float value) */ const LADSPA_Data freq = *(plugin_data->freq); /* Input (array of floats of length sample_count) */ const LADSPA_Data * const input = plugin_data->input; /* Output 1 (array of floats of length sample_count) */ LADSPA_Data * const out1 = plugin_data->out1; /* Output 2 (array of floats of length sample_count) */ LADSPA_Data * const out2 = plugin_data->out2; long comb_pos = plugin_data->comb_pos; LADSPA_Data * comb_tbl = plugin_data->comb_tbl; float last_offset = plugin_data->last_offset; long sample_rate = plugin_data->sample_rate; float offset; int data_pos; unsigned long pos; float xf, xf_step, d_pos, fr, interp, in; offset = sample_rate / freq; offset = f_clamp(offset, 0, COMB_SIZE - 1); xf_step = 1.0f / (float)sample_count; xf = 0.0f; for (pos = 0; pos < sample_count; pos++) { xf += xf_step; d_pos = comb_pos - LIN_INTERP(xf, last_offset, offset); data_pos = f_trunc(d_pos); fr = d_pos - data_pos; interp = cube_interp(fr, comb_tbl[(data_pos - 1) & COMB_MASK], comb_tbl[data_pos & COMB_MASK], comb_tbl[(data_pos + 1) & COMB_MASK], comb_tbl[(data_pos + 2) & COMB_MASK]); in = input[pos]; comb_tbl[comb_pos] = in; buffer_write(out1[pos], (in + interp) * 0.5f); buffer_write(out2[pos], (in - interp) * 0.5f); comb_pos = (comb_pos + 1) & COMB_MASK; } plugin_data->comb_pos = comb_pos; plugin_data->last_offset = offset; }
static void runComb(LADSPA_Handle instance, unsigned long sample_count) { Comb *plugin_data = (Comb *)instance; /* Band separation (Hz) (float value) */ const LADSPA_Data freq = *(plugin_data->freq); /* Feedback (float value) */ const LADSPA_Data fb = *(plugin_data->fb); /* 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; long comb_pos = plugin_data->comb_pos; LADSPA_Data * comb_tbl = plugin_data->comb_tbl; float last_offset = plugin_data->last_offset; long sample_rate = plugin_data->sample_rate; #line 41 "comb_1190.xml" float offset; int data_pos; unsigned long pos; float xf, xf_step, d_pos, fr, interp; offset = sample_rate / freq; offset = f_clamp(offset, 0, COMB_SIZE - 1); xf_step = 1.0f / (float)sample_count; xf = 0.0f; for (pos = 0; pos < sample_count; pos++) { xf += xf_step; d_pos = comb_pos - LIN_INTERP(xf, last_offset, offset); data_pos = f_trunc(d_pos); fr = d_pos - data_pos; interp = cube_interp(fr, comb_tbl[(data_pos - 1) & COMB_MASK], comb_tbl[data_pos & COMB_MASK], comb_tbl[(data_pos + 1) & COMB_MASK], comb_tbl[(data_pos + 2) & COMB_MASK]); comb_tbl[comb_pos] = input[pos] + fb * interp; buffer_write(output[pos], (input[pos] + interp) * 0.5f); comb_pos = (comb_pos + 1) & COMB_MASK; } plugin_data->comb_pos = comb_pos; plugin_data->last_offset = offset; }
static void runAddingSmoothDecimate(LADSPA_Handle instance, unsigned long sample_count) { SmoothDecimate *plugin_data = (SmoothDecimate *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Resample rate (float value) */ const LADSPA_Data rate = *(plugin_data->rate); /* Smoothing (float value) */ const LADSPA_Data smooth = *(plugin_data->smooth); /* 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 accum = plugin_data->accum; float * buffer = plugin_data->buffer; int buffer_pos = plugin_data->buffer_pos; float fs = plugin_data->fs; #line 31 "smooth_decimate_1414.xml" unsigned long pos; float smoothed; float inc = (rate / fs); inc = f_clamp(inc, 0.0f, 1.0f); for (pos = 0; pos < sample_count; pos++) { accum += inc; if (accum >= 1.0f) { accum -= 1.0f; buffer_pos = (buffer_pos + 1) & 7; buffer[buffer_pos] = input[pos]; } smoothed = cube_interp(accum, buffer[(buffer_pos - 3) & 7], buffer[(buffer_pos - 2) & 7], buffer[(buffer_pos - 1) & 7], buffer[buffer_pos]); buffer_write(output[pos], LIN_INTERP(smooth, buffer[(buffer_pos - 3) & 7], smoothed)); } plugin_data->accum = accum; plugin_data->buffer_pos = buffer_pos; }
static void runAddingComb_l(LADSPA_Handle instance, unsigned long sample_count) { Comb_l *plugin_data = (Comb_l *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Input (array of floats of length sample_count) */ const LADSPA_Data * const in = plugin_data->in; /* Output (array of floats of length sample_count) */ LADSPA_Data * const out = plugin_data->out; /* Max Delay (s) (float value) */ const LADSPA_Data max_delay = *(plugin_data->max_delay); /* Delay Time (s) (float value) */ const LADSPA_Data delay_time = *(plugin_data->delay_time); /* Decay Time (s) (float value) */ const LADSPA_Data decay_time = *(plugin_data->decay_time); LADSPA_Data * buffer = plugin_data->buffer; unsigned int buffer_mask = plugin_data->buffer_mask; LADSPA_Data delay_samples = plugin_data->delay_samples; LADSPA_Data feedback = plugin_data->feedback; LADSPA_Data last_decay_time = plugin_data->last_decay_time; LADSPA_Data last_delay_time = plugin_data->last_delay_time; unsigned int sample_rate = plugin_data->sample_rate; long write_phase = plugin_data->write_phase; #line 79 "comb_1887.xml" int i; i = max_delay; if (write_phase == 0) { plugin_data->last_delay_time = delay_time; plugin_data->last_decay_time = decay_time; plugin_data->delay_samples = delay_samples = CALC_DELAY (delay_time); plugin_data->feedback = feedback = calc_feedback (delay_time, decay_time); } if (delay_time == last_delay_time && decay_time == last_decay_time) { long idelay_samples = (long)delay_samples; LADSPA_Data frac = delay_samples - idelay_samples; for (i=0; i<sample_count; i++) { long read_phase = write_phase - (long)delay_samples; LADSPA_Data r1 = buffer[read_phase & buffer_mask]; LADSPA_Data r2 = buffer[(read_phase-1) & buffer_mask]; LADSPA_Data read = LIN_INTERP (frac, r1, r2); buffer[write_phase & buffer_mask] = read * feedback + in[i]; buffer_write(out[i], read); write_phase++; } } else { float next_delay_samples = CALC_DELAY (delay_time); float delay_samples_slope = (next_delay_samples - delay_samples) / sample_count; float next_feedback = calc_feedback (delay_time, decay_time); float feedback_slope = (next_feedback - feedback) / sample_count; for (i=0; i<sample_count; i++) { long read_phase, idelay_samples; LADSPA_Data read, frac; delay_samples += delay_samples_slope; write_phase++; read_phase = write_phase - (long)delay_samples; idelay_samples = (long)delay_samples; frac = delay_samples - idelay_samples; read = LIN_INTERP (frac, buffer[read_phase & buffer_mask], buffer[(read_phase-1) & buffer_mask]); buffer[write_phase & buffer_mask] = read * feedback + in[i]; buffer_write(out[i], read); feedback += feedback_slope; } plugin_data->last_delay_time = delay_time; plugin_data->last_decay_time = decay_time; plugin_data->feedback = feedback; plugin_data->delay_samples = delay_samples; } plugin_data->write_phase = write_phase; }
static void runAddingSc4m(LADSPA_Handle instance, unsigned long sample_count) { Sc4m *plugin_data = (Sc4m *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* RMS/peak (float value) */ const LADSPA_Data rms_peak = *(plugin_data->rms_peak); /* Attack time (ms) (float value) */ const LADSPA_Data attack = *(plugin_data->attack); /* Release time (ms) (float value) */ const LADSPA_Data release = *(plugin_data->release); /* Threshold level (dB) (float value) */ const LADSPA_Data threshold = *(plugin_data->threshold); /* Ratio (1:n) (float value) */ const LADSPA_Data ratio = *(plugin_data->ratio); /* Knee radius (dB) (float value) */ const LADSPA_Data knee = *(plugin_data->knee); /* Makeup gain (dB) (float value) */ const LADSPA_Data makeup_gain = *(plugin_data->makeup_gain); /* 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 amp = plugin_data->amp; float * as = plugin_data->as; unsigned int count = plugin_data->count; float env = plugin_data->env; float env_peak = plugin_data->env_peak; float env_rms = plugin_data->env_rms; float gain = plugin_data->gain; float gain_t = plugin_data->gain_t; rms_env * rms = plugin_data->rms; float sum = plugin_data->sum; unsigned long pos; const float ga = attack < 2.0f ? 0.0f : as[f_round(attack * 0.001f * (float)(A_TBL-1))]; const float gr = as[f_round(release * 0.001f * (float)(A_TBL-1))]; const float rs = (ratio - 1.0f) / ratio; const float mug = db2lin(makeup_gain); const float knee_min = db2lin(threshold - knee); const float knee_max = db2lin(threshold + knee); const float ef_a = ga * 0.25f; const float ef_ai = 1.0f - ef_a; for (pos = 0; pos < sample_count; pos++) { const float lev_in = input[pos]; sum += lev_in * lev_in; if (amp > env_rms) { env_rms = env_rms * ga + amp * (1.0f - ga); } else { env_rms = env_rms * gr + amp * (1.0f - gr); } round_to_zero(&env_rms); if (lev_in > env_peak) { env_peak = env_peak * ga + lev_in * (1.0f - ga); } else { env_peak = env_peak * gr + lev_in * (1.0f - gr); } round_to_zero(&env_peak); if ((count++ & 3) == 3) { amp = rms_env_process(rms, sum * 0.25f); sum = 0.0f; env = LIN_INTERP(rms_peak, env_rms, env_peak); if (env <= knee_min) { gain_t = 1.0f; } else if (env < knee_max) { const float x = -(threshold - knee - lin2db(env)) / knee; gain_t = db2lin(-knee * rs * x * x * 0.25f); } else { gain_t = db2lin((threshold - lin2db(env)) * rs); } } gain = gain * ef_a + gain_t * ef_ai; buffer_write(output[pos], input[pos] * gain * mug); } plugin_data->sum = sum; plugin_data->amp = amp; plugin_data->gain = gain; plugin_data->gain_t = gain_t; plugin_data->env = env; plugin_data->env_rms = env_rms; plugin_data->env_peak = env_peak; plugin_data->count = count; *(plugin_data->amplitude) = lin2db(env); *(plugin_data->gain_red) = lin2db(gain); }
void processAudio(AudioBuffer& _buf){ uint32_t sample_count = _buf.getSize(); float s_rate = getSampleRate(); delay_depth_avg = getParameterValue(PARAMETER_A)*10 - 0; law_freq = getParameterValue(PARAMETER_B)*7.5 - 0.5; input = _buf.getSamples(0); output = _buf.getSamples(0); RetroFlangePatch* plugin_data = this; long int pos; int law_p = f_trunc(LIMIT(sample_rate / f_clamp(law_freq, 0.0001f, 100.0f), 1, max_law_p)); float increment; float lin_int, lin_inc; int track; int fph; LADSPA_Data out = 0.0f; const float dda_c = f_clamp(delay_depth_avg, 0.0f, 10.0f); int dl_used = (dda_c * sample_rate) / 1000; float inc_base = 1000.0f * (float)BASE_BUFFER; const float delay_depth = 2.0f * dda_c; float n_ph, p_ph, law; for (pos = 0; pos < sample_count; pos++) { // Write into the delay line delay_line[delay_pos] = input[pos]; z0 = delay_line[MOD(delay_pos - dl_used, delay_line_length)] + 0.12919609397f*z1 - 0.31050847f*z2; out = sat(z0*0.20466966f + z1*0.40933933f + z2*0.40933933f, -0.23f, 3.3f); z2 = z1; z1 = z0; delay_pos = (delay_pos + 1) % delay_line_length; if ((count++ % law_p) == 0) { // Value for amplitude of law peak next_law_peak = (float)rand() / (float)RAND_MAX; next_law_pos = count + law_p; } else if (count % law_p == law_p / 2) { // Value for amplitude of law peak prev_law_peak = (float)rand() / (float)RAND_MAX; prev_law_pos = count + law_p; } n_ph = (float)(law_p - abs(next_law_pos - count))/(float)law_p; p_ph = n_ph + 0.5f; if (p_ph > 1.0f) { p_ph -= 1.0f; } law = f_sin_sq(3.1415926f*p_ph)*prev_law_peak + f_sin_sq(3.1415926f*n_ph)*next_law_peak; increment = inc_base / (delay_depth * law + 0.2); fph = f_trunc(phase); last_phase = fph; lin_int = phase - (float)fph; out += LIN_INTERP(lin_int, buffer[(fph+1) % buffer_size], buffer[(fph+2) % buffer_size]); phase += increment; lin_inc = 1.0f / (floor(phase) - last_phase + 1); lin_inc = lin_inc > 1.0f ? 1.0f : lin_inc; lin_int = 0.0f; for (track = last_phase; track < phase; track++) { lin_int += lin_inc; buffer[track % buffer_size] = LIN_INTERP(lin_int, last_in, input[pos]); } last_in = input[pos]; buffer_write(output[pos], out * 0.707f); if (phase >= buffer_size) { phase -= buffer_size; } } // Store current phase in instance plugin_data->phase = phase; plugin_data->prev_law_peak = prev_law_peak; plugin_data->next_law_peak = next_law_peak; plugin_data->prev_law_pos = prev_law_pos; plugin_data->next_law_pos = next_law_pos; plugin_data->last_phase = last_phase; plugin_data->last_in = last_in; plugin_data->count = count; plugin_data->last_law_p = last_law_p; plugin_data->delay_pos = delay_pos; plugin_data->z0 = z0; plugin_data->z1 = z1; plugin_data->z2 = z2; }
static void runAddingDelayorama(LADSPA_Handle instance, unsigned long sample_count) { Delayorama *plugin_data = (Delayorama *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Random seed (float value) */ const LADSPA_Data seed = *(plugin_data->seed); /* Input gain (dB) (float value) */ const LADSPA_Data gain = *(plugin_data->gain); /* Feedback (%) (float value) */ const LADSPA_Data feedback_pc = *(plugin_data->feedback_pc); /* Number of taps (float value) */ const LADSPA_Data tap_count = *(plugin_data->tap_count); /* First delay (s) (float value) */ const LADSPA_Data first_delay = *(plugin_data->first_delay); /* Delay range (s) (float value) */ const LADSPA_Data delay_range = *(plugin_data->delay_range); /* Delay change (float value) */ const LADSPA_Data delay_scale = *(plugin_data->delay_scale); /* Delay random (%) (float value) */ const LADSPA_Data delay_rand_pc = *(plugin_data->delay_rand_pc); /* Amplitude change (float value) */ const LADSPA_Data gain_scale = *(plugin_data->gain_scale); /* Amplitude random (%) (float value) */ const LADSPA_Data gain_rand_pc = *(plugin_data->gain_rand_pc); /* Dry/wet mix (float value) */ const LADSPA_Data wet = *(plugin_data->wet); /* 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; unsigned int active_set = plugin_data->active_set; LADSPA_Data * buffer = plugin_data->buffer; unsigned long buffer_pos = plugin_data->buffer_pos; unsigned int buffer_size = plugin_data->buffer_size; float last_a_rand = plugin_data->last_a_rand; float last_ampsc = plugin_data->last_ampsc; float last_d_rand = plugin_data->last_d_rand; float last_delaysc = plugin_data->last_delaysc; unsigned int last_ntaps = plugin_data->last_ntaps; LADSPA_Data last_out = plugin_data->last_out; float last_range = plugin_data->last_range; float last_seed = plugin_data->last_seed; float last_start = plugin_data->last_start; unsigned int next_set = plugin_data->next_set; unsigned int sample_rate = plugin_data->sample_rate; tap ** taps = plugin_data->taps; #line 73 "delayorama_1402.xml" unsigned long pos; float coef = DB_CO(gain); unsigned int i; unsigned int recalc = 0; unsigned int ntaps = LIMIT(f_round(tap_count), 2, N_TAPS); float range = f_clamp(delay_range * sample_rate, 0.0f, (float)(buffer_size-1)); LADSPA_Data out; float xfade = 0.0f; const float feedback = feedback_pc * 0.01f; const float gain_rand = gain_rand_pc * 0.01f; const float delay_rand = delay_rand_pc * 0.01f; if (ntaps != last_ntaps) { recalc = 1; plugin_data->last_ntaps = ntaps; } if (first_delay != last_start) { recalc = 1; plugin_data->last_start = first_delay; } if (range != last_range) { recalc = 1; plugin_data->last_range = range; } if (delay_scale != last_delaysc) { recalc = 1; plugin_data->last_delaysc = delay_scale; } if (gain_scale != last_ampsc) { recalc = 1; plugin_data->last_ampsc = gain_scale; } if (seed != last_seed) { recalc = 1; plugin_data->last_seed = seed; } if (gain_rand != last_a_rand) { recalc = 1; plugin_data->last_a_rand = gain_rand; } if (delay_rand != last_d_rand) { recalc = 1; plugin_data->last_d_rand = delay_rand; } if (recalc) { float delay_base = first_delay * sample_rate; float delay_fix; float gain, delay, delay_sum; float d_rand, g_rand; srand(f_round(seed)); if (delay_base + range > buffer_size-1) { delay_base = buffer_size - 1 - range; } if (gain_scale <= 1.0f) { gain = 1.0f; } else { gain = 1.0f / pow(gain_scale, ntaps-1); } if (delay_scale == 1.0f) { delay_fix = range / (ntaps - 1); } else { delay_fix = range * (delay_scale - 1.0f) / (pow(delay_scale, ntaps - 1) - 1.0f); } delay = 1.0f; delay_sum = 0.0f; for (i=0; i<ntaps; i++) { g_rand = (1.0f-gain_rand) + (float)rand() / (float)RAND_MAX * 2.0f * gain_rand; d_rand = (1.0f-delay_rand) + (float)rand() / (float)RAND_MAX * 2.0f * delay_rand; taps[next_set][i].delay = LIMIT((unsigned int)(delay_base + delay_sum * delay_fix * d_rand), 0, buffer_size-1); taps[next_set][i].gain = gain * g_rand; delay_sum += delay; delay *= delay_scale; gain *= gain_scale; } for (; i<N_TAPS; i++) { taps[next_set][i].delay = 0.0f; taps[next_set][i].gain = 0.0f; } } out = last_out; for (pos = 0; pos < sample_count; pos++) { buffer[buffer_pos] = input[pos] * coef + (out * feedback); out = 0.0f; for (i=0; i<ntaps; i++) { int p = buffer_pos - taps[active_set][i].delay; if (p<0) p += buffer_size; out += buffer[p] * taps[active_set][i].gain; } if (recalc) { xfade += 1.0f / (float)sample_count; out *= (1-xfade); for (i=0; i<ntaps; i++) { int p = buffer_pos - taps[next_set][i].delay; if (p<0) p += buffer_size; out += buffer[p] * taps[next_set][i].gain * xfade; } } buffer_write(output[pos], LIN_INTERP(wet, input[pos], out)); if (++buffer_pos >= buffer_size) { buffer_pos = 0; } } if (recalc) { plugin_data->active_set = next_set; plugin_data->next_set = active_set; } plugin_data->buffer_pos = buffer_pos; plugin_data->last_out = out; }
static void runAddingFlanger(LADSPA_Handle instance, unsigned long sample_count) { Flanger *plugin_data = (Flanger *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Delay base (ms) (float value) */ const LADSPA_Data delay_base = *(plugin_data->delay_base); /* Max slowdown (ms) (float value) */ const LADSPA_Data detune = *(plugin_data->detune); /* LFO frequency (Hz) (float value) */ const LADSPA_Data law_freq = *(plugin_data->law_freq); /* Feedback (float value) */ const LADSPA_Data feedback = *(plugin_data->feedback); /* 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; long count = plugin_data->count; long delay_pos = plugin_data->delay_pos; long delay_size = plugin_data->delay_size; LADSPA_Data * delay_tbl = plugin_data->delay_tbl; float next_law_peak = plugin_data->next_law_peak; int next_law_pos = plugin_data->next_law_pos; long old_d_base = plugin_data->old_d_base; float prev_law_peak = plugin_data->prev_law_peak; int prev_law_pos = plugin_data->prev_law_pos; long sample_rate = plugin_data->sample_rate; #line 50 "flanger_1191.xml" unsigned long pos; long d_base, new_d_base; LADSPA_Data out; float delay_depth; float dp; // float delay position float dp_frac; // fractional part long dp_idx; // integer delay index long law_p; // period of law float frac = 0.0f, step; // Portion the way through the block float law; /* law amplitude */ float n_ph, p_ph; const float fb = f_clamp(feedback, -0.999f, 0.999f); // Set law params law_p = (float)sample_rate / law_freq; if (law_p < 1) { law_p = 1; } // Calculate base delay size in samples new_d_base = (LIMIT(f_round(delay_base), 0, 25) * sample_rate) / 1000; // Calculate delay depth in samples delay_depth = f_clamp(detune * (float)sample_rate * 0.001f, 0.0f, delay_size - new_d_base - 1.0f); step = 1.0f/sample_count; for (pos = 0; pos < sample_count; pos++) { if (count % law_p == 0) { // Value for amplitude of law peak next_law_peak = (float)rand() / (float)RAND_MAX; next_law_pos = count + law_p; } else if (count % law_p == law_p / 2) { // Value for amplitude of law peak prev_law_peak = (float)rand() / (float)RAND_MAX; prev_law_pos = count + law_p; } // Calculate position in delay table d_base = LIN_INTERP(frac, old_d_base, new_d_base); n_ph = (float)(law_p - abs(next_law_pos - count))/(float)law_p; p_ph = n_ph + 0.5f; while (p_ph > 1.0f) { p_ph -= 1.0f; } law = f_sin_sq(3.1415926f*p_ph)*prev_law_peak + f_sin_sq(3.1415926f*n_ph)*next_law_peak; dp = (float)(delay_pos - d_base) - (delay_depth * law); // Get the integer part dp_idx = f_round(dp - 0.5f); // Get the fractional part dp_frac = dp - dp_idx; // Accumulate into output buffer out = cube_interp(dp_frac, delay_tbl[(dp_idx-1) & (delay_size-1)], delay_tbl[dp_idx & (delay_size-1)], delay_tbl[(dp_idx+1) & (delay_size-1)], delay_tbl[(dp_idx+2) & (delay_size-1)]); // Store new delayed value delay_tbl[delay_pos] = flush_to_zero(input[pos] + (fb * out)); // Sometimes the delay can pick up NaN values, I'm not sure why // and this is easier than fixing it if (isnan(delay_tbl[delay_pos])) { delay_tbl[delay_pos] = 0.0f; } out = f_clamp(delay_tbl[delay_pos] * 0.707f, -1.0, 1.0); buffer_write(output[pos], out); frac += step; delay_pos = (delay_pos + 1) & (delay_size-1); count++; } plugin_data->count = count; plugin_data->prev_law_peak = prev_law_peak; plugin_data->next_law_peak = next_law_peak; plugin_data->prev_law_pos = prev_law_pos; plugin_data->next_law_pos = next_law_pos; plugin_data->delay_pos = delay_pos; plugin_data->old_d_base = new_d_base; }
void Projector::rotate3D(MultidimArray<Complex > &f3d, Matrix2D<DOUBLE> &A, bool inv) { DOUBLE fx, fy, fz, xp, yp, zp; int x0, x1, y0, y1, z0, z1, y, z, y2, z2, r2; bool is_neg_x; Complex d000, d010, d100, d110, d001, d011, d101, d111, dx00, dx10, dxy0, dx01, dx11, dxy1; Matrix2D<DOUBLE> Ainv; // f3d should already be in the right size (ori_size,orihalfdim) // AND the points outside max_r should already be zero... // f3d.initZeros(); // Use the inverse matrix if (inv) Ainv = A; else Ainv = A.transpose(); // The f3d image may be smaller than r_max, in that case also make sure not to fill the corners! int my_r_max = XMIPP_MIN(r_max, XSIZE(f3d) - 1); // Go from the 3D rotated coordinates to the original map coordinates Ainv *= (DOUBLE)padding_factor; // take scaling into account directly int max_r2 = my_r_max * my_r_max; int min_r2_nn = r_min_nn * r_min_nn; #ifdef DEBUG std::cerr << " XSIZE(f3d)= "<< XSIZE(f3d) << std::endl; std::cerr << " YSIZE(f3d)= "<< YSIZE(f3d) << std::endl; std::cerr << " XSIZE(data)= "<< XSIZE(data) << std::endl; std::cerr << " YSIZE(data)= "<< YSIZE(data) << std::endl; std::cerr << " STARTINGX(data)= "<< STARTINGX(data) << std::endl; std::cerr << " STARTINGY(data)= "<< STARTINGY(data) << std::endl; std::cerr << " STARTINGZ(data)= "<< STARTINGZ(data) << std::endl; std::cerr << " max_r= "<< r_max << std::endl; std::cerr << " Ainv= " << Ainv << std::endl; #endif for (int k=0; k < ZSIZE(f3d); k++) { // Don't search beyond square with side max_r if (k <= my_r_max) { z = k; } else if (k >= ZSIZE(f3d) - my_r_max) { z = k - ZSIZE(f3d); } else continue; z2 = z * z; for (int i=0; i < YSIZE(f3d); i++) { // Don't search beyond square with side max_r if (i <= my_r_max) { y = i; } else if (i >= YSIZE(f3d) - my_r_max) { y = i - YSIZE(f3d); } else continue; y2 = y * y; for (int x=0; x <= my_r_max; x++) { // Only include points with radius < max_r (exclude points outside circle in square) r2 = x * x + y2 + z2; if (r2 > max_r2) continue; // Get logical coordinates in the 3D map xp = Ainv(0,0) * x + Ainv(0,1) * y + Ainv(0,2) * z; yp = Ainv(1,0) * x + Ainv(1,1) * y + Ainv(1,2) * z; zp = Ainv(2,0) * x + Ainv(2,1) * y + Ainv(2,2) * z; if (interpolator == TRILINEAR || r2 < min_r2_nn) { // Only asymmetric half is stored if (xp < 0) { // Get complex conjugated hermitian symmetry pair xp = -xp; yp = -yp; zp = -zp; is_neg_x = true; } else { is_neg_x = false; } // Trilinear interpolation (with physical coords) // Subtract STARTINGY to accelerate access to data (STARTINGX=0) // In that way use DIRECT_A3D_ELEM, rather than A3D_ELEM x0 = FLOOR(xp); fx = xp - x0; x1 = x0 + 1; y0 = FLOOR(yp); fy = yp - y0; y0 -= STARTINGY(data); y1 = y0 + 1; z0 = FLOOR(zp); fz = zp - z0; z0 -= STARTINGZ(data); z1 = z0 + 1; // Matrix access can be accelerated through pre-calculation of z0*xydim etc. d000 = DIRECT_A3D_ELEM(data, z0, y0, x0); d001 = DIRECT_A3D_ELEM(data, z0, y0, x1); d010 = DIRECT_A3D_ELEM(data, z0, y1, x0); d011 = DIRECT_A3D_ELEM(data, z0, y1, x1); d100 = DIRECT_A3D_ELEM(data, z1, y0, x0); d101 = DIRECT_A3D_ELEM(data, z1, y0, x1); d110 = DIRECT_A3D_ELEM(data, z1, y1, x0); d111 = DIRECT_A3D_ELEM(data, z1, y1, x1); // Set the interpolated value in the 2D output array // interpolate in x #ifndef FLOAT_PRECISION __m256d __fx = _mm256_set1_pd(fx); __m256d __interpx1 = LIN_INTERP_AVX(_mm256_setr_pd(d000.real, d000.imag, d100.real, d100.imag), _mm256_setr_pd(d001.real, d001.imag, d101.real, d101.imag), __fx); __m256d __interpx2 = LIN_INTERP_AVX(_mm256_setr_pd(d010.real, d010.imag, d110.real, d110.imag), _mm256_setr_pd(d011.real, d011.imag, d111.real, d111.imag), __fx); // interpolate in y __m256d __fy = _mm256_set1_pd(fy); __m256d __interpy = LIN_INTERP_AVX(__interpx1, __interpx2, __fy); #else __m128 __fx = _mm_set1_ps(fx); __m128 __interpx1 = LIN_INTERP_AVX(_mm_setr_ps(d000.real, d000.imag, d100.real, d100.imag), _mm_setr_ps(d001.real, d001.imag, d101.real, d101.imag), __fx); __m128 __interpx2 = LIN_INTERP_AVX(_mm_setr_ps(d010.real, d010.imag, d110.real, d110.imag), _mm_setr_ps(d011.real, d011.imag, d111.real, d111.imag), __fx); // interpolate in y __m128 __fy = _mm_set1_ps(fy); __m128 __interpy = LIN_INTERP_AVX(__interpx1, __interpx2, __fy); #endif Complex* interpy = (Complex*)&__interpy; //interpolate in z DIRECT_A3D_ELEM(f3d, k, i, x) = LIN_INTERP(fz, interpy[0], interpy[1]); // Take complex conjugated for half with negative x if (is_neg_x) DIRECT_A3D_ELEM(f3d, k, i, x) = conj(DIRECT_A3D_ELEM(f3d, k, i, x)); } // endif TRILINEAR else if (interpolator == NEAREST_NEIGHBOUR ) { x0 = ROUND(xp); y0 = ROUND(yp); z0 = ROUND(zp); if (x0 < 0) DIRECT_A3D_ELEM(f3d, k, i, x) = conj(A3D_ELEM(data, -z0, -y0, -x0)); else DIRECT_A3D_ELEM(f3d, k, i, x) = A3D_ELEM(data, z0, y0, x0); } // endif NEAREST_NEIGHBOUR else REPORT_ERROR("Unrecognized interpolator in Projector::project"); } // endif x-loop } // endif y-loop } // endif z-loop }
static block_t * DoWork( filter_t * p_filter, block_t * p_in_buf ) { int i_samples = p_in_buf->i_nb_samples; int i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio ); float *pf_buf = (float*)p_in_buf->p_buffer; /* Current parameters */ filter_sys_t *p_sys = p_filter->p_sys; /* Fetch the configurable parameters */ vlc_mutex_lock( &p_sys->lock ); float f_rms_peak = p_sys->f_rms_peak; /* RMS/peak */ float f_attack = p_sys->f_attack; /* Attack time (ms) */ float f_release = p_sys->f_release; /* Release time (ms) */ float f_threshold = p_sys->f_threshold; /* Threshold level (dB) */ float f_ratio = p_sys->f_ratio; /* Ratio (n:1) */ float f_knee = p_sys->f_knee; /* Knee radius (dB) */ float f_makeup_gain = p_sys->f_makeup_gain; /* Makeup gain (dB) */ vlc_mutex_unlock( &p_sys->lock ); /* Fetch the internal parameters */ float f_amp = p_sys->f_amp; float *pf_as = p_sys->pf_as; float f_env = p_sys->f_env; float f_env_peak = p_sys->f_env_peak; float f_env_rms = p_sys->f_env_rms; float f_gain = p_sys->f_gain; float f_gain_out = p_sys->f_gain_out; rms_env *p_rms = &p_sys->rms; float f_sum = p_sys->f_sum; lookahead *p_la = &p_sys->la; /* Prepare other compressor parameters */ float f_ga = f_attack < 2.0f ? 0.0f : pf_as[Round( f_attack * 0.001f * ( A_TBL - 1 ) )]; float f_gr = pf_as[Round( f_release * 0.001f * ( A_TBL - 1 ) )]; float f_rs = ( f_ratio - 1.0f ) / f_ratio; float f_mug = Db2Lin( f_makeup_gain, p_sys ); float f_knee_min = Db2Lin( f_threshold - f_knee, p_sys ); float f_knee_max = Db2Lin( f_threshold + f_knee, p_sys ); float f_ef_a = f_ga * 0.25f; float f_ef_ai = 1.0f - f_ef_a; /* Process the current buffer */ for( int i = 0; i < i_samples; i++ ) { float f_lev_in_old, f_lev_in_new; /* Now, compress the pre-equalized audio (ported from sc4_1882 * plugin with a few modifications) */ /* Fetch the old delayed buffer value */ f_lev_in_old = p_la->p_buf[p_la->i_pos].f_lev_in; /* Find the peak value of current sample. This becomes the new delayed * buffer value that replaces the old one in the lookahead array */ f_lev_in_new = fabs( pf_buf[0] ); for( int i_chan = 1; i_chan < i_channels; i_chan++ ) { f_lev_in_new = Max( f_lev_in_new, fabs( pf_buf[i_chan] ) ); } p_la->p_buf[p_la->i_pos].f_lev_in = f_lev_in_new; /* Add the square of the peak value to a running sum */ f_sum += f_lev_in_new * f_lev_in_new; /* Update the RMS envelope */ if( f_amp > f_env_rms ) { f_env_rms = f_env_rms * f_ga + f_amp * ( 1.0f - f_ga ); } else { f_env_rms = f_env_rms * f_gr + f_amp * ( 1.0f - f_gr ); } RoundToZero( &f_env_rms ); /* Update the peak envelope */ if( f_lev_in_old > f_env_peak ) { f_env_peak = f_env_peak * f_ga + f_lev_in_old * ( 1.0f - f_ga ); } else { f_env_peak = f_env_peak * f_gr + f_lev_in_old * ( 1.0f - f_gr ); } RoundToZero( &f_env_peak ); /* Process the RMS value and update the output gain every 4 samples */ if( ( p_sys->i_count++ & 3 ) == 3 ) { /* Process the RMS value by placing in the mean square value, and * reset the running sum */ f_amp = RmsEnvProcess( p_rms, f_sum * 0.25f ); f_sum = 0.0f; if( cover_isnan( f_env_rms ) ) // sunqueen modify { /* This can happen sometimes, but I don't know why. */ f_env_rms = 0.0f; } /* Find the superposition of the RMS and peak envelopes */ f_env = LIN_INTERP( f_rms_peak, f_env_rms, f_env_peak ); /* Update the output gain */ if( f_env <= f_knee_min ) { /* Gain below the knee (and below the threshold) */ f_gain_out = 1.0f; } else if( f_env < f_knee_max ) { /* Gain within the knee */ const float f_x = -( f_threshold - f_knee - Lin2Db( f_env, p_sys ) ) / f_knee; f_gain_out = Db2Lin( -f_knee * f_rs * f_x * f_x * 0.25f, p_sys ); } else { /* Gain above the knee (and above the threshold) */ f_gain_out = Db2Lin( ( f_threshold - Lin2Db( f_env, p_sys ) ) * f_rs, p_sys ); } } /* Find the total gain */ f_gain = f_gain * f_ef_a + f_gain_out * f_ef_ai; /* Write the resulting buffer to the output */ BufferProcess( pf_buf, i_channels, f_gain, f_mug, p_la ); pf_buf += i_channels; } /* Update the internal parameters */ p_sys->f_sum = f_sum; p_sys->f_amp = f_amp; p_sys->f_gain = f_gain; p_sys->f_gain_out = f_gain_out; p_sys->f_env = f_env; p_sys->f_env_rms = f_env_rms; p_sys->f_env_peak = f_env_peak; return p_in_buf; }
static void runAddingDelay_l(LADSPA_Handle instance, unsigned long sample_count) { Delay_l *plugin_data = (Delay_l *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Input (array of floats of length sample_count) */ const LADSPA_Data * const in = plugin_data->in; /* Output (array of floats of length sample_count) */ LADSPA_Data * const out = plugin_data->out; /* Delay Time (s) (float value) */ const LADSPA_Data delay_time = *(plugin_data->delay_time); LADSPA_Data * buffer = plugin_data->buffer; unsigned int buffer_mask = plugin_data->buffer_mask; LADSPA_Data delay_samples = plugin_data->delay_samples; LADSPA_Data last_delay_time = plugin_data->last_delay_time; unsigned int sample_rate = plugin_data->sample_rate; long write_phase = plugin_data->write_phase; unsigned int i; if (write_phase == 0) { plugin_data->last_delay_time = delay_time; plugin_data->delay_samples = delay_samples = CALC_DELAY (delay_time); } if (delay_time == last_delay_time) { long idelay_samples = (long)delay_samples; LADSPA_Data frac = delay_samples - idelay_samples; for (i=0; i<sample_count; i++) { long read_phase = write_phase - (long)delay_samples; LADSPA_Data read; read = LIN_INTERP (frac, buffer[(read_phase-1) & buffer_mask], buffer[read_phase & buffer_mask]); buffer[write_phase & buffer_mask] = in[i]; buffer_write(out[i], read); write_phase++; } } else { float next_delay_samples = CALC_DELAY (delay_time); float delay_samples_slope = (next_delay_samples - delay_samples) / sample_count; for (i=0; i<sample_count; i++) { long read_phase, idelay_samples; LADSPA_Data frac, read; delay_samples += delay_samples_slope; write_phase++; read_phase = write_phase - (long)delay_samples; idelay_samples = (long)delay_samples; frac = delay_samples - idelay_samples; read = LIN_INTERP (frac, buffer[(read_phase-1) & buffer_mask], buffer[read_phase & buffer_mask]); buffer[write_phase & buffer_mask] = in[i]; buffer_write(out[i], read); } plugin_data->last_delay_time = delay_time; plugin_data->delay_samples = delay_samples; } plugin_data->write_phase = write_phase; }
static void runVynil(LADSPA_Handle instance, unsigned long sample_count) { Vynil *plugin_data = (Vynil *)instance; /* Year (float value) */ const LADSPA_Data year = *(plugin_data->year); /* RPM (float value) */ const LADSPA_Data rpm = *(plugin_data->rpm); /* Surface warping (float value) */ const LADSPA_Data warp = *(plugin_data->warp); /* Crackle (float value) */ const LADSPA_Data click = *(plugin_data->click); /* Wear (float value) */ const LADSPA_Data wear = *(plugin_data->wear); /* Input L (array of floats of length sample_count) */ const LADSPA_Data * const in_l = plugin_data->in_l; /* Input R (array of floats of length sample_count) */ const LADSPA_Data * const in_r = plugin_data->in_r; /* Output L (array of floats of length sample_count) */ LADSPA_Data * const out_l = plugin_data->out_l; /* Output R (array of floats of length sample_count) */ LADSPA_Data * const out_r = plugin_data->out_r; LADSPA_Data * buffer_m = plugin_data->buffer_m; unsigned int buffer_mask = plugin_data->buffer_mask; unsigned int buffer_pos = plugin_data->buffer_pos; LADSPA_Data * buffer_s = plugin_data->buffer_s; LADSPA_Data * click_buffer = plugin_data->click_buffer; fixp16 click_buffer_omega = plugin_data->click_buffer_omega; fixp16 click_buffer_pos = plugin_data->click_buffer_pos; float click_gain = plugin_data->click_gain; float def = plugin_data->def; float def_target = plugin_data->def_target; float fs = plugin_data->fs; biquad * highp = plugin_data->highp; biquad * lowp_m = plugin_data->lowp_m; biquad * lowp_s = plugin_data->lowp_s; biquad * noise_filt = plugin_data->noise_filt; float phi = plugin_data->phi; unsigned int sample_cnt = plugin_data->sample_cnt; #line 90 "vynil_1905.xml" unsigned long pos; float deflec = def; float deflec_target = def_target; float src_m, src_s; /* angular velocity of platter * 16 */ const float omega = 960.0f / (rpm * fs); const float age = (2000 - year) * 0.01f; const unsigned int click_prob = (age*age*(float)RAND_MAX)/10 + click * 0.02 * RAND_MAX; const float noise_amp = (click + wear * 0.3f) * 0.12f + (1993.0f - year) * 0.0031f; const float bandwidth = (year - 1880.0f) * (rpm * 1.9f); const float noise_bandwidth = bandwidth * (0.25 - wear * 0.02) + click * 200.0 + 300.0; const float stereo = f_clamp((year - 1940.0f) * 0.02f, 0.0f, 1.0f); const float wrap_gain = age * 3.1f + 0.05f; const float wrap_bias = age * 0.1f; lp_set_params(lowp_m, bandwidth * (1.0 - wear * 0.86), 2.0, fs); lp_set_params(lowp_s, bandwidth * (1.0 - wear * 0.89), 2.0, fs); hp_set_params(highp, (2000-year) * 8.0, 1.5, fs); lp_set_params(noise_filt, noise_bandwidth, 4.0 + wear * 2.0, fs); for (pos = 0; pos < sample_count; pos++) { unsigned int o1, o2; float ofs; if ((sample_cnt & 15) == 0) { const float ang = phi * 2.0f * M_PI; const float w = warp * (2000.0f - year) * 0.01f; deflec_target = w*df(ang)*0.5f + w*w*df(2.0f*ang)*0.31f + w*w*w*df(3.0f*ang)*0.129f; phi += omega; while (phi > 1.0f) { phi -= 1.0f; } if ((unsigned int)rand() < click_prob) { click_buffer_omega.all = ((rand() >> 6) + 1000) * rpm; click_gain = noise_amp * 5.0f * noise(); } } deflec = deflec * 0.1f + deflec_target * 0.9f; /* matrix into mid_side representation (this is roughly what stereo * LPs do) */ buffer_m[buffer_pos] = in_l[pos] + in_r[pos]; buffer_s[buffer_pos] = in_l[pos] - in_r[pos]; /* cacluate the effects of the surface warping */ ofs = fs * 0.009f * deflec; o1 = f_round(floorf(ofs)); o2 = f_round(ceilf(ofs)); ofs -= o1; src_m = LIN_INTERP(ofs, buffer_m[(buffer_pos - o1 - 1) & buffer_mask], buffer_m[(buffer_pos - o2 - 1) & buffer_mask]); src_s = LIN_INTERP(ofs, buffer_s[(buffer_pos - o1 - 1) & buffer_mask], buffer_s[(buffer_pos - o2 - 1) & buffer_mask]); src_m = biquad_run(lowp_m, src_m + click_buffer[click_buffer_pos.part.in & (CLICK_BUF_SIZE - 1)] * click_gain); /* waveshaper */ src_m = LIN_INTERP(age, src_m, sinf(src_m * wrap_gain + wrap_bias)); /* output highpass */ src_m = biquad_run(highp, src_m) + biquad_run(noise_filt, noise()) * noise_amp + click_buffer[click_buffer_pos.part.in & (CLICK_BUF_SIZE - 1)] * click_gain * 0.5f; /* stereo seperation filter */ src_s = biquad_run(lowp_s, src_s) * stereo; buffer_write(out_l[pos], (src_s + src_m) * 0.5f); buffer_write(out_r[pos], (src_m - src_s) * 0.5f); /* roll buffer indexes */ buffer_pos = (buffer_pos + 1) & buffer_mask; click_buffer_pos.all += click_buffer_omega.all; if (click_buffer_pos.part.in >= CLICK_BUF_SIZE) { click_buffer_pos.all = 0; click_buffer_omega.all = 0; } sample_cnt++; }
static void runSc4(LADSPA_Handle instance, unsigned long sample_count) { Sc4 *plugin_data = (Sc4 *)instance; /* RMS/peak (float value) */ const LADSPA_Data rms_peak = *(plugin_data->rms_peak); /* Attack time (ms) (float value) */ const LADSPA_Data attack = *(plugin_data->attack); /* Release time (ms) (float value) */ const LADSPA_Data release = *(plugin_data->release); /* Threshold level (dB) (float value) */ const LADSPA_Data threshold = *(plugin_data->threshold); /* Ratio (1:n) (float value) */ const LADSPA_Data ratio = *(plugin_data->ratio); /* Knee radius (dB) (float value) */ const LADSPA_Data knee = *(plugin_data->knee); /* Makeup gain (dB) (float value) */ const LADSPA_Data makeup_gain = *(plugin_data->makeup_gain); /* Left input (array of floats of length sample_count) */ const LADSPA_Data * const left_in = plugin_data->left_in; /* Right input (array of floats of length sample_count) */ const LADSPA_Data * const right_in = plugin_data->right_in; /* Left output (array of floats of length sample_count) */ LADSPA_Data * const left_out = plugin_data->left_out; /* Right output (array of floats of length sample_count) */ LADSPA_Data * const right_out = plugin_data->right_out; float amp = plugin_data->amp; float * as = plugin_data->as; unsigned int count = plugin_data->count; float env = plugin_data->env; float env_peak = plugin_data->env_peak; float env_rms = plugin_data->env_rms; float gain = plugin_data->gain; float gain_t = plugin_data->gain_t; rms_env * rms = plugin_data->rms; float sum = plugin_data->sum; #line 51 "sc4_1434.xml" unsigned long pos; const float ga = attack < 2.0f ? 0.0f : as[f_round(attack * 0.001f * (float)(A_TBL-1))]; const float gr = as[f_round(release * 0.001f * (float)(A_TBL-1))]; const float rs = (ratio - 1.0f) / ratio; const float mug = db2lin(makeup_gain); const float knee_min = db2lin(threshold - knee); const float knee_max = db2lin(threshold + knee); const float ef_a = ga * 0.25f; const float ef_ai = 1.0f - ef_a; for (pos = 0; pos < sample_count; pos++) { const float la = fabs(left_in[pos]); const float ra = fabs(right_in[pos]); const float lev_in = f_max(la, ra); sum += lev_in * lev_in; if (amp > env_rms) { env_rms = env_rms * ga + amp * (1.0f - ga); } else { env_rms = env_rms * gr + amp * (1.0f - gr); } if (lev_in > env_peak) { env_peak = env_peak * ga + lev_in * (1.0f - ga); } else { env_peak = env_peak * gr + lev_in * (1.0f - gr); } if ((count++ & 3) == 3) { amp = rms_env_process(rms, sum * 0.25f); sum = 0.0f; if (isnan(env_rms)) { // This can happen sometimes, but I don't know why env_rms = 0.0f; } env = LIN_INTERP(rms_peak, env_rms, env_peak); if (env <= knee_min) { gain_t = 1.0f; } else if (env < knee_max) { const float x = -(threshold - knee - lin2db(env)) / knee; gain_t = db2lin(-knee * rs * x * x * 0.25f); } else { gain_t = db2lin((threshold - lin2db(env)) * rs); } } gain = gain * ef_a + gain_t * ef_ai; buffer_write(left_out[pos], left_in[pos] * gain * mug); buffer_write(right_out[pos], right_in[pos] * gain * mug); } plugin_data->sum = sum; plugin_data->amp = amp; plugin_data->gain = gain; plugin_data->gain_t = gain_t; plugin_data->env = env; plugin_data->env_rms = env_rms; plugin_data->env_peak = env_peak; plugin_data->count = count; *(plugin_data->amplitude) = lin2db(env); *(plugin_data->gain_red) = lin2db(gain); }
static void runAddingRetroFlange(LADSPA_Handle instance, unsigned long sample_count) { RetroFlange *plugin_data = (RetroFlange *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Average stall (ms) (float value) */ const LADSPA_Data delay_depth_avg = *(plugin_data->delay_depth_avg); /* Flange frequency (Hz) (float value) */ const LADSPA_Data law_freq = *(plugin_data->law_freq); /* 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; LADSPA_Data * buffer = plugin_data->buffer; long buffer_size = plugin_data->buffer_size; long count = plugin_data->count; LADSPA_Data * delay_line = plugin_data->delay_line; int delay_line_length = plugin_data->delay_line_length; int delay_pos = plugin_data->delay_pos; LADSPA_Data last_in = plugin_data->last_in; int last_law_p = plugin_data->last_law_p; int last_phase = plugin_data->last_phase; int max_law_p = plugin_data->max_law_p; float next_law_peak = plugin_data->next_law_peak; int next_law_pos = plugin_data->next_law_pos; float phase = plugin_data->phase; float prev_law_peak = plugin_data->prev_law_peak; int prev_law_pos = plugin_data->prev_law_pos; long sample_rate = plugin_data->sample_rate; LADSPA_Data z0 = plugin_data->z0; LADSPA_Data z1 = plugin_data->z1; LADSPA_Data z2 = plugin_data->z2; #line 75 "retro_flange_1208.xml" long int pos; int law_p = f_trunc(LIMIT(sample_rate / f_clamp(law_freq, 0.0001f, 100.0f), 1, max_law_p)); float increment; float lin_int, lin_inc; int track; int fph; LADSPA_Data out = 0.0f; const float dda_c = f_clamp(delay_depth_avg, 0.0f, 10.0f); int dl_used = (dda_c * sample_rate) / 1000; float inc_base = 1000.0f * (float)BASE_BUFFER; const float delay_depth = 2.0f * dda_c; float n_ph, p_ph, law; for (pos = 0; pos < sample_count; pos++) { // Write into the delay line delay_line[delay_pos] = input[pos]; z0 = delay_line[MOD(delay_pos - dl_used, delay_line_length)] + 0.12919609397f*z1 - 0.31050847f*z2; out = sat(z0*0.20466966f + z1*0.40933933f + z2*0.40933933f, -0.23f, 3.3f); z2 = z1; z1 = z0; delay_pos = (delay_pos + 1) % delay_line_length; if ((count++ % law_p) == 0) { // Value for amplitude of law peak next_law_peak = (float)rand() / (float)RAND_MAX; next_law_pos = count + law_p; } else if (count % law_p == law_p / 2) { // Value for amplitude of law peak prev_law_peak = (float)rand() / (float)RAND_MAX; prev_law_pos = count + law_p; } n_ph = (float)(law_p - abs(next_law_pos - count))/(float)law_p; p_ph = n_ph + 0.5f; if (p_ph > 1.0f) { p_ph -= 1.0f; } law = f_sin_sq(3.1415926f*p_ph)*prev_law_peak + f_sin_sq(3.1415926f*n_ph)*next_law_peak; increment = inc_base / (delay_depth * law + 0.2); fph = f_trunc(phase); last_phase = fph; lin_int = phase - (float)fph; out += LIN_INTERP(lin_int, buffer[(fph+1) % buffer_size], buffer[(fph+2) % buffer_size]); phase += increment; lin_inc = 1.0f / (floor(phase) - last_phase + 1); lin_inc = lin_inc > 1.0f ? 1.0f : lin_inc; lin_int = 0.0f; for (track = last_phase; track < phase; track++) { lin_int += lin_inc; buffer[track % buffer_size] = LIN_INTERP(lin_int, last_in, input[pos]); } last_in = input[pos]; buffer_write(output[pos], out * 0.707f); if (phase >= buffer_size) { phase -= buffer_size; } } // Store current phase in instance plugin_data->phase = phase; plugin_data->prev_law_peak = prev_law_peak; plugin_data->next_law_peak = next_law_peak; plugin_data->prev_law_pos = prev_law_pos; plugin_data->next_law_pos = next_law_pos; plugin_data->last_phase = last_phase; plugin_data->last_in = last_in; plugin_data->count = count; plugin_data->last_law_p = last_law_p; plugin_data->delay_pos = delay_pos; plugin_data->z0 = z0; plugin_data->z1 = z1; plugin_data->z2 = z2; }
static void runAddingGiantFlange(LADSPA_Handle instance, unsigned long sample_count) { GiantFlange *plugin_data = (GiantFlange *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Double delay (float value) */ const LADSPA_Data deldouble = *(plugin_data->deldouble); /* LFO frequency 1 (Hz) (float value) */ const LADSPA_Data freq1 = *(plugin_data->freq1); /* Delay 1 range (s) (float value) */ const LADSPA_Data delay1 = *(plugin_data->delay1); /* LFO frequency 2 (Hz) (float value) */ const LADSPA_Data freq2 = *(plugin_data->freq2); /* Delay 2 range (s) (float value) */ const LADSPA_Data delay2 = *(plugin_data->delay2); /* Feedback (float value) */ const LADSPA_Data feedback = *(plugin_data->feedback); /* Dry/Wet level (float value) */ const LADSPA_Data wet = *(plugin_data->wet); /* 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; int16_t * buffer = plugin_data->buffer; unsigned int buffer_mask = plugin_data->buffer_mask; unsigned int buffer_pos = plugin_data->buffer_pos; float fs = plugin_data->fs; float x1 = plugin_data->x1; float x2 = plugin_data->x2; float y1 = plugin_data->y1; float y2 = plugin_data->y2; #line 59 "giant_flange_1437.xml" unsigned long pos; const float omega1 = 6.2831852f * (freq1 / fs); const float omega2 = 6.2831852f * (freq2 / fs); float fb; float d1, d2; float d1out, d2out; float fbs; if (feedback > 99.0f) { fb = 0.99f; } else if (feedback < -99.0f) { fb = -0.99f; } else { fb = feedback * 0.01f; } if (f_round(deldouble)) { const float dr1 = delay1 * fs * 0.25f; const float dr2 = delay2 * fs * 0.25f; for (pos = 0; pos < sample_count; pos++) { /* Write input into delay line */ buffer[buffer_pos] = f_round(input[pos] * INT_SCALE); /* Calcuate delays */ d1 = (x1 + 1.0f) * dr1; d2 = (y2 + 1.0f) * dr2; d1out = buffer[(buffer_pos - f_round(d1)) & buffer_mask] * INT_SCALE_R; d2out = buffer[(buffer_pos - f_round(d2)) & buffer_mask] * INT_SCALE_R; /* Add feedback, must be done afterwards for case where delay = 0 */ fbs = input[pos] + (d1out + d2out) * fb; if(fbs < CLIP && fbs > -CLIP) { buffer[buffer_pos] = fbs * INT_SCALE; } else if (fbs > 0.0f) { buffer[buffer_pos] = (MAX_AMP - (CLIP_A / (CLIP_B + fbs))) * INT_SCALE; } else { buffer[buffer_pos] = (MAX_AMP - (CLIP_A / (CLIP_B - fbs))) * -INT_SCALE; } /* Write output */ buffer_write(output[pos], LIN_INTERP(wet, input[pos], d1out + d2out)); if (pos % 2) { buffer_pos = (buffer_pos + 1) & buffer_mask; } /* Run LFOs */ x1 -= omega1 * y1; y1 += omega1 * x1; x2 -= omega2 * y2; y2 += omega2 * x2; } } else { const float dr1 = delay1 * fs * 0.5f; const float dr2 = delay2 * fs * 0.5f; for (pos = 0; pos < sample_count; pos++) { /* Write input into delay line */ buffer[buffer_pos] = f_round(input[pos] * INT_SCALE); /* Calcuate delays */ d1 = (x1 + 1.0f) * dr1; d2 = (y2 + 1.0f) * dr2; d1out = buffer[(buffer_pos - f_round(d1)) & buffer_mask] * INT_SCALE_R; d2out = buffer[(buffer_pos - f_round(d2)) & buffer_mask] * INT_SCALE_R; /* Add feedback, must be done afterwards for case where delay = 0 */ fbs = input[pos] + (d1out + d2out) * fb; if(fbs < CLIP && fbs > -CLIP) { buffer[buffer_pos] = fbs * INT_SCALE; } else if (fbs > 0.0f) { buffer[buffer_pos] = (MAX_AMP - (CLIP_A / (CLIP_B + fbs))) * INT_SCALE; } else { buffer[buffer_pos] = (MAX_AMP - (CLIP_A / (CLIP_B - fbs))) * -INT_SCALE; } /* Write output */ buffer_write(output[pos], LIN_INTERP(wet, input[pos], d1out + d2out)); buffer_pos = (buffer_pos + 1) & buffer_mask; /* Run LFOs */ x1 -= omega1 * y1; y1 += omega1 * x1; x2 -= omega2 * y2; y2 += omega2 * x2; } } plugin_data->x1 = x1; plugin_data->y1 = y1; plugin_data->x2 = x2; plugin_data->y2 = y2; plugin_data->buffer_pos = buffer_pos; }