Exemplo n.º 1
0
static void runGate(LADSPA_Handle instance, unsigned long sample_count) {
	Gate *plugin_data = (Gate *)instance;

	/* 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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
static
void
run_adding_eq(LADSPA_Handle instance, unsigned long sample_count) {

	eq * ptr = (eq *)instance;

	const LADSPA_Data ch0f = LIMIT(*(ptr->ch0f),40.0f,280.0f);
	const LADSPA_Data ch0g = LIMIT(*(ptr->ch0g),-50.0f,20.0f);
	const LADSPA_Data ch0b = LIMIT(*(ptr->ch0b),0.1f,5.0f);
	const LADSPA_Data ch1f = LIMIT(*(ptr->ch1f),100.0f,500.0f);
	const LADSPA_Data ch1g = LIMIT(*(ptr->ch1g),-50.0f,20.0f);
	const LADSPA_Data ch1b = LIMIT(*(ptr->ch1b),0.1f,5.0f);
	const LADSPA_Data ch2f = LIMIT(*(ptr->ch2f),200.0f,1000.0f);
	const LADSPA_Data ch2g = LIMIT(*(ptr->ch2g),-50.0f,20.0f);
	const LADSPA_Data ch2b = LIMIT(*(ptr->ch2b),0.1f,5.0f);
	const LADSPA_Data ch3f = LIMIT(*(ptr->ch3f),400.0f,2800.0f);
	const LADSPA_Data ch3g = LIMIT(*(ptr->ch3g),-50.0f,20.0f);
	const LADSPA_Data ch3b = LIMIT(*(ptr->ch3b),0.1f,5.0f);
	const LADSPA_Data ch4f = LIMIT(*(ptr->ch4f),1000.0f,5000.0f);
	const LADSPA_Data ch4g = LIMIT(*(ptr->ch4g),-50.0f,20.0f);
	const LADSPA_Data ch4b = LIMIT(*(ptr->ch4b),0.1f,5.0f);
	const LADSPA_Data ch5f = LIMIT(*(ptr->ch5f),3000.0f,9000.0f);
	const LADSPA_Data ch5g = LIMIT(*(ptr->ch5g),-50.0f,20.0f);
	const LADSPA_Data ch5b = LIMIT(*(ptr->ch5b),0.1f,5.0f);
	const LADSPA_Data ch6f = LIMIT(*(ptr->ch6f),6000.0f,18000.0f);
	const LADSPA_Data ch6g = LIMIT(*(ptr->ch6g),-50.0f,20.0f);
	const LADSPA_Data ch6b = LIMIT(*(ptr->ch6b),0.1f,5.0f);
	const LADSPA_Data ch7f = LIMIT(*(ptr->ch7f),10000.0f,20000.0f);
	const LADSPA_Data ch7g = LIMIT(*(ptr->ch7g),-50.0f,20.0f);
	const LADSPA_Data ch7b = LIMIT(*(ptr->ch7b),0.1f,5.0f);

	const LADSPA_Data * input = ptr->input;
	LADSPA_Data * output = ptr->output;

	biquad * filters = ptr->filters;
	float fs = ptr->fs;

	unsigned long pos;
	float samp;


	if ((ch0f != ptr->old_ch0f) ||
	    (ch0g != ptr->old_ch0g) ||
	    (ch0b != ptr->old_ch0b)) {
		ptr->old_ch0f = ch0f;
		ptr->old_ch0g = ch0g;
		ptr->old_ch0b = ch0b;
		eq_set_params(&filters[0], ch0f, ch0g, ch0b, fs);
	}
	if ((ch1f != ptr->old_ch1f) ||
	    (ch1g != ptr->old_ch1g) ||
	    (ch1b != ptr->old_ch1b)) {
		ptr->old_ch1f = ch1f;
		ptr->old_ch1g = ch1g;
		ptr->old_ch1b = ch1b;
		eq_set_params(&filters[1], ch1f, ch1g, ch1b, fs);
	}
	if ((ch2f != ptr->old_ch2f) ||
	    (ch2g != ptr->old_ch2g) ||
	    (ch2b != ptr->old_ch2b)) {
		ptr->old_ch2f = ch2f;
		ptr->old_ch2g = ch2g;
		ptr->old_ch2b = ch2b;
		eq_set_params(&filters[2], ch2f, ch2g, ch2b, fs);
	}
	if ((ch3f != ptr->old_ch3f) ||
	    (ch3g != ptr->old_ch3g) ||
	    (ch3b != ptr->old_ch3b)) {
		ptr->old_ch3f = ch3f;
		ptr->old_ch3g = ch3g;
		ptr->old_ch3b = ch3b;
		eq_set_params(&filters[3], ch3f, ch3g, ch3b, fs);
	}
	if ((ch4f != ptr->old_ch4f) ||
	    (ch4g != ptr->old_ch4g) ||
	    (ch4b != ptr->old_ch4b)) {
		ptr->old_ch4f = ch4f;
		ptr->old_ch4g = ch4g;
		ptr->old_ch4b = ch4b;
		eq_set_params(&filters[4], ch4f, ch4g, ch4b, fs);
	}
	if ((ch5f != ptr->old_ch5f) ||
	    (ch5g != ptr->old_ch5g) ||
	    (ch5b != ptr->old_ch5b)) {
		ptr->old_ch5f = ch5f;
		ptr->old_ch5g = ch5g;
		ptr->old_ch5b = ch5b;
		eq_set_params(&filters[5], ch5f, ch5g, ch5b, fs);
	}
	if ((ch6f != ptr->old_ch6f) ||
	    (ch6g != ptr->old_ch6g) ||
	    (ch6b != ptr->old_ch6b)) {
		ptr->old_ch6f = ch6f;
		ptr->old_ch6g = ch6g;
		ptr->old_ch6b = ch6b;
		eq_set_params(&filters[6], ch6f, ch6g, ch6b, fs);
	}
	if ((ch7f != ptr->old_ch7f) ||
	    (ch7g != ptr->old_ch7g) ||
	    (ch7b != ptr->old_ch7b)) {
		ptr->old_ch7f = ch7f;
		ptr->old_ch7g = ch7g;
		ptr->old_ch7b = ch7b;
		eq_set_params(&filters[7], ch7f, ch7g, ch7b, fs);
	}

	for (pos = 0; pos < sample_count; pos++) {
		samp = input[pos];
		if (ch0g != 0.0f)
			samp = biquad_run(&filters[0], samp);
		if (ch1g != 0.0f)
			samp = biquad_run(&filters[1], samp);
		if (ch2g != 0.0f)
			samp = biquad_run(&filters[2], samp);
		if (ch3g != 0.0f)
			samp = biquad_run(&filters[3], samp);
		if (ch4g != 0.0f)
			samp = biquad_run(&filters[4], samp);
		if (ch5g != 0.0f)
			samp = biquad_run(&filters[5], samp);
		if (ch6g != 0.0f)
			samp = biquad_run(&filters[6], samp);
		if (ch7g != 0.0f)
			samp = biquad_run(&filters[7], samp);
		output[pos] += ptr->run_adding_gain * samp;
	}
}
Exemplo n.º 4
0
static void runVynil(LV2_Handle instance, uint32_t sample_count)
{
  Vynil *plugin_data = (Vynil *)instance;

  const float year = *(plugin_data->year);
  const float rpm = *(plugin_data->rpm);
  const float warp = *(plugin_data->warp);
  const float click = *(plugin_data->click);
  const float wear = *(plugin_data->wear);
  const float * const in_l = plugin_data->in_l;
  const float * const in_r = plugin_data->in_r;
  float * const out_l = plugin_data->out_l;
  float * const out_r = plugin_data->out_r;
  float fs = plugin_data->fs;
  float * buffer_m = plugin_data->buffer_m;
  float * buffer_s = plugin_data->buffer_s;
  unsigned int buffer_mask = plugin_data->buffer_mask;
  unsigned int buffer_pos = plugin_data->buffer_pos;
  float * click_buffer = plugin_data->click_buffer;
  fixp16 click_buffer_pos = plugin_data->click_buffer_pos;
  fixp16 click_buffer_omega = plugin_data->click_buffer_omega;
  float click_gain = plugin_data->click_gain;
  float phi = plugin_data->phi;
  unsigned int sample_cnt = plugin_data->sample_cnt;
  float def = plugin_data->def;
  float def_target = plugin_data->def_target;
  biquad * lowp_m = plugin_data->lowp_m;
  biquad * lowp_s = plugin_data->lowp_s;
  biquad * noise_filt = plugin_data->noise_filt;
  biquad * highp = plugin_data->highp;
  
      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++;
      }