Exemple #1
0
inline float run_svf(sv_filter *sv, float in) {
	float out;
	int i;

	in = sv->qnrm * in ;
	for (i=0; i < F_R; i++) {
		// only needed for pentium chips
		in  = flush_to_zero(in);
		sv->l = flush_to_zero(sv->l);
		// very slight waveshape for extra stability
		sv->b = sv->b - sv->b * sv->b * sv->b * 0.001f;

		// regular state variable code here
		// the notch and peaking outputs are optional
		sv->h = in - sv->l - sv->q * sv->b;
		sv->b = sv->b + sv->f * sv->h;
		sv->l = sv->l + sv->f * sv->b;
		sv->n = sv->l + sv->h;
		sv->p = sv->l - sv->h;

		out = *(sv->op);
		in = out;
	}

	return out;
}
Exemple #2
0
static inline float diffuser_do(GVerb *unit, g_diffuser *p, float x){
    float y,w;
    w = x - p->buf[p->idx] * p->coef;
    w = flush_to_zero(w);
    y = p->buf[p->idx] + w * p->coef;
    p->buf[p->idx] = zapgremlins(w);
    p->idx = (p->idx + 1) % p->size;
    return(y);
    }
Exemple #3
0
static void runFreqTracker(LV2_Handle instance, uint32_t sample_count)
{
  FreqTracker *plugin_data = (FreqTracker *)instance;

  const float speed = *(plugin_data->speed);
  const float * const input = plugin_data->input;
  float * const freq = plugin_data->freq;
  float fs = plugin_data->fs;
  int cross_time = plugin_data->cross_time;
  float last_amp = plugin_data->last_amp;
  float f = plugin_data->f;
  float fo = plugin_data->fo;
  
      unsigned long pos;
      float xm1 = last_amp;
      const float damp_lp = (1.0f - speed) * 0.9f;
      const float damp_lpi = 1.0f - damp_lp;

      for (pos = 0; pos < sample_count; pos++) {
	if (input[pos] < 0.0f && xm1 > 0.0f) {
	  if (cross_time > 3.0f) {
	    f = fs / ((float)cross_time * 2.0f);
	  }
	  cross_time = 0;
	}
	xm1 = input[pos];
	cross_time++;
	fo = fo * damp_lp + f * damp_lpi;
	fo = flush_to_zero(fo);
	buffer_write(freq[pos], fo);
      }

      plugin_data->last_amp = xm1;
      plugin_data->fo = fo;
      plugin_data->f = f;
      plugin_data->cross_time = cross_time;
    
}
static void runAddingLcrDelay(LADSPA_Handle instance, unsigned long sample_count) {
	LcrDelay *plugin_data = (LcrDelay *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

	/* L delay (ms) (float value) */
	const LADSPA_Data ldel = *(plugin_data->ldel);

	/* L level (float value) */
	const LADSPA_Data llev = *(plugin_data->llev);

	/* C delay (ms) (float value) */
	const LADSPA_Data cdel = *(plugin_data->cdel);

	/* C level (float value) */
	const LADSPA_Data clev = *(plugin_data->clev);

	/* R delay (ms) (float value) */
	const LADSPA_Data rdel = *(plugin_data->rdel);

	/* R level (float value) */
	const LADSPA_Data rlev = *(plugin_data->rlev);

	/* Feedback (float value) */
	const LADSPA_Data feedback = *(plugin_data->feedback);

	/* High damp (%) (float value) */
	const LADSPA_Data high_d = *(plugin_data->high_d);

	/* Low damp (%) (float value) */
	const LADSPA_Data low_d = *(plugin_data->low_d);

	/* Spread (float value) */
	const LADSPA_Data spread = *(plugin_data->spread);

	/* Dry/Wet level (float value) */
	const LADSPA_Data wet = *(plugin_data->wet);

	/* L input (array of floats of length sample_count) */
	const LADSPA_Data * const in_l = plugin_data->in_l;

	/* R input (array of floats of length sample_count) */
	const LADSPA_Data * const in_r = plugin_data->in_r;

	/* L output (array of floats of length sample_count) */
	LADSPA_Data * const out_l = plugin_data->out_l;

	/* R output (array of floats of length sample_count) */
	LADSPA_Data * const out_r = plugin_data->out_r;
	LADSPA_Data * buffer = plugin_data->buffer;
	unsigned int buffer_mask = plugin_data->buffer_mask;
	unsigned int buffer_pos = plugin_data->buffer_pos;
	biquad * filters = plugin_data->filters;
	float fs = plugin_data->fs;
	float last_cd = plugin_data->last_cd;
	float last_cl = plugin_data->last_cl;
	float last_ld = plugin_data->last_ld;
	float last_ll = plugin_data->last_ll;
	float last_rd = plugin_data->last_rd;
	float last_rl = plugin_data->last_rl;

#line 58 "lcr_delay_1436.xml"
	unsigned long pos;
	const float sc_r = 1.0f / (float)sample_count;
	const float spr_t = 0.5f + spread * 0.01f;
	const float spr_o = 0.5f - spread * 0.01f;
	float fb = feedback * 0.01f;
	float ll, cl, rl, ld, cd, rd;
	float ll_d, cl_d, rl_d, ld_d, cd_d, rd_d;
	float left, right;
	float fbs; /* Feedback signal */

	if (fb < -0.99f) {
	  fb = -0.99f;
	} else if (fb > 0.99f) {
	  fb = 0.99f;
	}

	ls_set_params(filters, fs * 0.0001f * powf(2.0f, low_d * 0.12f),
	              -0.5f * low_d, 0.5f, fs);
	hs_set_params(filters + 1, fs * (0.41f - 0.0001f *
	              powf(2.0f, high_d * 0.12f)), -70.0f, 0.9f, fs);

	ll = last_ll;                                /* Start value of Left Level */
	ll_d = (llev * 0.01f - last_ll) * sc_r;         /* Delta for Left Level */
	cl = last_cl;
	cl_d = (clev * 0.01f - last_cl) * sc_r;
	rl = last_rl;
	rl_d = (rlev * 0.01f - last_rl) * sc_r;

	ld = last_ld;
	ld_d = (ldel * fs * 0.001f - last_ld) * sc_r;
	cd = last_cd;
	cd_d = (cdel * fs * 0.001f - last_cd) * sc_r;
	rd = last_rd;
	rd_d = (rdel * fs * 0.001f - last_rd) * sc_r;

	for (pos = 0; pos < sample_count; pos++) {
	  /* Increment linear interpolators */
	  ll += ll_d;
	  rl += rl_d;
	  cl += cl_d;
	  ld += ld_d;
	  rd += rd_d;
	  cd += cd_d;

	  /* Write input into delay line */
	  buffer[buffer_pos] = in_l[pos] + in_r[pos];
	  /* Add feedback, must be done afterwards for case where C delay = 0 */
	  fbs = buffer[(buffer_pos - f_round(cd)) & buffer_mask] * fb;
	  fbs = flush_to_zero(fbs);
	  fbs = biquad_run(filters, fbs);
	  fbs = biquad_run(filters + 1, fbs);
	  buffer[buffer_pos] += fbs;

	  /* Outputs from left and right delay beffers + centre mix */
	  left  = buffer[(buffer_pos - f_round(ld)) & buffer_mask] * ll +
	          buffer[(buffer_pos - f_round(cd)) & buffer_mask] * cl;
	  right = buffer[(buffer_pos - f_round(rd)) & buffer_mask] * rl +
	          buffer[(buffer_pos - f_round(cd)) & buffer_mask] * cl;

	  /* Left and right channel outs */
	  buffer_write(out_l[pos], in_l[pos] * (1.0f - wet) +
	                  (left * spr_t + right * spr_o) * wet);
	  buffer_write(out_r[pos], in_r[pos] * (1.0f - wet) +
	                  (left * spr_o + right * spr_t) * wet);

	  buffer_pos = (buffer_pos + 1) & buffer_mask;
	}

	plugin_data->last_ll = ll;
	plugin_data->last_cl = cl;
	plugin_data->last_rl = rl;
	plugin_data->last_ld = ld;
	plugin_data->last_cd = cd;
	plugin_data->last_rd = rd;
	plugin_data->buffer_pos = buffer_pos;
}
Exemple #5
0
static void runAddingRevdelay(LADSPA_Handle instance, unsigned long sample_count) {
	Revdelay *plugin_data = (Revdelay *)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);

	/* Dry Level (dB) (float value) */
	const LADSPA_Data dry_level = *(plugin_data->dry_level);

	/* Wet Level (dB) (float value) */
	const LADSPA_Data wet_level = *(plugin_data->wet_level);

	/* Feedback (float value) */
	const LADSPA_Data feedback = *(plugin_data->feedback);

	/* Crossfade samples (float value) */
	const LADSPA_Data xfade_samp = *(plugin_data->xfade_samp);
	LADSPA_Data * buffer = plugin_data->buffer;
	unsigned int buffer_size = plugin_data->buffer_size;
	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;

#line 55 "revdelay_1605.xml"
	int i;
	unsigned long delay2;
	float dry = DB_CO(dry_level);
	float wet = DB_CO(wet_level);
	float fadescale;
	unsigned long xfadesamp = xfade_samp;

	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;
	  delay2 = idelay_samples * 2;

	  if (xfadesamp > idelay_samples) {
	      /* force it to half */
	      xfadesamp = idelay_samples / 2;
	  }

	  for (i=0; i<sample_count; i++) {
	    long read_phase = delay2 - write_phase;
	    LADSPA_Data read;
	    LADSPA_Data insamp;

	    insamp = in[i];
	    read =  (wet * buffer[read_phase]) + (dry * insamp);

	    if ( (write_phase % idelay_samples) < xfadesamp) {
	      fadescale = (write_phase % idelay_samples) / (1.0 * xfadesamp);
	    }
	    else if ((write_phase % idelay_samples) > (idelay_samples - xfadesamp)) {
	      fadescale = (idelay_samples - (write_phase % idelay_samples)) / (1.0 * xfadesamp);
	    }
	    else {
	      fadescale = 1.0;
	    }

	    buffer[write_phase] = fadescale * (insamp + (feedback * read)); 
	    buffer[write_phase] = flush_to_zero(buffer[write_phase]);
	            
	    buffer_write(out[i], read);
	    write_phase = (write_phase + 1) % delay2;
	  }
	} 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 read;
	    LADSPA_Data insamp;
	    insamp = in[i];

	    delay_samples += delay_samples_slope;
	    delay2 = (long) (delay_samples * 2);
	    write_phase = (write_phase + 1) % delay2;

	    read_phase = delay2 - write_phase;
	    idelay_samples = (long)delay_samples;
	    read = wet * buffer[read_phase]   + (dry * insamp);

	    if ((write_phase % idelay_samples) < xfade_samp) {
	      fadescale = (write_phase % idelay_samples) / (1.0 * xfade_samp);
	    }
	    else if ((write_phase % idelay_samples) > (idelay_samples - xfade_samp)) {
	      fadescale = (idelay_samples - (write_phase % idelay_samples)) / (1.0 * xfade_samp);
	    }
	    else {
	      fadescale = 1.0;
	    }

	    buffer[write_phase] = fadescale * (insamp + (feedback * read)); 
	    buffer[write_phase] = flush_to_zero(buffer[write_phase]);

	    buffer_write(out[i], read);
	  }

	  plugin_data->last_delay_time = delay_time;
	  plugin_data->delay_samples = delay_samples;
	}
	
	plugin_data->write_phase = write_phase;
}
Exemple #6
0
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;
}