示例#1
0
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++;
	}
示例#2
0
void 
run_adding_DeEsser(LADSPA_Handle Instance,
		   unsigned long SampleCount) {
  
	DeEsser * ptr = (DeEsser *)Instance;

	LADSPA_Data * input = ptr->input;
	LADSPA_Data * output = ptr->output;
	LADSPA_Data threshold = LIMIT(*(ptr->threshold),-50.0f,10.0f);
	LADSPA_Data freq = LIMIT(*(ptr->freq),2000.0f,16000.0f);
	LADSPA_Data sidechain = LIMIT(*(ptr->sidechain),0.0f,1.0f);
	LADSPA_Data monitor = LIMIT(*(ptr->monitor),0.0f,1.0f);
	unsigned long sample_index;

	LADSPA_Data in = 0;
	LADSPA_Data out = 0;
	LADSPA_Data sidech = 0;
	LADSPA_Data ampl_db = 0.0f;
	LADSPA_Data attn = 0.0f;
	LADSPA_Data max_attn = 0.0f;


	if (ptr->old_freq != freq) {
		lp_set_params(&ptr->sidech_lo_filter, freq, SIDECH_BW, ptr->sample_rate);
		hp_set_params(&ptr->sidech_hi_filter, freq, SIDECH_BW, ptr->sample_rate);
		ptr->old_freq = freq;
	}

	for (sample_index = 0; sample_index < SampleCount; sample_index++) {

		in = *(input++);

		/* process sidechain filters */
		sidech = biquad_run(&ptr->sidech_hi_filter, in);
		if (sidechain > 0.1f)
			sidech = biquad_run(&ptr->sidech_lo_filter, sidech);

		ampl_db = 20.0f * log10f(sidech);
		if (ampl_db <= threshold)
			attn = 0.0f;
		else
			attn = -0.5f * (ampl_db - threshold);

		ptr->sum += attn;
		ptr->sum -= push_buffer(attn, ptr->ringbuffer, ptr->buflen, &ptr->pos);

		if (-1.0f * ptr->sum > max_attn)
			max_attn = -0.01f * ptr->sum;

		in *= db2lin(ptr->sum / 100.0f);


		/* output selector */
		if (monitor > 0.1f)
			out = sidech;
		else
			out = in;

		*(output++) += ptr->run_adding_gain * out;
		*(ptr->attenuat) = LIMIT(max_attn,0,10);
	}
}
示例#3
0
void
run_ChorusFlanger(LV2_Handle Instance,
		  uint32_t SampleCount) {

	ChorusFlanger * ptr = (ChorusFlanger *)Instance;

	float freq = LIMIT(*(ptr->freq), 0.0f, MAX_FREQ);

	float calcphase = (*(ptr->phase)+ptr->smoothphase)*0.5;
	ptr->smoothphase=calcphase;
	float phase = LIMIT(calcphase, 0.0f, 180.0f) / 180.0f;

	float calcdepth = (*(ptr->depth)+ptr->smoothdepth)*0.5;
	ptr->smoothdepth=calcdepth;
	float depth = 100.0f * ptr->sample_rate / 44100.0f
		* LIMIT(calcdepth,0.0f,100.0f) / 100.0f;

	float calcdelay = (*(ptr->delay)+ptr->smoothdelay)*0.5;
	ptr->smoothdelay=calcdelay;
	float delay = LIMIT(calcdelay,0.0f,100.0f);
	float contour = LIMIT(*(ptr->contour), 20.0f, 20000.0f);

	float calcdry = (*(ptr->drylevel)+ptr->smoothdry)*0.5;
	ptr->smoothdry=calcdry;
	float drylevel = db2lin(LIMIT(calcdry,-90.0f,20.0f));

	float calcwet = (*(ptr->wetlevel)+ptr->smoothwet)*0.5;
	ptr->smoothwet=calcwet;
	float wetlevel = db2lin(LIMIT(calcwet,-90.0f,20.0f));
	float * input_L = ptr->input_L;
	float * input_R = ptr->input_R;
	float * output_L = ptr->output_L;
	float * output_R = ptr->output_R;

	unsigned long sample_index;
	unsigned long sample_count = SampleCount;

	float in_L = 0.0f;
	float in_R = 0.0f;
	float d_L = 0.0f;
	float d_R = 0.0f;
	float f_L = 0.0f;
	float f_R = 0.0f;
	float out_L = 0.0f;
	float out_R = 0.0f;

	float phase_L = 0.0f;
	float phase_R = 0.0f;
	float fpos_L = 0.0f;
	float fpos_R = 0.0f;
	float n_L = 0.0f;
	float n_R = 0.0f;
	float rem_L = 0.0f;
	float rem_R = 0.0f;
	float s_a_L, s_a_R, s_b_L, s_b_R;

	float d_pos = 0.0f;

	if (delay < 1.0f)
		delay = 1.0f;
	delay = 100.0f - delay;

	hp_set_params(&ptr->highpass_L, contour, HP_BW, ptr->sample_rate);
	hp_set_params(&ptr->highpass_R, contour, HP_BW, ptr->sample_rate);

	for (sample_index = 0; sample_index < sample_count; sample_index++) {

		in_L = *(input_L++);
		in_R = *(input_R++);

		push_buffer(in_L, ptr->ring_L, ptr->buflen_L, &(ptr->pos_L));
		push_buffer(in_R, ptr->ring_R, ptr->buflen_R, &(ptr->pos_R));

		ptr->cm_phase += freq / ptr->sample_rate * COS_TABLE_SIZE;

		while (ptr->cm_phase >= COS_TABLE_SIZE)
			ptr->cm_phase -= COS_TABLE_SIZE;

		ptr->dm_phase = phase * COS_TABLE_SIZE / 2.0f;

		phase_L = ptr->cm_phase;
		phase_R = ptr->cm_phase + ptr->dm_phase;
		while (phase_R >= COS_TABLE_SIZE)
			phase_R -= COS_TABLE_SIZE;

		d_pos = delay * ptr->sample_rate / 1000.0f;
		fpos_L = d_pos + depth * (0.5f + 0.5f * cos_table[(unsigned long)phase_L]);
		fpos_R = d_pos + depth * (0.5f + 0.5f * cos_table[(unsigned long)phase_R]);

		n_L = floorf(fpos_L);
		n_R = floorf(fpos_R);
		rem_L = fpos_L - n_L;
		rem_R = fpos_R - n_R;

		s_a_L = read_buffer(ptr->ring_L, ptr->buflen_L,
				    ptr->pos_L, (unsigned long) n_L);
		s_b_L = read_buffer(ptr->ring_L, ptr->buflen_L,
				    ptr->pos_L, (unsigned long) n_L + 1);

		s_a_R = read_buffer(ptr->ring_R, ptr->buflen_R,
				    ptr->pos_R, (unsigned long) n_R);
		s_b_R = read_buffer(ptr->ring_R, ptr->buflen_R,
				    ptr->pos_R, (unsigned long) n_R + 1);

		d_L = ((1 - rem_L) * s_a_L + rem_L * s_b_L);
		d_R = ((1 - rem_R) * s_a_R + rem_R * s_b_R);

		f_L = biquad_run(&ptr->highpass_L, d_L);
		f_R = biquad_run(&ptr->highpass_R, d_R);

		out_L = drylevel * in_L + wetlevel * f_L;
		out_R = drylevel * in_R + wetlevel * f_R;

		*(output_L++) = out_L;
		*(output_R++) = out_R;
	}
}
示例#4
0
void 
run_adding_ChorusFlanger(LADSPA_Handle Instance,
                         unsigned long SampleCount) {
  
	ChorusFlanger * ptr = (ChorusFlanger *)Instance;

	LADSPA_Data freq = LIMIT(*(ptr->freq), 0.0f, MAX_FREQ);
	LADSPA_Data phase = LIMIT(*(ptr->phase), 0.0f, 180.0f) / 180.0f;
	LADSPA_Data depth = 100.0f * ptr->sample_rate / 44100.0f
		* LIMIT(*(ptr->depth),0.0f,100.0f) / 100.0f;
	LADSPA_Data delay = LIMIT(*(ptr->delay),0.0f,100.0f);
	LADSPA_Data contour = LIMIT(*(ptr->contour), 20.0f, 20000.0f);
	LADSPA_Data drylevel = db2lin(LIMIT(*(ptr->drylevel),-90.0f,20.0f));
	LADSPA_Data wetlevel = db2lin(LIMIT(*(ptr->wetlevel),-90.0f,20.0f));
	LADSPA_Data * input_L = ptr->input_L;
	LADSPA_Data * input_R = ptr->input_R;
	LADSPA_Data * output_L = ptr->output_L;
	LADSPA_Data * output_R = ptr->output_R;

	unsigned long sample_index;
	unsigned long sample_count = SampleCount;

	LADSPA_Data in_L = 0.0f;
	LADSPA_Data in_R = 0.0f;
	LADSPA_Data d_L = 0.0f;
	LADSPA_Data d_R = 0.0f;
	LADSPA_Data f_L = 0.0f;
	LADSPA_Data f_R = 0.0f;
	LADSPA_Data out_L = 0.0f;
	LADSPA_Data out_R = 0.0f;

	float phase_L = 0.0f;
	float phase_R = 0.0f;
	float fpos_L = 0.0f;
	float fpos_R = 0.0f;
	float n_L = 0.0f;
	float n_R = 0.0f;
	float rem_L = 0.0f;
	float rem_R = 0.0f;
	float s_a_L, s_a_R, s_b_L, s_b_R;

	float d_pos = 0.0f;

	if (delay < 1.0f)
		delay = 1.0f;
	delay = 100.0f - delay;

	hp_set_params(&ptr->highpass_L, contour, HP_BW, ptr->sample_rate);
	hp_set_params(&ptr->highpass_R, contour, HP_BW, ptr->sample_rate);

	for (sample_index = 0; sample_index < sample_count; sample_index++) {

		in_L = *(input_L++);
		in_R = *(input_R++);

		push_buffer(in_L, ptr->ring_L, ptr->buflen_L, &(ptr->pos_L));
		push_buffer(in_R, ptr->ring_R, ptr->buflen_R, &(ptr->pos_R));
		
		ptr->cm_phase += freq / ptr->sample_rate * COS_TABLE_SIZE;
		
		while (ptr->cm_phase >= COS_TABLE_SIZE)
			ptr->cm_phase -= COS_TABLE_SIZE;
		
		ptr->dm_phase = phase * COS_TABLE_SIZE / 2.0f;
		
		phase_L = ptr->cm_phase;
		phase_R = ptr->cm_phase + ptr->dm_phase;
		while (phase_R >= COS_TABLE_SIZE)
			phase_R -= COS_TABLE_SIZE;
		
		d_pos = delay * ptr->sample_rate / 1000.0f;
		fpos_L = d_pos + depth * (0.5f + 0.5f * cos_table[(unsigned long)phase_L]);
		fpos_R = d_pos + depth * (0.5f + 0.5f * cos_table[(unsigned long)phase_R]);
		
		n_L = floorf(fpos_L);
		n_R = floorf(fpos_R);
		rem_L = fpos_L - n_L;
		rem_R = fpos_R - n_R;
		
		s_a_L = read_buffer(ptr->ring_L, ptr->buflen_L,
				    ptr->pos_L, (unsigned long) n_L);
		s_b_L = read_buffer(ptr->ring_L, ptr->buflen_L,
				    ptr->pos_L, (unsigned long) n_L + 1);
		
		s_a_R = read_buffer(ptr->ring_R, ptr->buflen_R,
				    ptr->pos_R, (unsigned long) n_R);
		s_b_R = read_buffer(ptr->ring_R, ptr->buflen_R,
				    ptr->pos_R, (unsigned long) n_R + 1);
		
		d_L = ((1 - rem_L) * s_a_L + rem_L * s_b_L);
		d_R = ((1 - rem_R) * s_a_R + rem_R * s_b_R);

		f_L = biquad_run(&ptr->highpass_L, d_L);
		f_R = biquad_run(&ptr->highpass_R, d_R);

		out_L = drylevel * in_L + wetlevel * f_L;
		out_R = drylevel * in_R + wetlevel * f_R;

		*(output_L++) += ptr->run_adding_gain * out_L;
		*(output_R++) += ptr->run_adding_gain * out_R;
	}
}
示例#5
0
/* load plugin data from reverb_data[] into an instance */
void
load_plugin_data(LADSPA_Handle Instance) {

	Reverb * ptr = (Reverb *)Instance;
	unsigned long m;
	unsigned int i;


	m = LIMIT(*(ptr->mode),0,NUM_MODES-1);

	/* load combs data */
	ptr->num_combs = 2 * reverb_data[m].num_combs;
	for (i = 0; i < reverb_data[m].num_combs; i++) {
		((COMB_FILTER *)(ptr->combs + 2*i))->buflen = 
			reverb_data[m].combs[i].delay * ptr->sample_rate;
		((COMB_FILTER *)(ptr->combs + 2*i))->feedback = 
			reverb_data[m].combs[i].feedback;
		((COMB_FILTER *)(ptr->combs + 2*i))->freq_resp =
			LIMIT(reverb_data[m].combs[i].freq_resp
			      * powf(ptr->sample_rate / 44100.0f, 0.8f),
			      0.0f, 1.0f);

		((COMB_FILTER *)(ptr->combs + 2*i+1))->buflen =
			((COMB_FILTER *)(ptr->combs + 2*i))->buflen;
		((COMB_FILTER *)(ptr->combs + 2*i+1))->feedback = 
			((COMB_FILTER *)(ptr->combs + 2*i))->feedback;
		((COMB_FILTER *)(ptr->combs + 2*i+1))->feedback = 
			((COMB_FILTER *)(ptr->combs + 2*i))->freq_resp;

		/* set initial values: */
		*(((COMB_FILTER *)(ptr->combs + 2*i))->buffer_pos) = 0;
		*(((COMB_FILTER *)(ptr->combs + 2*i+1))->buffer_pos) = 0;
		((COMB_FILTER *)(ptr->combs + 2*i))->last_out = 0;
		((COMB_FILTER *)(ptr->combs + 2*i+1))->last_out = 0;

		lp_set_params(((COMB_FILTER *)(ptr->combs + 2*i))->filter,
			      2000.0f + 13000.0f * (1 - reverb_data[m].combs[i].freq_resp)
			      * ptr->sample_rate / 44100.0f,
			      BANDPASS_BWIDTH, ptr->sample_rate);
		lp_set_params(((COMB_FILTER *)(ptr->combs + 2*i+1))->filter,
			      2000.0f + 13000.0f * (1 - reverb_data[m].combs[i].freq_resp)
			      * ptr->sample_rate / 44100.0f,
			      BANDPASS_BWIDTH, ptr->sample_rate);
	}

	/* load allps data */
	ptr->num_allps = 2 * reverb_data[m].num_allps;
	for (i = 0; i < reverb_data[m].num_allps; i++) {
		((ALLP_FILTER *)(ptr->allps + 2*i))->buflen = 
			reverb_data[m].allps[i].delay * ptr->sample_rate;
		((ALLP_FILTER *)(ptr->allps + 2*i))->feedback = 
			reverb_data[m].allps[i].feedback;

		((ALLP_FILTER *)(ptr->allps + 2*i+1))->buflen = 
			((ALLP_FILTER *)(ptr->allps + 2*i))->buflen;
		((ALLP_FILTER *)(ptr->allps + 2*i+1))->feedback = 
			((ALLP_FILTER *)(ptr->allps + 2*i))->feedback;

		/* set initial values: */
		*(((ALLP_FILTER *)(ptr->allps + 2*i))->buffer_pos) = 0;
		*(((ALLP_FILTER *)(ptr->allps + 2*i+1))->buffer_pos) = 0;
		((ALLP_FILTER *)(ptr->allps + 2*i))->last_out = 0;
		((ALLP_FILTER *)(ptr->allps + 2*i+1))->last_out = 0;
	}

	/* init bandpass filters */
	lp_set_params((biquad *)(ptr->low_pass), reverb_data[m].bandpass_high,
		      BANDPASS_BWIDTH, ptr->sample_rate);
	hp_set_params((biquad *)(ptr->high_pass), reverb_data[m].bandpass_low,
		      BANDPASS_BWIDTH, ptr->sample_rate);
	lp_set_params((biquad *)(ptr->low_pass + 1), reverb_data[m].bandpass_high,
		      BANDPASS_BWIDTH, ptr->sample_rate);
	hp_set_params((biquad *)(ptr->high_pass + 1), reverb_data[m].bandpass_low,
		      BANDPASS_BWIDTH, ptr->sample_rate);
}