Exemplo n.º 1
0
static void runAddingValve(LADSPA_Handle instance, unsigned long sample_count) {
	Valve *plugin_data = (Valve *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

	/* Distortion level (float value) */
	const LADSPA_Data q_p = *(plugin_data->q_p);

	/* Distortion character (float value) */
	const LADSPA_Data dist_p = *(plugin_data->dist_p);

	/* 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 itm1 = plugin_data->itm1;
	LADSPA_Data otm1 = plugin_data->otm1;

#line 26 "valve_1209.xml"
	unsigned long pos;
	LADSPA_Data fx;
	
	const float q = q_p - 0.999f;
	const float dist = dist_p * 40.0f + 0.1f;
	
	if (q == 0.0f) {
	        for (pos = 0; pos < sample_count; pos++) {
	                if (input[pos] == q) {
	                        fx = 1.0f / dist;
	                } else {
	                        fx = input[pos] / (1.0f - f_exp(-dist * input[pos]));
	                }
	                otm1 = 0.999f * otm1 + fx - itm1;
	                round_to_zero(&otm1);
	                itm1 = fx;
	                buffer_write(output[pos], otm1);
	        }
	} else {
	        for (pos = 0; pos < sample_count; pos++) {
	                if (input[pos] == q) {
	                        fx = 1.0f / dist + q / (1.0f - f_exp(dist * q));
	                } else {
	                        fx = (input[pos] - q) /
	                         (1.0f - f_exp(-dist * (input[pos] - q))) +
	                         q / (1.0f - f_exp(dist * q));
	                }
	                otm1 = 0.999f * otm1 + fx - itm1;
	                round_to_zero(&otm1);
	                itm1 = fx;
	                buffer_write(output[pos], otm1);
	        }
	}
	
	plugin_data->itm1 = itm1;
	plugin_data->otm1 = otm1;
}
Exemplo n.º 2
0
void Compressor::process(int frames, float* ip, float *op)
      {
      const float ga       = _attack < 2.0f ? 0.0f : as[f_round(_attack * 0.001f * (float)(A_TBL-1))];
      const float gr       = as[f_round(_release * 0.001f * (float)(A_TBL-1))];
      const float rs       = (_ratio - 1.0f) / _ratio;
      const float mug      = db2lin(_makeupGain);
      const float knee_min = db2lin(_threshold - _knee);
      const float knee_max = db2lin(_threshold + _knee);
      const float ef_a     = ga * 0.25f;
      const float ef_ai    = 1.0f - ef_a;

      for (int pos = 0; pos < frames; pos++) {
            const float la = fabs(ip[pos * 2]);
            const float ra = fabs(ip[pos * 2 + 1]);
            const float lev_in = f_max(la, ra);

            sum += lev_in * lev_in;
            if (amp > env_rms)
                  env_rms = env_rms * ga + amp * (1.0f - ga);
            else
                  env_rms = env_rms * gr + amp * (1.0f - gr);
            round_to_zero(&env_rms);
            if (lev_in > env_peak)
                  env_peak = env_peak * ga + lev_in * (1.0f - ga);
            else
                  env_peak = env_peak * gr + lev_in * (1.0f - gr);
            round_to_zero(&env_peak);
            if ((count++ & 3) == 3) {
                  amp = rms.process(sum * 0.25f);
                  sum = 0.0f;
                  if (qIsNaN(env_rms))     // This can happen sometimes, but I don't know why
                        env_rms = 0.0f;
                  env = LIN_INTERP(rms_peak, env_rms, env_peak);
                  if (env <= knee_min)
                        gain_t = 1.0f;
                  else if (env < knee_max) {
                        const float x = -(_threshold - _knee - lin2db(env)) / _knee;
                        gain_t = db2lin(-_knee * rs * x * x * 0.25f);
                        }
                  else
                        gain_t = db2lin((_threshold - lin2db(env)) * rs);
                  }
            gain          = gain * ef_a + gain_t * ef_ai;
            op[pos * 2]   = ip[pos * 2] * gain * mug;
            op[pos * 2+1] = ip[pos * 2 + 1] * gain * mug;
            }

//      printf("gain %f\n", gain);

//      amplitude = lin2db(env);
//      gain_red  = lin2db(gain);
      }
static void runAddingFastLookaheadLimiter(LADSPA_Handle instance, unsigned long sample_count) {
	FastLookaheadLimiter *plugin_data = (FastLookaheadLimiter *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

	/* Input gain (dB) (float value) */
	const LADSPA_Data ingain = *(plugin_data->ingain);

	/* Limit (dB) (float value) */
	const LADSPA_Data limit = *(plugin_data->limit);

	/* Release time (s) (float value) */
	const LADSPA_Data release = *(plugin_data->release);

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

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

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

	/* Output 2 (array of floats of length sample_count) */
	LADSPA_Data * const out_2 = plugin_data->out_2;
	float atten = plugin_data->atten;
	float atten_lp = plugin_data->atten_lp;
	LADSPA_Data * buffer = plugin_data->buffer;
	unsigned int buffer_len = plugin_data->buffer_len;
	unsigned int buffer_pos = plugin_data->buffer_pos;
	unsigned int chunk_num = plugin_data->chunk_num;
	unsigned int chunk_pos = plugin_data->chunk_pos;
	unsigned int chunk_size = plugin_data->chunk_size;
	float * chunks = plugin_data->chunks;
	unsigned int delay = plugin_data->delay;
	float delta = plugin_data->delta;
	unsigned int fs = plugin_data->fs;
	float peak = plugin_data->peak;

#line 67 "fast_lookahead_limiter_1913.xml"
	unsigned long pos;
	const float max = DB_CO(limit);
	const float trim = DB_CO(ingain);
	float sig;
	unsigned int i;

	#ifdef DEBUG
	float clip = 0.0, clipp = 0.0;
	int clipc = 0;
	#endif

	for (pos = 0; pos < sample_count; pos++) {
	  if (chunk_pos++ == chunk_size) {
	    /* we've got a full chunk */
	   
	    delta = (1.0f - atten) / (fs * release);
	    round_to_zero(&delta);
	    for (i=0; i<10; i++) {
	      const int p = (chunk_num - 9 + i) & (NUM_CHUNKS - 1);
	      const float this_delta = (max / chunks[p] - atten) /
	                                ((float)(i+1) * fs * 0.0005f + 1.0f);

	      if (this_delta < delta) {
	        delta = this_delta;
	      }
	    }

	    chunks[chunk_num++ & (NUM_CHUNKS - 1)] = peak;
	    peak = 0.0f;
	    chunk_pos = 0;
	  }

	  buffer[(buffer_pos * 2) & (buffer_len - 1)] =     in_1[pos] * trim
	                                                  + 1.0e-30;
	  buffer[(buffer_pos * 2 + 1) & (buffer_len - 1)] = in_2[pos] * trim
	                                                  + 1.0e-30;

	  sig = fabs(in_1[pos]) > fabs(in_2[pos]) ? fabs(in_1[pos]) :
	          fabs(in_2[pos]);
	  sig += 1.0e-30;
	  if (sig * trim > peak) {
	    peak = sig * trim;
	  }
	  //round_to_zero(&peak);
	  //round_to_zero(&sig);

	  atten += delta;
	  atten_lp = atten * 0.1f + atten_lp * 0.9f;
	  //round_to_zero(&atten_lp);
	  if (delta > 0.0f && atten > 1.0f) {
	    atten = 1.0f;
	    delta = 0.0f;
	  }

	  buffer_write(out_1[pos], buffer[(buffer_pos * 2 - delay * 2) &
	                                  (buffer_len - 1)] * atten_lp);
	  buffer_write(out_2[pos], buffer[(buffer_pos * 2 - delay * 2 + 1) &
	                                  (buffer_len - 1)] * atten_lp);
	  round_to_zero(&out_1[pos]);
	  round_to_zero(&out_2[pos]);

	  if (out_1[pos] < -max) {
	    #ifdef DEBUG
	    clip += 20.0*log10(out_1[pos] / -max);
	    clipc++;
	    if (fabs(out_1[pos] - max) > clipp) {
	      clipp = fabs(out_1[pos] / -max);
	    }
	    #endif
	    buffer_write(out_1[pos], -max);
	  } else if (out_1[pos] > max) {
	    #ifdef DEBUG
	    clip += 20.0*log10(out_1[pos] / max);
	    clipc++;
	    if (fabs(out_1[pos] - max) > clipp) {
	      clipp = fabs(out_1[pos] / max);
	    }
	    #endif
	    buffer_write(out_1[pos], max);
	  }
	  if (out_2[pos] < -max) {
	    #ifdef DEBUG
	    clip += 20.0*log10(out_2[pos] / -max);
	    clipc++;
	    if (fabs(out_2[pos] - max) > clipp) {
	      clipp = fabs(out_2[pos] / -max);
	    }
	    #endif
	    buffer_write(out_2[pos], -max);
	  } else if (out_2[pos] > max) {
	    #ifdef DEBUG
	    clip += 20.0*log10(out_2[pos] / max);
	    clipc++;
	    if (fabs(out_2[pos] - max) > clipp) {
	      clipp = fabs(out_2[pos] / max);
	    }
	    #endif
	    buffer_write(out_2[pos], max);
	  }

	  buffer_pos++;
	}

	#ifdef DEBUG
	if (clipc > 0) {
	  printf("%d overs: %fdB avg, %fdB peak\n", clipc, clip/(float)clipc, 20.0*log10(clipp));
	}
	#endif

	plugin_data->buffer_pos = buffer_pos;
	plugin_data->peak = peak;
	plugin_data->atten = atten;
	plugin_data->atten_lp = atten_lp;
	plugin_data->chunk_pos = chunk_pos;
	plugin_data->chunk_num = chunk_num;

	*(plugin_data->attenuation) = -CO_DB(atten);
	*(plugin_data->latency) = delay;
}
Exemplo n.º 4
0
const vector4<int> round0(const vector4<t>& in)
{
    return vector4<int>(round_to_zero(in.x), round_to_zero(in.y),
                        round_to_zero(in.z), round_to_zero(in.w));
}
Exemplo n.º 5
0
static void runAddingSc4m(LADSPA_Handle instance, unsigned long sample_count) {
	Sc4m *plugin_data = (Sc4m *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

	/* RMS/peak (float value) */
	const LADSPA_Data rms_peak = *(plugin_data->rms_peak);

	/* Attack time (ms) (float value) */
	const LADSPA_Data attack = *(plugin_data->attack);

	/* Release time (ms) (float value) */
	const LADSPA_Data release = *(plugin_data->release);

	/* Threshold level (dB) (float value) */
	const LADSPA_Data threshold = *(plugin_data->threshold);

	/* Ratio (1:n) (float value) */
	const LADSPA_Data ratio = *(plugin_data->ratio);

	/* Knee radius (dB) (float value) */
	const LADSPA_Data knee = *(plugin_data->knee);

	/* Makeup gain (dB) (float value) */
	const LADSPA_Data makeup_gain = *(plugin_data->makeup_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;
	float amp = plugin_data->amp;
	float * as = plugin_data->as;
	unsigned int count = plugin_data->count;
	float env = plugin_data->env;
	float env_peak = plugin_data->env_peak;
	float env_rms = plugin_data->env_rms;
	float gain = plugin_data->gain;
	float gain_t = plugin_data->gain_t;
	rms_env * rms = plugin_data->rms;
	float sum = plugin_data->sum;

	unsigned long pos;

	const float ga = attack < 2.0f ? 0.0f : as[f_round(attack * 0.001f * (float)(A_TBL-1))];
	const float gr = as[f_round(release * 0.001f * (float)(A_TBL-1))];
	const float rs = (ratio - 1.0f) / ratio;
	const float mug = db2lin(makeup_gain);
	const float knee_min = db2lin(threshold - knee);
	const float knee_max = db2lin(threshold + knee);
	const float ef_a = ga * 0.25f;
	const float ef_ai = 1.0f - ef_a;

	for (pos = 0; pos < sample_count; pos++) {
	         const float lev_in = input[pos];
	  sum += lev_in * lev_in;

	  if (amp > env_rms) {
	    env_rms = env_rms * ga + amp * (1.0f - ga);
	  } else {
	    env_rms = env_rms * gr + amp * (1.0f - gr);
	  }
	  round_to_zero(&env_rms);
	  if (lev_in > env_peak) {
	    env_peak = env_peak * ga + lev_in * (1.0f - ga);
	  } else {
	    env_peak = env_peak * gr + lev_in * (1.0f - gr);
	  }
	  round_to_zero(&env_peak);
	  if ((count++ & 3) == 3) {
	    amp = rms_env_process(rms, sum * 0.25f);
	    sum = 0.0f;

	    env = LIN_INTERP(rms_peak, env_rms, env_peak);

	    if (env <= knee_min) {
	      gain_t = 1.0f;
	    } else if (env < knee_max) {
	      const float x = -(threshold - knee - lin2db(env)) / knee;
	      gain_t = db2lin(-knee * rs * x * x * 0.25f);
	    } else {
	      gain_t = db2lin((threshold - lin2db(env)) * rs);
	    }
	  }
	  gain = gain * ef_a + gain_t * ef_ai;
	  buffer_write(output[pos], input[pos] * gain * mug);
	}
	plugin_data->sum = sum;
	plugin_data->amp = amp;
	plugin_data->gain = gain;
	plugin_data->gain_t = gain_t;
	plugin_data->env = env;
	plugin_data->env_rms = env_rms;
	plugin_data->env_peak = env_peak;
	plugin_data->count = count;

	*(plugin_data->amplitude) = lin2db(env);
	*(plugin_data->gain_red) = lin2db(gain);
}