예제 #1
0
static void runAddingSvf(LADSPA_Handle instance, unsigned long sample_count) {
	Svf *plugin_data = (Svf *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_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;

	/* Filter type (0=none, 1=LP, 2=HP, 3=BP, 4=BR, 5=AP) (float value) */
	const LADSPA_Data filt_type = *(plugin_data->filt_type);

	/* Filter freq (float value) */
	const LADSPA_Data filt_freq = *(plugin_data->filt_freq);

	/* Filter Q (float value) */
	const LADSPA_Data filt_q = *(plugin_data->filt_q);

	/* Filter resonance (float value) */
	const LADSPA_Data filt_res = *(plugin_data->filt_res);
	int sample_rate = plugin_data->sample_rate;
	sv_filter * svf = plugin_data->svf;

#line 108 "svf_1214.xml"
	long int pos;
	
	setup_svf(svf, sample_rate, filt_freq, filt_q, f_round(filt_type));
	
	for (pos = 0; pos < sample_count; pos++) {
	        buffer_write(output[pos], run_svf(svf, input[pos] + (svf->b * filt_res)));
	}
}
예제 #2
0
파일: svf~.c 프로젝트: myQuil/amPd
static t_int *svf_perform(t_int *w)
{
	t_svf *obj = (t_svf *)(w[1]);
	t_float *in   = (t_float *)(w[2]);
	t_float *freq = (t_float *)(w[3]);
	t_float *q    = (t_float *)(w[4]);
	t_float *res  = (t_float *)(w[5]);
	t_float *out  = (t_float *)(w[6]);
	int n = (int)(w[7]);
	while (n--) {
		float f = *(in++);
		setup_svf(obj, *(freq++), *(q++));
		*(out++) = run_svf(obj, f + ((obj->b) * (*(res++))));
	}
	return (w+8);
}
예제 #3
0
파일: plugin.c 프로젝트: moddevices/swh-lv2
static void runHermesFilter(LV2_Handle instance, uint32_t sample_count)
{
  HermesFilter *plugin_data = (HermesFilter *)instance;

  const float lfo1_freq = *(plugin_data->lfo1_freq);
  const float lfo1_wave = *(plugin_data->lfo1_wave);
  const float lfo2_freq = *(plugin_data->lfo2_freq);
  const float lfo2_wave = *(plugin_data->lfo2_wave);
  const float osc1_freq = *(plugin_data->osc1_freq);
  const float osc1_wave = *(plugin_data->osc1_wave);
  const float osc2_freq = *(plugin_data->osc2_freq);
  const float osc2_wave = *(plugin_data->osc2_wave);
  const float rm1_depth = *(plugin_data->rm1_depth);
  const float rm2_depth = *(plugin_data->rm2_depth);
  const float rm3_depth = *(plugin_data->rm3_depth);
  const float osc1_gain_db = *(plugin_data->osc1_gain_db);
  const float rm1_gain_db = *(plugin_data->rm1_gain_db);
  const float osc2_gain_db = *(plugin_data->osc2_gain_db);
  const float rm2_gain_db = *(plugin_data->rm2_gain_db);
  const float in_gain_db = *(plugin_data->in_gain_db);
  const float rm3_gain_db = *(plugin_data->rm3_gain_db);
  const float xover_lfreqp = *(plugin_data->xover_lfreqp);
  const float xover_ufreqp = *(plugin_data->xover_ufreqp);
  const float drive1 = *(plugin_data->drive1);
  const float drive2 = *(plugin_data->drive2);
  const float drive3 = *(plugin_data->drive3);
  const float filt1_type = *(plugin_data->filt1_type);
  const float filt1_freq = *(plugin_data->filt1_freq);
  const float filt1_q = *(plugin_data->filt1_q);
  const float filt1_res = *(plugin_data->filt1_res);
  const float filt1_lfo1 = *(plugin_data->filt1_lfo1);
  const float filt1_lfo2 = *(plugin_data->filt1_lfo2);
  const float filt2_type = *(plugin_data->filt2_type);
  const float filt2_freq = *(plugin_data->filt2_freq);
  const float filt2_q = *(plugin_data->filt2_q);
  const float filt2_res = *(plugin_data->filt2_res);
  const float filt2_lfo1 = *(plugin_data->filt2_lfo1);
  const float filt2_lfo2 = *(plugin_data->filt2_lfo2);
  const float filt3_type = *(plugin_data->filt3_type);
  const float filt3_freq = *(plugin_data->filt3_freq);
  const float filt3_q = *(plugin_data->filt3_q);
  const float filt3_res = *(plugin_data->filt3_res);
  const float filt3_lfo1 = *(plugin_data->filt3_lfo1);
  const float filt3_lfo2 = *(plugin_data->filt3_lfo2);
  const float dela1_length = *(plugin_data->dela1_length);
  const float dela1_fb = *(plugin_data->dela1_fb);
  const float dela1_wet = *(plugin_data->dela1_wet);
  const float dela2_length = *(plugin_data->dela2_length);
  const float dela2_fb = *(plugin_data->dela2_fb);
  const float dela2_wet = *(plugin_data->dela2_wet);
  const float dela3_length = *(plugin_data->dela3_length);
  const float dela3_fb = *(plugin_data->dela3_fb);
  const float dela3_wet = *(plugin_data->dela3_wet);
  const float band1_gain_db = *(plugin_data->band1_gain_db);
  const float band2_gain_db = *(plugin_data->band2_gain_db);
  const float band3_gain_db = *(plugin_data->band3_gain_db);
  const float * const input = plugin_data->input;
  float * const output = plugin_data->output;
  blo_h_tables * tables = plugin_data->tables;
  blo_h_osc * osc1_d = plugin_data->osc1_d;
  blo_h_osc * osc2_d = plugin_data->osc2_d;
  blo_h_osc * lfo1_d = plugin_data->lfo1_d;
  blo_h_osc * lfo2_d = plugin_data->lfo2_d;
  float lfo1 = plugin_data->lfo1;
  float lfo2 = plugin_data->lfo2;
  float lfo1_phase = plugin_data->lfo1_phase;
  float lfo2_phase = plugin_data->lfo2_phase;
  sv_filter ** filt_data = plugin_data->filt_data;
  sv_filter * xover_b1_data = plugin_data->xover_b1_data;
  sv_filter * xover_b2_data = plugin_data->xover_b2_data;
  float ** dela_data = plugin_data->dela_data;
  int * dela_pos = plugin_data->dela_pos;
  long count = plugin_data->count;
  
unsigned long pos;
int i;

// dB gains converted to coefficients
float osc1_gain, rm1_gain, osc2_gain, rm2_gain, in_gain, rm3_gain;

// Output values for the oscilators etc.
float osc1, osc2, in, rm1, rm2, rm3, mixer1;

// Outputs from xover
float xover[3], band_gain[3];

// Output values for disortions
float dist[3];

// Stuff for distortions
float drive[3];

// Stuff for filters
float filt[3];
float filt_freq[3];
float filt_res[3];
float filt_lfo1[3];
float filt_lfo2[3];
int filt_t[3];

// Values for delays
float dela[3], dela_wet[3], dela_fb[3];
int dela_offset[3];

// Output of mixer2
float mixer2;

// X overs
const float xover_ufreq = f_clamp(xover_ufreqp, 200.0f, (float)(sample_rate / 6));
const float xover_lfreq = f_clamp(xover_lfreqp, 0.0f, xover_ufreq);
setup_f_svf(xover_b1_data, sample_rate, xover_ufreq);
setup_f_svf(xover_b2_data, sample_rate, xover_lfreq);

// Calculate delay offsets
dela_offset[0] = dela1_length * sample_rate;
dela_offset[1] = dela2_length * sample_rate;
dela_offset[2] = dela3_length * sample_rate;
for (i = 0; i < 3; i++) {
	if (dela_offset[i] > sample_rate * 2 || dela_offset[i] < 0) {
		dela_offset[i] = 0;
	}
	dela[i] = 0.0f;
	filt_t[i] = 0;
}

// Convert dB gains to coefficients
osc1_gain = DB_CO(osc1_gain_db);
osc2_gain = DB_CO(osc2_gain_db);
in_gain   = DB_CO(in_gain_db);
rm1_gain  = DB_CO(rm1_gain_db);
rm2_gain  = DB_CO(rm2_gain_db);
rm3_gain  = DB_CO(rm3_gain_db);
band_gain[0] = DB_CO(band1_gain_db);
band_gain[1] = DB_CO(band2_gain_db);
band_gain[2] = DB_CO(band3_gain_db);

osc1_d->wave = wave_tbl(osc1_wave);
osc2_d->wave = wave_tbl(osc2_wave);
lfo1_d->wave = wave_tbl(lfo1_wave);
lfo2_d->wave = wave_tbl(lfo2_wave);

blo_hd_set_freq(osc1_d, osc1_freq);
blo_hd_set_freq(osc2_d, osc2_freq);
blo_hd_set_freq(lfo1_d, lfo1_freq * 16);
blo_hd_set_freq(lfo2_d, lfo2_freq * 16);

#define SETUP_F(n,f,q,t) setup_svf(filt_data[n], sample_rate, f, q, (int)t)

// Set filter stuff
SETUP_F(0, filt1_freq, filt1_q, filt1_type);
SETUP_F(1, filt2_freq, filt2_q, filt2_type);
SETUP_F(2, filt3_freq, filt3_q, filt3_type);

filt_freq[0] = filt1_freq;
filt_freq[1] = filt2_freq;
filt_freq[2] = filt3_freq;
filt_res[0] = filt1_res;
filt_res[1] = filt2_res;
filt_res[2] = filt3_res;
filt_lfo1[0] = filt1_lfo1;
filt_lfo1[1] = filt2_lfo1;
filt_lfo1[2] = filt3_lfo1;
filt_lfo2[0] = filt1_lfo2;
filt_lfo2[1] = filt2_lfo2;
filt_lfo2[2] = filt3_lfo2;

// Setup distortions
drive[0] = drive1;
drive[1] = drive2;
drive[2] = drive3;

// Setup delays
dela_wet[0] = dela1_wet;
dela_wet[1] = dela2_wet;
dela_wet[2] = dela3_wet;
dela_fb[0] = dela1_fb;
dela_fb[1] = dela2_fb;
dela_fb[2] = dela3_fb;

tables = tables; // To shut up gcc

for (pos = 0; pos < sample_count; pos++) {
	count++; // Count of number of samples processed

	// Calculate oscilator values for this sample

	if (osc1_d->wave == NOISE) {
		osc1 = rand() * (0.5f/(float)RAND_MAX) - 1.0f;
	} else {
		osc1 = blo_hd_run_lin(osc1_d);
	}
	if (osc2_d->wave == NOISE) {
		osc2 = rand() * (0.5f/(float)RAND_MAX) - 1.0f;
	} else {
		osc2 = blo_hd_run_lin(osc2_d);
	}

	// Calculate LFO values every 16 samples
	if ((count & 15) == 1) {
		// Calculate lfo values
		if (lfo1_d->wave == NOISE) {
			lfo1_phase += lfo1_freq;
			if (lfo1_phase >= sample_rate) {
				lfo1_phase -= sample_rate;
				lfo1 = rand() * (0.5f/(float)RAND_MAX) - 1.0f;
			}
		} else {
			lfo1 = blo_hd_run_lin(lfo1_d);
		}
		if (lfo2_d->wave == NOISE) {
			lfo2_phase += lfo1_freq;
			if (lfo2_phase >= sample_rate) {
				lfo2_phase -= sample_rate;
				lfo2 = rand() * (0.5f/(float)RAND_MAX) - 1.0f;
			}
		} else {
			lfo2 = blo_hd_run_lin(lfo2_d);
		}
	}

	in = input[pos];
	rm1 = RINGMOD(osc2, osc1, rm1_depth);
	rm2 = RINGMOD(in, osc2, rm2_depth);
	rm3 = RINGMOD(osc1, in, rm3_depth);

	mixer1 = (osc1 * osc1_gain) + (osc2 * osc2_gain) + (in * in_gain) +
	         (rm1 * rm1_gain) + (rm2 * rm2_gain) + (rm3 * rm3_gain);

	mixer1 = soft_clip(mixer1);

	// Higpass off the top band
	xover[0] = run_svf(xover_b1_data, mixer1);
	// Lowpass off the bottom band
	xover[2] = run_svf(xover_b2_data, mixer1);
	// The middle band is whats left
	xover[1] = mixer1 - xover[0] - xover[2];

	mixer2 = 0.0f;
	for (i = 0; i < 3; i++) {
		dist[i] = xover[i]*(fabs(xover[i]) + drive1)/(xover[i]*xover[i] + (drive[i]-1)*fabs(xover[i]) + 1.0f);

		if (filt_t[i] == 0) {
			filt[i] = dist[i];
		} else {
			if (count % 16 == 1) {
				setup_f_svf(filt_data[i], sample_rate, filt_freq[i]+LFO(filt_lfo1[i], filt_lfo2[i]));
			}
			filt[i] = run_svf(filt_data[i], dist[i] + (filt_res[i] * (filt_data[i])->b));
		}

		dela[i] = (dela_data[i][dela_pos[i]] * dela_wet[i]) + filt[i];
		dela_data[i][(dela_pos[i] + dela_offset[i]) %
		 (2 * sample_rate)] = filt[i] + (dela[i] * dela_fb[i]);
		dela_pos[i] = (dela_pos[i] + 1) % (2 * sample_rate);

		mixer2 += band_gain[i] * dela[i];
	}

	buffer_write(output[pos], soft_clip(mixer2));
}

plugin_data->count = count;
plugin_data->lfo1 = lfo1;
plugin_data->lfo2 = lfo2;
plugin_data->lfo1_phase = lfo1_phase;
plugin_data->lfo2_phase = lfo2_phase;
		
}