void runAmPitchshift(LADSPA_Handle instance, unsigned long sample_count) { AmPitchshift *plugin_data = (AmPitchshift *)instance; /* Pitch shift (float value) */ const LADSPA_Data pitch = *(plugin_data->pitch); /* Buffer size (float value) */ const LADSPA_Data size = *(plugin_data->size); /* 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 count = plugin_data->count; LADSPA_Data * delay = plugin_data->delay; unsigned int delay_mask = plugin_data->delay_mask; unsigned int delay_ofs = plugin_data->delay_ofs; float last_gain = plugin_data->last_gain; float last_inc = plugin_data->last_inc; int last_size = plugin_data->last_size; fixp16 rptr = plugin_data->rptr; unsigned int wptr = plugin_data->wptr; //#line 43 "am_pitchshift_1433.xml" unsigned long pos; fixp16 om; float gain = last_gain, gain_inc = last_inc; unsigned int i; om.all = f_round(pitch * 65536.0f); if (size != last_size) { int size_tmp = f_round(size); if (size_tmp > 7) { size_tmp = 5; } else if (size_tmp < 1) { size_tmp = 1; } plugin_data->last_size = size; /* Calculate the ringbuf parameters, the magick constants will need * to be changed if you change DELAY_SIZE */ delay_mask = (1 << (size_tmp + 6)) - 1; delay_ofs = 1 << (size_tmp + 5); } for (pos = 0; pos < sample_count; pos++) { float out = 0.0f; if (count++ > 14) { float tmp; count = 0; tmp = 0.5f * (float)((rptr.part.in - wptr + delay_ofs/2) & delay_mask) / (float)delay_ofs; tmp = sinf(M_PI * 2.0f * tmp) * 0.5f + 0.5f; gain_inc = (tmp - gain) / 15.0f; } gain += gain_inc; delay[wptr] = input[pos]; /* Add contributions from the two readpointers, scaled by thier * distance from the write pointer */ i = rptr.part.in; out += cube_interp((float)rptr.part.fr * 0.0000152587f, delay[(i - 1) & delay_mask], delay[i], delay[(i + 1) & delay_mask], delay[(i + 2) & delay_mask]) * (1.0f - gain); i += delay_ofs; out += cube_interp((float)rptr.part.fr * 0.0000152587f, delay[(i - 1) & delay_mask], delay[i & delay_mask], delay[(i + 1) & delay_mask], delay[(i + 2) & delay_mask]) * gain; buffer_write(output[pos], out); /* Increment ringbuffer pointers */ wptr = (wptr + 1) & delay_mask; rptr.all += om.all; rptr.part.in &= delay_mask; } plugin_data->rptr.all = rptr.all; plugin_data->wptr = wptr; plugin_data->delay_mask = delay_mask; plugin_data->delay_ofs = delay_ofs; plugin_data->last_gain = gain; plugin_data->count = count; plugin_data->last_inc = gain_inc; *(plugin_data->latency) = delay_ofs/2; }
static void runAddingLfoPhaser(LADSPA_Handle instance, unsigned long sample_count) { LfoPhaser *plugin_data = (LfoPhaser *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* LFO rate (Hz) (float value) */ const LADSPA_Data lfo_rate = *(plugin_data->lfo_rate); /* LFO depth (float value) */ const LADSPA_Data lfo_depth = *(plugin_data->lfo_depth); /* Feedback (float value) */ const LADSPA_Data fb = *(plugin_data->fb); /* Spread (octaves) (float value) */ const LADSPA_Data spread = *(plugin_data->spread); /* 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; allpass * ap = plugin_data->ap; int count = plugin_data->count; float f_per_lv = plugin_data->f_per_lv; int lfo_pos = plugin_data->lfo_pos; float * lfo_tbl = plugin_data->lfo_tbl; float ym1 = plugin_data->ym1; #line 114 "phasers_1217.xml" unsigned long pos; unsigned int mod; float y, d, ofs; mod = f_round(f_per_lv / lfo_rate); if (mod < 1) { mod=1; } d = lfo_tbl[lfo_pos]; for (pos = 0; pos < sample_count; pos++) { // Get new value for LFO if needed if (++count % mod == 0) { lfo_pos++; lfo_pos &= 0x7FF; count = 0; d = lfo_tbl[lfo_pos] * lfo_depth; ap_set_delay(ap, d); ofs = spread * 0.01562f; ap_set_delay(ap+1, d+ofs); ofs *= 2.0f; ap_set_delay(ap+2, d+ofs); ofs *= 2.0f; ap_set_delay(ap+3, d+ofs); ofs *= 2.0f; ap_set_delay(ap+4, d+ofs); ofs *= 2.0f; ap_set_delay(ap+5, d+ofs); } //Run in series, doesn't quite sound as nice y = ap_run(ap, input[pos] + ym1 * fb); y = ap_run(ap+1, y); y = ap_run(ap+2, y); y = ap_run(ap+3, y); y = ap_run(ap+4, y); y = ap_run(ap+5, y); buffer_write(output[pos], y); ym1 = y; } plugin_data->ym1 = ym1; plugin_data->count = count; plugin_data->lfo_pos = lfo_pos; }
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 runAddingMatrixSpatialiser(LADSPA_Handle instance, unsigned long sample_count) { MatrixSpatialiser *plugin_data = (MatrixSpatialiser *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Input L (array of floats of length sample_count) */ const LADSPA_Data * const i_left = plugin_data->i_left; /* Input R (array of floats of length sample_count) */ const LADSPA_Data * const i_right = plugin_data->i_right; /* Width (float value) */ const LADSPA_Data width = *(plugin_data->width); /* Output L (array of floats of length sample_count) */ LADSPA_Data * const o_left = plugin_data->o_left; /* Output R (array of floats of length sample_count) */ LADSPA_Data * const o_right = plugin_data->o_right; LADSPA_Data current_m_gain = plugin_data->current_m_gain; LADSPA_Data current_s_gain = plugin_data->current_s_gain; #line 100 "matrix_spatialiser_1422.xml" unsigned long pos; LADSPA_Data mid, side; LADSPA_Data m_gain, s_gain; int width_ = f_round(width + EQUALGAINPOINT_OFFSET); /* smoothen the gain changes. to spread the curve over the entire buffer length (i.e.#sample_count samples), make lp dependent on sample_count. */ const float lp = 7.0f / (float) sample_count; /* value found by experiment */ const float lp_i = 1.0f - lp; /* do approximately the same as s_gain = sin(width); m_gain = cos(width); but a lot faster: */ sin_cos_approx(width_, &s_gain, &m_gain); m_gain *= EQUALGAINPOINT_TO_UNITY; /* normalize the neutral */ s_gain *= EQUALGAINPOINT_TO_UNITY; /* setting to unity gain. */ #ifdef DEBUG /* do a "hardware bypass" if width == 0 */ /* no smoothing here */ if (width_ == 128) { for (pos = 0; pos < sample_count; pos++) { buffer_write(o_left[pos], i_left[pos]); buffer_write(o_right[pos], i_right[pos]); } } else #endif for (pos = 0; pos < sample_count; pos++) { current_m_gain = current_m_gain * lp_i + m_gain * lp; current_s_gain = current_s_gain * lp_i + s_gain * lp; mid = (i_left[pos] + i_right[pos]) * 0.5f * current_m_gain; side = (i_left[pos] - i_right[pos]) * 0.5f * current_s_gain; buffer_write(o_left[pos], mid + side); buffer_write(o_right[pos], mid - side); } plugin_data->current_m_gain = current_m_gain; plugin_data->current_s_gain = current_s_gain; }
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; }
static void runAddingTapeDelay(LADSPA_Handle instance, unsigned long sample_count) { TapeDelay *plugin_data = (TapeDelay *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Tape speed (inches/sec, 1=normal) (float value) */ const LADSPA_Data speed = *(plugin_data->speed); /* Dry level (dB) (float value) */ const LADSPA_Data da_db = *(plugin_data->da_db); /* Tap 1 distance (inches) (float value) */ const LADSPA_Data t1d = *(plugin_data->t1d); /* Tap 1 level (dB) (float value) */ const LADSPA_Data t1a_db = *(plugin_data->t1a_db); /* Tap 2 distance (inches) (float value) */ const LADSPA_Data t2d = *(plugin_data->t2d); /* Tap 2 level (dB) (float value) */ const LADSPA_Data t2a_db = *(plugin_data->t2a_db); /* Tap 3 distance (inches) (float value) */ const LADSPA_Data t3d = *(plugin_data->t3d); /* Tap 3 level (dB) (float value) */ const LADSPA_Data t3a_db = *(plugin_data->t3a_db); /* Tap 4 distance (inches) (float value) */ const LADSPA_Data t4d = *(plugin_data->t4d); /* Tap 4 level (dB) (float value) */ const LADSPA_Data t4a_db = *(plugin_data->t4a_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 int buffer_mask = plugin_data->buffer_mask; unsigned int buffer_size = plugin_data->buffer_size; LADSPA_Data last2_in = plugin_data->last2_in; LADSPA_Data last3_in = plugin_data->last3_in; LADSPA_Data last_in = plugin_data->last_in; unsigned int last_phase = plugin_data->last_phase; float phase = plugin_data->phase; int sample_rate = plugin_data->sample_rate; LADSPA_Data z0 = plugin_data->z0; LADSPA_Data z1 = plugin_data->z1; LADSPA_Data z2 = plugin_data->z2; unsigned int pos; float increment = f_clamp(speed, 0.0f, 40.0f); float lin_int, lin_inc; unsigned int track; unsigned int fph; LADSPA_Data out; const float da = DB_CO(da_db); const float t1a = DB_CO(t1a_db); const float t2a = DB_CO(t2a_db); const float t3a = DB_CO(t3a_db); const float t4a = DB_CO(t4a_db); const unsigned int t1d_s = f_round(t1d * sample_rate); const unsigned int t2d_s = f_round(t2d * sample_rate); const unsigned int t3d_s = f_round(t3d * sample_rate); const unsigned int t4d_s = f_round(t4d * sample_rate); for (pos = 0; pos < sample_count; pos++) { fph = f_trunc(phase); last_phase = fph; lin_int = phase - (float)fph; out = buffer[(unsigned int)(fph - t1d_s) & buffer_mask] * t1a; out += buffer[(unsigned int)(fph - t2d_s) & buffer_mask] * t2a; out += buffer[(unsigned int)(fph - t3d_s) & buffer_mask] * t3a; out += buffer[(unsigned int)(fph - t4d_s) & buffer_mask] * t4a; 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_mask] = cube_interp(lin_int, last3_in, last2_in, last_in, input[pos]); } last3_in = last2_in; last2_in = last_in; last_in = input[pos]; out += input[pos] * da; 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; plugin_data->last2_in = last2_in; plugin_data->last3_in = last3_in; plugin_data->z0 = z0; plugin_data->z1 = z1; plugin_data->z2 = z2; }
static void runAddingGsm(LADSPA_Handle instance, unsigned long sample_count) { Gsm *plugin_data = (Gsm *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Dry/wet mix (float value) */ const LADSPA_Data drywet = *(plugin_data->drywet); /* Number of passes (float value) */ const LADSPA_Data passes = *(plugin_data->passes); /* Error rate (bits/block) (float value) */ const LADSPA_Data error = *(plugin_data->error); /* 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 * blf = plugin_data->blf; int count = plugin_data->count; LADSPA_Data * dry = plugin_data->dry; gsm_signal * dst = plugin_data->dst; float fs = plugin_data->fs; gsm handle = plugin_data->handle; int resamp = plugin_data->resamp; float rsf = plugin_data->rsf; gsm_signal * src = plugin_data->src; unsigned long pos; gsm_frame frame; int samp; float part; int error_rate = f_round(error); int num_passes = f_round(passes); fs = fs; // So gcc doesn't think it's unused for (pos = 0; pos < sample_count; pos++) { // oversample into buffer down to aprox 8kHz, 13bit src[count / resamp] += f_round(biquad_run(blf, input[pos]) * rsf); // interpolate output, so it doesn't sound totaly awful samp = count / resamp; part = (float)count / (float)resamp - (float)samp; buffer_write(output[pos], cube_interp(part, dst[samp], dst[samp+1], dst[samp+2], dst[samp+3]) * SCALE_R * drywet + dry[count] * (1.0f - drywet)); // Maintain delayed, dry buffer. dry[count] = input[pos]; count++; // If we have a full, downsampled buffer then run the encode + // decode process. if (count >= 160 * resamp) { int i, j; gsm_signal *in; count = 0; dst[0] = dst[160]; dst[1] = dst[161]; dst[2] = dst[162]; in = src; for (j=0; j<num_passes; j++) { gsm_encode(handle, in, frame); for (i=0; i < error_rate; i++) { frame[1 + (rand() % 32)] ^= bits[rand() % 8]; } gsm_decode(handle, frame, dst+3); in = dst+3; } if (num_passes == 0) { for (j=0; j < 160; j++) { dst[j + 3] = src[j]; } } memset(src, 0, sizeof(gsm_signal) * 160); } } plugin_data->count = count; *(plugin_data->latency) = 160 * resamp; }
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 runAddingBodeShifterCV(LADSPA_Handle instance, unsigned long sample_count) { BodeShifterCV *plugin_data = (BodeShifterCV *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Base shift (float value) */ const LADSPA_Data shift_b = *(plugin_data->shift_b); /* Mix (-1=down, +1=up) (float value) */ const LADSPA_Data mix = *(plugin_data->mix); /* Input (array of floats of length sample_count) */ const LADSPA_Data * const input = plugin_data->input; /* CV Attenuation (float value) */ const LADSPA_Data atten = *(plugin_data->atten); /* Shift CV (array of floats of length sample_count) */ const LADSPA_Data * const shift = plugin_data->shift; /* Down out (array of floats of length sample_count) */ LADSPA_Data * const dout = plugin_data->dout; /* Up out (array of floats of length sample_count) */ LADSPA_Data * const uout = plugin_data->uout; /* Mix out (array of floats of length sample_count) */ LADSPA_Data * const mixout = plugin_data->mixout; LADSPA_Data * delay = plugin_data->delay; unsigned int dptr = plugin_data->dptr; float fs = plugin_data->fs; float phi = plugin_data->phi; float * sint = plugin_data->sint; #line 73 "bode_shifter_cv_1432.xml" unsigned long pos; unsigned int i; float hilb, rm1, rm2; int int_p; float frac_p; const float freq_fix = (float)SIN_T_SIZE * 1000.0f * f_clamp(atten, 0.0f, 10.0f) / fs; const float base_ofs = (float)SIN_T_SIZE * f_clamp(shift_b, 0.0f, 10000.0f) / fs; const float mixc = mix * 0.5f + 0.5f; for (pos = 0; pos < sample_count; pos++) { delay[dptr] = input[pos]; /* Perform the Hilbert FIR convolution * (probably FFT would be faster) */ hilb = 0.0f; for (i = 0; i < NZEROS/2; i++) { hilb += (xcoeffs[i] * delay[(dptr - i*2) & (D_SIZE - 1)]); } /* Calcuate the table positions for the sine modulator */ int_p = f_round(floor(phi)); /* Calculate ringmod1, the transformed input modulated with a shift Hz * sinewave. This creates a +180 degree sideband at source-shift Hz and * a 0 degree sindeband at source+shift Hz */ frac_p = phi - int_p; rm1 = hilb * 0.63661978f * cube_interp(frac_p, sint[int_p], sint[int_p+1], sint[int_p+2], sint[int_p+3]); /* Calcuate the table positions for the cosine modulator */ int_p = (int_p + SIN_T_SIZE / 4) & (SIN_T_SIZE - 1); /* Calculate ringmod2, the delayed input modulated with a shift Hz * cosinewave. This creates a 0 degree sideband at source+shift Hz * and a -180 degree sindeband at source-shift Hz */ rm2 = delay[(dptr - 99) & (D_SIZE - 1)] * cube_interp(frac_p, sint[int_p], sint[int_p+1], sint[int_p+2], sint[int_p+3]); /* Output the sum and differences of the ringmods. The +/-180 degree * sidebands cancel (more of less) and just leave the shifted * components */ buffer_write(dout[pos], (rm2 - rm1) * 0.5f); buffer_write(uout[pos], (rm2 + rm1) * 0.5f); buffer_write(mixout[pos], (dout[pos] - uout[pos]) * mixc + uout[pos]); dptr = (dptr + 1) & (D_SIZE - 1); phi += f_clamp(shift[pos], 0.0f, 10.0f) * freq_fix + base_ofs; while (phi > SIN_T_SIZE) { phi -= SIN_T_SIZE; } } plugin_data->dptr = dptr; plugin_data->phi = phi; *(plugin_data->latency) = 99; }
static void runAddingSc3(LADSPA_Handle instance, unsigned long sample_count) { Sc3 *plugin_data = (Sc3 *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* 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); /* Chain balance (float value) */ const LADSPA_Data chain_bal = *(plugin_data->chain_bal); /* Sidechain (array of floats of length sample_count) */ const LADSPA_Data * const sidechain = plugin_data->sidechain; /* 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 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 = 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 chain_bali = 1.0f - chain_bal; 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 = chain_bali * (left_in[pos] + right_in[pos]) * 0.5f + chain_bal * sidechain[pos]; sum += lev_in * lev_in; if (amp > env) { env = env * ga + amp * (1.0f - ga); } else { env = env * gr + amp * (1.0f - gr); } if (count++ % 4 == 3) { amp = rms_env_process(rms, sum * 0.25f); sum = 0.0f; if (isnan(env)) { // This can happen sometimes, but I dont know why env = 0.0f; } else 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->count = count; }
static void runAddingSifter(LADSPA_Handle instance, unsigned long sample_count) { Sifter *plugin_data = (Sifter *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Sift size (float value) */ const LADSPA_Data size = *(plugin_data->size); /* 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 * b1 = plugin_data->b1; long b1ptr = plugin_data->b1ptr; LADSPA_Data * b2 = plugin_data->b2; long b2ptr = plugin_data->b2ptr; LADSPA_Data * ob = plugin_data->ob; LADSPA_Data * rc = plugin_data->rc; #line 99 "sifter_1210.xml" unsigned long pos, i; long bsize = f_round(LIMIT(size, 1, MAX_BSIZE)); for (pos = 0; pos < sample_count; pos++) { if (b1ptr >= bsize) { float wstep = (float)MAX_BSIZE / (float)b1ptr, wpos = 0.0f; q_sort(b1, 0, b1ptr); for (i=0; i<b1ptr; i++) { ob[i] += b1[i] * rc[f_round(wpos)]; wpos += wstep; } b1ptr = 0; b2ptr = (bsize+1) / 2; } if (b2ptr >= bsize) { float wstep = (float)MAX_BSIZE / (float)b2ptr, wpos = 0.0f; int offset = (b2ptr+1)/2; q_sort(b2, 0, b2ptr); for (i=0; i<offset; i++) { ob[i + offset] += b2[i] * rc[f_round(wpos)]; wpos += wstep; } for (; i<b2ptr; i++) { ob[i - offset] += b2[i] * rc[f_round(wpos)]; wpos += wstep; } b2ptr = 0; } if (bsize < 2) { ob[b1ptr] = input[pos]; } b1[b1ptr] = input[pos]; b2[b2ptr] = input[pos]; buffer_write(output[pos], ob[b1ptr]); ob[b1ptr] = 0.0f; b1ptr++; b2ptr++; } plugin_data->b1ptr = b1ptr; plugin_data->b2ptr = b2ptr; }
static void runAddingBodeShifter(LADSPA_Handle instance, unsigned long sample_count) { BodeShifter *plugin_data = (BodeShifter *)instance; LADSPA_Data run_adding_gain = plugin_data->run_adding_gain; /* Frequency shift (float value) */ const LADSPA_Data shift = *(plugin_data->shift); /* Input (array of floats of length sample_count) */ const LADSPA_Data * const input = plugin_data->input; /* Down out (array of floats of length sample_count) */ LADSPA_Data * const dout = plugin_data->dout; /* Up out (array of floats of length sample_count) */ LADSPA_Data * const uout = plugin_data->uout; LADSPA_Data * delay = plugin_data->delay; unsigned int dptr = plugin_data->dptr; float fs = plugin_data->fs; float last_shift = plugin_data->last_shift; float phi = plugin_data->phi; float * sint = plugin_data->sint; #line 80 "bode_shifter_1431.xml" unsigned long pos; unsigned int i; float hilb, rm1, rm2; float shift_i = last_shift; int int_p; float frac_p; const float shift_c = f_clamp(shift, 0.0f, 10000.0f); const float shift_inc = (shift_c - last_shift) / (float)sample_count; const float freq_fix = (float)SIN_T_SIZE / fs; for (pos = 0; pos < sample_count; pos++) { delay[dptr] = input[pos]; /* Perform the Hilbert FIR convolution * (probably FFT would be faster) */ hilb = 0.0f; for (i = 0; i < NZEROS/2; i++) { hilb += (xcoeffs[i] * delay[(dptr - i*2) & (D_SIZE - 1)]); } /* Calcuate the table positions for the sine modulator */ int_p = f_round(floor(phi)); /* Calculate ringmod1, the transformed input modulated with a shift Hz * sinewave. This creates a +180 degree sideband at source-shift Hz and * a 0 degree sindeband at source+shift Hz */ frac_p = phi - int_p; /* the Hilbert has a gain of pi/2, which we have to correct for, thanks * Fons! */ rm1 = hilb * 0.63661978f * cube_interp(frac_p, sint[int_p], sint[int_p+1], sint[int_p+2], sint[int_p+3]); /* Calcuate the table positions for the cosine modulator */ int_p = (int_p + SIN_T_SIZE / 4) & (SIN_T_SIZE - 1); /* Calculate ringmod2, the delayed input modulated with a shift Hz * cosinewave. This creates a 0 degree sideband at source+shift Hz * and a -180 degree sindeband at source-shift Hz */ rm2 = delay[(dptr - 99) & (D_SIZE - 1)] * cube_interp(frac_p, sint[int_p], sint[int_p+1], sint[int_p+2], sint[int_p+3]); /* Output the sum and differences of the ringmods. The +/-180 degree * sidebands cancel (more of less) and just leave the shifted * components */ buffer_write(dout[pos], (rm2 - rm1) * 0.5f); buffer_write(uout[pos], (rm2 + rm1) * 0.5f); dptr = (dptr + 1) & (D_SIZE - 1); phi += shift_i * freq_fix; while (phi > SIN_T_SIZE) { phi -= SIN_T_SIZE; } shift_i += shift_inc; } plugin_data->dptr = dptr; plugin_data->phi = phi; plugin_data->last_shift = shift_c; *(plugin_data->latency) = 99; }
static void runSc2(LV2_Handle instance, uint32_t sample_count) { Sc2 *plugin_data = (Sc2 *)instance; const float attack = *(plugin_data->attack); const float release = *(plugin_data->release); const float threshold = *(plugin_data->threshold); const float ratio = *(plugin_data->ratio); const float knee = *(plugin_data->knee); const float makeup_gain = *(plugin_data->makeup_gain); const float * const sidechain = plugin_data->sidechain; const float * const input = plugin_data->input; float * const output = plugin_data->output; rms_env * rms = plugin_data->rms; float * as = plugin_data->as; float sum = plugin_data->sum; float amp = plugin_data->amp; float gain = plugin_data->gain; float gain_t = plugin_data->gain_t; float env = plugin_data->env; unsigned int count = plugin_data->count; unsigned long pos; const float ga = 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++) { sum += sidechain[pos] * sidechain[pos]; if (amp > env) { env = env * ga + amp * (1.0f - ga); } else { env = env * gr + amp * (1.0f - gr); } if (count++ % 4 == 3) { amp = rms_env_process(rms, sum * 0.25f); sum = 0.0f; 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->count = count; }
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; }