示例#1
0
static t_int *freqshift_tilde_perform(t_int *w)
{
	t_freqshift_tilde *x = (t_freqshift_tilde *)(w[1]);
    t_float *in = (t_float *)(w[2]);
    t_float *out1 = (t_float *)(w[3]);
	t_float *out2 = (t_float *)(w[4]);
    int n = (int)(w[5]);
	float f, hilb, rm1, rm2, frac_p;
	float shift_i = x->x_last_shift;
	float sample_count = sys_getblksize();
	unsigned int i;
	int int_p;
	const float shift_c = f_clamp(x->x_shift, 0.0f, 10000.0f);
	const float shift_inc = (shift_c - x->x_last_shift) / (float)sample_count;
	const float freq_fix = (float)SIN_T_SIZE / x->x_fs;
    while (n--)
    {
		f = *in++;
		x->x_delay[x->x_dptr] = f;
		/* Perform the Hilbert FIR convolution
		 * (probably FFT would be faster) */
		hilb = 0.0f;
	    for (i = 0; i <= NZEROS/2; i++) {
	        hilb += (xcoeffs[i] * x->x_delay[(x->x_dptr - i*2) & (D_SIZE - 1)]);
		}

	    /* Calcuate the table positions for the sine modulator */
	    int_p = f_round(floor(x->x_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 = x->x_phi - int_p;
	    rm1 = hilb * cube_interp(frac_p, x->x_sint[int_p], x->x_sint[int_p+1],
	                             x->x_sint[int_p+2], x->x_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 = x->x_delay[(x->x_dptr - 100) & (D_SIZE - 1)] * cube_interp(frac_p,
	          x->x_sint[int_p], x->x_sint[int_p+1], x->x_sint[int_p+2], x->x_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 */
	    *out1++ = (rm2 - rm1) * 0.5f; /*downshifting*/
	    *out2++ = (rm2 + rm1) * 0.5f; /*upshifting*/

		x->x_dptr = (x->x_dptr + 1) & (D_SIZE - 1);
	    x->x_phi += shift_i * freq_fix;
	    while (x->x_phi > SIN_T_SIZE) {
			x->x_phi -= SIN_T_SIZE;
		}
		shift_i += shift_inc;
	}	
    return (w+6);
}
示例#2
0
static void runAddingModDelay(LADSPA_Handle instance, unsigned long sample_count) {
	ModDelay *plugin_data = (ModDelay *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

	/* Base delay (s) (float value) */
	const LADSPA_Data base = *(plugin_data->base);

	/* Delay (s) (array of floats of length sample_count) */
	const LADSPA_Data * const delay = plugin_data->delay;

	/* 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;
	float fs = plugin_data->fs;
	unsigned int write_ptr = plugin_data->write_ptr;

#line 42 "mod_delay_1419.xml"
	unsigned long pos;

	for (pos = 0; pos < sample_count; pos++) {
	  float tmp;
	  const float rpf = modff((base + delay[pos]) * fs, &tmp);
	  const int rp = write_ptr - 4 - f_round(tmp);

	  buffer[write_ptr++] = input[pos];
	  write_ptr &= buffer_mask;

	  buffer_write(output[pos], cube_interp(rpf, buffer[(rp - 1) & buffer_mask], buffer[rp & buffer_mask],  buffer[(rp + 1) & buffer_mask], buffer[(rp + 2) & buffer_mask]));
	}
	plugin_data->write_ptr = write_ptr;
}
示例#3
0
static inline float f_lin2db_cube(float lin)
      {
      float scale = (lin - LIN_MIN) * (float)DB_TABLE_SIZE / (LIN_MAX - LIN_MIN);
      int base = f_round(scale - 0.5f);
      float ofs = scale - base;

      if (base < 2) {
            return db_data[2] * scale * 0.5f - 23 * (2.0f - scale);
      } else if (base > DB_TABLE_SIZE - 3) {
            return db_data[DB_TABLE_SIZE - 2];
      }
      return cube_interp(ofs, db_data[base-1], db_data[base], db_data[base+1], db_data[base+2]);
      }
示例#4
0
static inline float f_db2lin_cube(float db)
      {
      float scale = (db - DB_MIN) * (float)LIN_TABLE_SIZE / (DB_MAX - DB_MIN);
      int base = f_round(scale - 0.5f);
      float ofs = scale - base;

      if (base < 1) {
            return 0.0f;
      } else if (base > LIN_TABLE_SIZE - 3) {
            return lin_data[LIN_TABLE_SIZE - 2];
      }
      return cube_interp(ofs, lin_data[base-1], lin_data[base], lin_data[base+1], lin_data[base+2]);
      }
示例#5
0
static void runAddingCombSplitter(LADSPA_Handle instance, unsigned long sample_count) {
	CombSplitter *plugin_data = (CombSplitter *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

	/* Band separation (Hz) (float value) */
	const LADSPA_Data freq = *(plugin_data->freq);

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

	/* Output 1 (array of floats of length sample_count) */
	LADSPA_Data * const out1 = plugin_data->out1;

	/* Output 2 (array of floats of length sample_count) */
	LADSPA_Data * const out2 = plugin_data->out2;
	long comb_pos = plugin_data->comb_pos;
	LADSPA_Data * comb_tbl = plugin_data->comb_tbl;
	float last_offset = plugin_data->last_offset;
	long sample_rate = plugin_data->sample_rate;

	float offset;
	int data_pos;
	unsigned long pos;
	float xf, xf_step, d_pos, fr, interp, in;

	offset = sample_rate / freq;
	offset = f_clamp(offset, 0, COMB_SIZE - 1);
	xf_step = 1.0f / (float)sample_count;
	xf = 0.0f;

	for (pos = 0; pos < sample_count; pos++) {
	        xf += xf_step;
	        d_pos = comb_pos - LIN_INTERP(xf, last_offset, offset);
	        data_pos = f_trunc(d_pos);
	        fr = d_pos - data_pos;
	        interp =  cube_interp(fr, comb_tbl[(data_pos - 1) & COMB_MASK], comb_tbl[data_pos & COMB_MASK], comb_tbl[(data_pos + 1) & COMB_MASK], comb_tbl[(data_pos + 2) & COMB_MASK]);
	        in = input[pos];
	        comb_tbl[comb_pos] = in;
	        buffer_write(out1[pos], (in + interp) * 0.5f);
	        buffer_write(out2[pos], (in - interp) * 0.5f);
	        comb_pos = (comb_pos + 1) & COMB_MASK;
	}

	plugin_data->comb_pos = comb_pos;
	plugin_data->last_offset = offset;
}
示例#6
0
文件: comb_1190.c 项目: Cubiicle/lmms
static void runComb(LADSPA_Handle instance, unsigned long sample_count) {
	Comb *plugin_data = (Comb *)instance;

	/* Band separation (Hz) (float value) */
	const LADSPA_Data freq = *(plugin_data->freq);

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

	/* 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 comb_pos = plugin_data->comb_pos;
	LADSPA_Data * comb_tbl = plugin_data->comb_tbl;
	float last_offset = plugin_data->last_offset;
	long sample_rate = plugin_data->sample_rate;

#line 41 "comb_1190.xml"
	float offset;
	int data_pos;
	unsigned long pos;
	float xf, xf_step, d_pos, fr, interp;

	offset = sample_rate / freq;
	offset = f_clamp(offset, 0, COMB_SIZE - 1);
	xf_step = 1.0f / (float)sample_count;
	xf = 0.0f;

	for (pos = 0; pos < sample_count; pos++) {
	        xf += xf_step;
	        d_pos = comb_pos - LIN_INTERP(xf, last_offset, offset);
	        data_pos = f_trunc(d_pos);
	        fr = d_pos - data_pos;
	        interp =  cube_interp(fr, comb_tbl[(data_pos - 1) & COMB_MASK], comb_tbl[data_pos & COMB_MASK], comb_tbl[(data_pos + 1) & COMB_MASK], comb_tbl[(data_pos + 2) & COMB_MASK]);
	        comb_tbl[comb_pos] = input[pos] + fb * interp;
	        buffer_write(output[pos], (input[pos] + interp) * 0.5f);
	        comb_pos = (comb_pos + 1) & COMB_MASK;
	}

	plugin_data->comb_pos = comb_pos;
	plugin_data->last_offset = offset;
}
static void runAddingSmoothDecimate(LADSPA_Handle instance, unsigned long sample_count) {
	SmoothDecimate *plugin_data = (SmoothDecimate *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

	/* Resample rate (float value) */
	const LADSPA_Data rate = *(plugin_data->rate);

	/* Smoothing (float value) */
	const LADSPA_Data smooth = *(plugin_data->smooth);

	/* 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 accum = plugin_data->accum;
	float * buffer = plugin_data->buffer;
	int buffer_pos = plugin_data->buffer_pos;
	float fs = plugin_data->fs;

#line 31 "smooth_decimate_1414.xml"
	unsigned long pos;
	float smoothed;
	float inc = (rate / fs);
	inc = f_clamp(inc, 0.0f, 1.0f);

	for (pos = 0; pos < sample_count; pos++) {
	  accum += inc;
	  if (accum >= 1.0f) {
	    accum -= 1.0f;
	    buffer_pos = (buffer_pos + 1) & 7;
	    buffer[buffer_pos] = input[pos];
	  }
	  smoothed = cube_interp(accum, buffer[(buffer_pos - 3) & 7],
	                                buffer[(buffer_pos - 2) & 7],
	                                buffer[(buffer_pos - 1) & 7],
	                                buffer[buffer_pos]);
	  buffer_write(output[pos], LIN_INTERP(smooth, buffer[(buffer_pos - 3) & 7], smoothed));
	}

	plugin_data->accum = accum;
	plugin_data->buffer_pos = buffer_pos;
}
示例#8
0
static void runAddingRateShifter(LADSPA_Handle instance, unsigned long sample_count) {
	RateShifter *plugin_data = (RateShifter *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

	/* Rate (float value) */
	const LADSPA_Data rate = *(plugin_data->rate);

	/* 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;
	fixp32 read_ptr = plugin_data->read_ptr;
	unsigned int write_ptr = plugin_data->write_ptr;

#line 47 "rate_shifter_1417.xml"
	unsigned long pos;
	fixp32 read_inc;

	read_inc.all = (long long)(rate * 4294967296.0f);

	for (pos = 0; pos < sample_count; pos++) {
	  const unsigned int rp = read_ptr.part.in;

	  /* Do write pointer stuff */
	  buffer[write_ptr] = input[pos];
	  write_ptr = (write_ptr + 1) & buffer_mask;

	  /* And now read pointer */
	  buffer_write(output[pos], cube_interp((float)read_ptr.part.fr / 4294967296.0f, buffer[(rp - 1) & buffer_mask], buffer[rp],  buffer[(rp + 1) & buffer_mask], buffer[(rp + 2) & buffer_mask]));
	  read_ptr.all += read_inc.all;
	  read_ptr.part.in &= buffer_mask;
	}

	plugin_data->read_ptr.all = read_ptr.all;
	plugin_data->write_ptr = write_ptr;
}
示例#9
0
文件: Delay.cpp 项目: ventosus/ingen
void
DelayNode::run(ProcessContext& context)
{
	Buffer* const delay_buf = _delay_port->buffer(0).get();
	Buffer* const in_buf    = _in_port->buffer(0).get();
	Buffer* const out_buf   = _out_port->buffer(0).get();

	DelayNode* plugin_data = this;

	const float* const in            = in_buf->samples();
	float* const       out           = out_buf->samples();
	const float        delay_time    = delay_buf->samples()[0];
	const uint32_t     buffer_mask   = plugin_data->_buffer_mask;
	const SampleRate   sample_rate   = context.engine().driver()->sample_rate();
	float              delay_samples = plugin_data->_delay_samples;
	int64_t            write_phase   = plugin_data->_write_phase;
	const uint32_t     sample_count  = context.nframes();

	if (write_phase == 0) {
		_last_delay_time = delay_time;
		_delay_samples   = delay_samples = CALC_DELAY(delay_time);
	}

	if (delay_time == _last_delay_time) {
		const int64_t idelay_samples = (int64_t)delay_samples;
		const float   frac           = delay_samples - idelay_samples;

		for (uint32_t i = 0; i < sample_count; i++) {
			int64_t read_phase = write_phase - (int64_t)delay_samples;
			const float read = cube_interp(frac,
			                               buffer_at(read_phase - 1),
			                               buffer_at(read_phase),
			                               buffer_at(read_phase + 1),
			                               buffer_at(read_phase + 2));
			buffer_at(write_phase++) = in[i];
			out[i] = read;
		}
	} else {
		const float next_delay_samples  = CALC_DELAY(delay_time);
		const float delay_samples_slope = (next_delay_samples - delay_samples) / sample_count;

		for (uint32_t i = 0; i < sample_count; i++) {
			delay_samples += delay_samples_slope;
			write_phase++;
			const int64_t read_phase     = write_phase - (int64_t)delay_samples;
			const int64_t idelay_samples = (int64_t)delay_samples;
			const float   frac           = delay_samples - idelay_samples;
			const float   read           = cube_interp(frac,
			                                           buffer_at(read_phase - 1),
			                                           buffer_at(read_phase),
			                                           buffer_at(read_phase + 1),
			                                           buffer_at(read_phase + 2));
			buffer_at(write_phase) = in[i];
			out[i] = read;
		}

		_last_delay_time = delay_time;
		_delay_samples   = delay_samples;
	}

	_write_phase = write_phase;
}
示例#10
0
static void runComb_c(LADSPA_Handle instance, unsigned long sample_count) {
	Comb_c *plugin_data = (Comb_c *)instance;

	/* 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;

	/* Max Delay (s) (float value) */
	const LADSPA_Data max_delay = *(plugin_data->max_delay);

	/* Delay Time (s) (float value) */
	const LADSPA_Data delay_time = *(plugin_data->delay_time);

	/* Decay Time (s) (float value) */
	const LADSPA_Data decay_time = *(plugin_data->decay_time);
	LADSPA_Data * buffer = plugin_data->buffer;
	unsigned int buffer_mask = plugin_data->buffer_mask;
	LADSPA_Data delay_samples = plugin_data->delay_samples;
	LADSPA_Data feedback = plugin_data->feedback;
	LADSPA_Data last_decay_time = plugin_data->last_decay_time;
	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 79 "comb_1887.xml"
	int i;

	i = max_delay;

	if (write_phase == 0) {
	  plugin_data->last_delay_time = delay_time;
	  plugin_data->last_decay_time = decay_time;
	  plugin_data->delay_samples = delay_samples = CALC_DELAY (delay_time);
	  plugin_data->feedback = feedback = calc_feedback (delay_time, decay_time);
	}
	
	if (delay_time == last_delay_time && decay_time == last_decay_time) {
	  long idelay_samples = (long)delay_samples;
	  LADSPA_Data frac = delay_samples - idelay_samples;

	  for (i=0; i<sample_count; i++) {
	    long read_phase = write_phase - (long)delay_samples;
	    LADSPA_Data read = cube_interp (frac,
	                                    buffer[(read_phase-1) & buffer_mask], 
	                                    buffer[read_phase & buffer_mask], 
	                                    buffer[(read_phase+1) & buffer_mask], 
	                                    buffer[(read_phase+2) & buffer_mask]);

	    buffer[write_phase++ & buffer_mask] = read * feedback + in[i];
	    buffer_write(out[i], read);
	  }
	} else {
	  float next_delay_samples = CALC_DELAY (delay_time);
	  float delay_samples_slope = (next_delay_samples - delay_samples) / sample_count;
	  float next_feedback = calc_feedback (delay_time, decay_time);
	  float feedback_slope = (next_feedback - feedback) / sample_count;

	  for (i=0; i<sample_count; i++) {
	    long read_phase, idelay_samples;
	    LADSPA_Data read, frac;

	    delay_samples += delay_samples_slope;
	    write_phase++;
	    read_phase = write_phase - (long)delay_samples;
	    idelay_samples = (long)delay_samples;
	    frac = delay_samples - idelay_samples;
	    read = cube_interp (frac,
	                        buffer[(read_phase-1) & buffer_mask], 
	                        buffer[read_phase & buffer_mask], 
	                        buffer[(read_phase+1) & buffer_mask], 
	                        buffer[(read_phase+2) & buffer_mask]);

	    buffer[write_phase & buffer_mask] = read * feedback + in[i];
	    buffer_write(out[i], read);

	    feedback += feedback_slope;
	  }

	  plugin_data->last_delay_time = delay_time;
	  plugin_data->last_decay_time = decay_time;
	  plugin_data->feedback = feedback;
	  plugin_data->delay_samples = delay_samples;
	}
	
	plugin_data->write_phase = write_phase;
}
示例#11
0
文件: Delay.cpp 项目: pgiblock/ingen
void
DelayNode::process(ProcessContext& context)
{
	AudioBuffer* const delay_buf = (AudioBuffer*)_delay_port->buffer(0).get();
	AudioBuffer* const in_buf    = (AudioBuffer*)_in_port->buffer(0).get();
	AudioBuffer* const out_buf   = (AudioBuffer*)_out_port->buffer(0).get();

	NodeImpl::pre_process(context);

	DelayNode* plugin_data = this;

	const float* const in            = in_buf->data();
	float* const       out           = out_buf->data();
	const float        delay_time    = delay_buf->data()[0];
	const uint32_t     buffer_mask   = plugin_data->_buffer_mask;
	const unsigned int sample_rate   = plugin_data->_srate;
	float              delay_samples = plugin_data->_delay_samples;
	long               write_phase   = plugin_data->_write_phase;
	const uint32_t     sample_count  = context.nframes();

	if (write_phase == 0) {
		_last_delay_time = delay_time;
		_delay_samples   = delay_samples = CALC_DELAY(delay_time);
	}

	if (delay_time == _last_delay_time) {
		const long  idelay_samples = (long)delay_samples;
		const float frac           = delay_samples - idelay_samples;

		for (uint32_t i = 0; i < sample_count; i++) {
			long read_phase = write_phase - (long)delay_samples;
			const float read = cube_interp(frac,
					buffer_at(read_phase - 1),
					buffer_at(read_phase),
					buffer_at(read_phase + 1),
					buffer_at(read_phase + 2));
			buffer_at(write_phase++) = in[i];
			out[i] = read;
		}
	} else {
		const float next_delay_samples  = CALC_DELAY(delay_time);
		const float delay_samples_slope = (next_delay_samples - delay_samples) / sample_count;

		for (uint32_t i = 0; i < sample_count; i++) {
			delay_samples += delay_samples_slope;
			write_phase++;
			const long  read_phase     = write_phase - (long)delay_samples;
			const long  idelay_samples = (long)delay_samples;
			const float frac           = delay_samples - idelay_samples;
			const float read           = cube_interp(frac,
					buffer_at(read_phase - 1),
					buffer_at(read_phase),
					buffer_at(read_phase + 1),
					buffer_at(read_phase + 2));
			buffer_at(write_phase) = in[i];
			out[i] = read;
		}

		_last_delay_time = delay_time;
		_delay_samples   = delay_samples;
	}

	_write_phase = write_phase;

	NodeImpl::post_process(context);
}
示例#12
0
static void runAddingAmPitchshift(LADSPA_Handle instance, unsigned long sample_count) {
	AmPitchshift *plugin_data = (AmPitchshift *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

	/* 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;

	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;
}
示例#13
0
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;
}
示例#14
0
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;

	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;
}
示例#15
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;
}
示例#16
0
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;
}
示例#17
0
static void runAddingDelay_c(LADSPA_Handle instance, unsigned long sample_count) {
	Delay_c *plugin_data = (Delay_c *)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);
	LADSPA_Data * buffer = plugin_data->buffer;
	unsigned int buffer_mask = plugin_data->buffer_mask;
	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;

	unsigned int i;

	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;
	  LADSPA_Data frac = delay_samples - idelay_samples;

	  for (i=0; i<sample_count; i++) {
	    long read_phase = write_phase - (long)delay_samples;
	    LADSPA_Data read = cube_interp (frac,
	                                    buffer[(read_phase-1) & buffer_mask], 
	                                    buffer[read_phase & buffer_mask], 
	                                    buffer[(read_phase+1) & buffer_mask], 
	                                    buffer[(read_phase+2) & buffer_mask]);
	    buffer[write_phase++ & buffer_mask] = in[i];
	    buffer_write(out[i], read);
	  }
	} 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 frac, read;

	    delay_samples += delay_samples_slope;
	    write_phase++;
	    read_phase = write_phase - (long)delay_samples;
	    idelay_samples = (long)delay_samples;
	    frac = delay_samples - idelay_samples;
	    read = cube_interp (frac,
	                        buffer[(read_phase-1) & buffer_mask], 
	                        buffer[read_phase & buffer_mask], 
	                        buffer[(read_phase+1) & buffer_mask], 
	                        buffer[(read_phase+2) & buffer_mask]);
	    buffer[write_phase & buffer_mask] = in[i];
	    buffer_write(out[i], read);
	  }

	  plugin_data->last_delay_time = delay_time;
	  plugin_data->delay_samples = delay_samples;
	}
	
	plugin_data->write_phase = write_phase;
}
示例#18
0
文件: gsm_1215.c 项目: BaraMGB/lmms
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;

#line 61 "gsm_1215.xml"
	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;
}