Example #1
0
static inline LADSPA_Data sat(LADSPA_Data x, float q,  float dist) {
        if (x == q) {
                return 1.0f / dist + q / (1.0f - f_exp(dist * q));
        }
        return ((x - q) / (1.0f - f_exp(-dist * (x - q))) + q /
         (1.0f - f_exp(dist * q)));
}
Example #2
0
static void runValveRect(LV2_Handle instance, uint32_t sample_count)
{
  ValveRect *plugin_data = (ValveRect *)instance;

  const float sag = *(plugin_data->sag);
  const float dist_p = *(plugin_data->dist_p);
  const float * const input = plugin_data->input;
  float * const output = plugin_data->output;
  float lp1tm1 = plugin_data->lp1tm1;
  float lp2tm1 = plugin_data->lp2tm1;
  float * avg = plugin_data->avg;
  int avg_size = plugin_data->avg_size;
  float avg_sizer = plugin_data->avg_sizer;
  float avgs = plugin_data->avgs;
  unsigned int apos = plugin_data->apos;
  
      unsigned long pos;
      float q, x, fx;
      const float dist = dist_p * 40.0f + 0.1f;

      for (pos = 0; pos < sample_count; pos++) {
        x = fabs(input[pos]);
        if (x > lp1tm1) {
          lp1tm1 = x;
        } else {
          lp1tm1 = 0.9999f * lp1tm1 + 0.0001f * x;
        }

        avgs -= avg[apos];
        avgs += lp1tm1;
        avg[apos++] = lp1tm1;
        apos %= avg_size;

        lp2tm1 = 0.999f * lp2tm1 + avgs*avg_sizer * 0.001f;
	q = lp1tm1 * sag - lp2tm1 * 1.02f - 1.0f;
	if (q > -0.01f) {
          q = -0.01f;
        } else if (q < -1.0f) {
          q = -1.0f;
        }

        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));
        }

        buffer_write(output[pos], fx);
      }

      plugin_data->lp1tm1 = lp1tm1;
      plugin_data->lp2tm1 = lp2tm1;
      plugin_data->avgs = avgs;
      plugin_data->apos = apos;
    
}
Example #3
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;
}
Example #4
0
void
RyanWah::setampsns (int Pp)
{
    Pampsns = Pp;
    if(Pampsns>0) {
        ampsns = expf(0.083f*(float)Pampsns);
    } else {
        ampsns = - expf(-0.083f*(float)Pampsns);
    }
    fbias  =  ((float)Pampsnsinv )/ 127.0f;

    ampsmooth = f_exp(-1.0f/((((float) Pampsmooth)/127.0f + 0.01f)*fSAMPLE_RATE)); //goes up to 1 second

};
Example #5
0
void
Dflange::changepar (int npar, int value)
{
    switch (npar) {
    case 0:
        Pwetdry = value;
        dry = (float) (Pwetdry+64) /128.0f;
        wet = 1.0f - dry;

        if(Psubtract) {
            ldelayline0->set_mix(-dry);
            rdelayline0->set_mix(-dry);
            ldelayline1->set_mix(-dry);
            rdelayline1->set_mix(-dry);
        } else {
            ldelayline0->set_mix(dry);
            rdelayline0->set_mix(dry);
            ldelayline1->set_mix(dry);
            rdelayline1->set_mix(dry);
        }

        break;
    case 1:
        Ppanning = value;
        if (value < 0) {
            rpan = 1.0f + (float) Ppanning/64.0;
            lpan = 1.0f;
        } else {
            lpan = 1.0f - (float) Ppanning/64.0;
            rpan = 1.0f;
        };
        break;
    case 2:
        Plrcross = value;
        flrcross = (float) Plrcross/127.0;
        frlcross = 1.0f - flrcross;	//keep this out of the DSP loop
        break;
    case 3:
        Pdepth = value;
        fdepth =  (float) Pdepth;
        zcenter = (int) fSAMPLE_RATE/floor(0.5f * (fdepth + fwidth));
        logmax = logf( (fdepth + fwidth)/fdepth )/LOG_2;
        break;
    case 4:
        Pwidth = value;
        fwidth = (float) Pwidth;
        zcenter = (int) fSAMPLE_RATE/floor(0.5f * (fdepth + fwidth));
        logmax = logf( (fdepth + fwidth)/fdepth )/LOG_2;
        break;
    case 5:
        Poffset = value;
        foffset = 0.5f + (float) Poffset/255.0;
        break;
    case 6:
        Pfb = value;
        ffb = (float) Pfb/64.5f;
        break;
    case 7:
        Phidamp = value;
        fhidamp = f_exp(-D_PI * (float) Phidamp/fSAMPLE_RATE);
        break;
    case 8:
        Psubtract = value;
        fsubtract = 0.5f;
        if(Psubtract) {
            fsubtract = -0.5f;  //In loop a mult by 0.5f is necessary, so this kills 2 birds with 1...
            ldelayline0->set_mix(-dry);
            rdelayline0->set_mix(-dry);
            ldelayline1->set_mix(-dry);
            rdelayline1->set_mix(-dry);
        }
        break;
    case 9:
        Pzero = value;
        if (Pzero) fzero = 1.0f;
        break;
    case 10:
        lfo.Pfreq = value;
        lfo.updateparams ();
        break;
    case 11:
        lfo.Pstereo = value;
        lfo.updateparams ();
        break;
    case 12:
        lfo.PLFOtype = value;
        lfo.updateparams ();
        break;
    case 13:
        lfo.Prandomness = value;
        lfo.updateparams ();
        break;
    case 14:
        Pintense = value;
        break;
    };
};
bool TestExtMath::test_exp() {
  VC(f_exp(12), 162754.791419);
  VC(f_exp(5.7), 298.86740096706);
  return Count(true);
}
Example #7
0
static void runAddingDysonCompress(LADSPA_Handle instance, unsigned long sample_count) {
	DysonCompress *plugin_data = (DysonCompress *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

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

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

	/* Fast compression ratio (float value) */
	const LADSPA_Data cfrate = *(plugin_data->cfrate);

	/* Compression ratio (float value) */
	const LADSPA_Data crate = *(plugin_data->crate);

	/* 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 * delay = plugin_data->delay;
	float extra_maxlevel = plugin_data->extra_maxlevel;
	float lastrgain = plugin_data->lastrgain;
	float maxgain = plugin_data->maxgain;
	float mingain = plugin_data->mingain;
	float ndelay = plugin_data->ndelay;
	unsigned int ndelayptr = plugin_data->ndelayptr;
	int peaklimitdelay = plugin_data->peaklimitdelay;
	float rgain = plugin_data->rgain;
	float rlevelsq0 = plugin_data->rlevelsq0;
	float rlevelsq1 = plugin_data->rlevelsq1;
	LADSPA_Data * rlevelsqe = plugin_data->rlevelsqe;
	LADSPA_Data * rlevelsqn = plugin_data->rlevelsqn;
	float rmastergain0 = plugin_data->rmastergain0;
	float rpeakgain0 = plugin_data->rpeakgain0;
	float rpeakgain1 = plugin_data->rpeakgain1;
	float rpeaklimitdelay = plugin_data->rpeaklimitdelay;
	float sample_rate = plugin_data->sample_rate;

	unsigned long pos;
	float targetlevel = MAXLEVEL * DB_CO(peak_limit);
	float rgainfilter = 1.0f / (release_time * sample_rate);
	float fastgaincompressionratio = cfrate;
	float compressionratio = crate;
	float efilt;
	float levelsqe;
	float gain;
	float tgain;
	float d;
	float fastgain;
	float qgain;
	float tslowgain;
	float slowgain;
	float npeakgain;
	float neww;
	float nrgain;
	float ngain;
	float ngsq;
	float tnrgain;
	float sqrtrpeakgain;
	float totalgain;
	unsigned int i;

	for (pos = 0; pos < sample_count; pos++) {
	  // Ergh! this was originally meant to track a stereo signal
	  float levelsq0 = 2.0f * (input[pos] * input[pos]);

	  delay[ndelayptr] = input[pos];
	  ndelayptr++;

	  if (ndelayptr >= ndelay) {
	    ndelayptr = 0;
	  }

	  if (levelsq0 > rlevelsq0) {
	    rlevelsq0 = (levelsq0 * RLEVELSQ0FFILTER) +
	     rlevelsq0 * (1 - RLEVELSQ0FFILTER);
	  } else {
	    rlevelsq0 = (levelsq0 * RLEVELSQ0FILTER) +
	     rlevelsq0 * (1 - RLEVELSQ0FILTER);
	  }

	  if (rlevelsq0 <= FLOORLEVEL * FLOORLEVEL) {
	    goto skipagc;
	  }

	  if (rlevelsq0 > rlevelsq1) {
	    rlevelsq1 = rlevelsq0;
	  } else {
	    rlevelsq1 = rlevelsq0 * RLEVELSQ1FILTER +
	      rlevelsq1 * (1 - RLEVELSQ1FILTER);
	  }

	  rlevelsqn[0] = rlevelsq1;
	  for(i = 0; i < NFILT-1; i++) {
	    if (rlevelsqn[i] > rlevelsqn[i+1])
	      rlevelsqn[i+1] = rlevelsqn[i];
	    else
	      rlevelsqn[i+1] = rlevelsqn[i] * RLEVELSQ1FILTER +
	        rlevelsqn[i+1] * (1 - RLEVELSQ1FILTER);
	  }

	  efilt = RLEVELSQEFILTER;
	  levelsqe = rlevelsqe[0] = rlevelsqn[NFILT-1];
	  for(i = 0; i < NEFILT-1; i++) {
	    rlevelsqe[i+1] = rlevelsqe[i] * efilt +
	      rlevelsqe[i+1] * (1.0 - efilt);
	    if (rlevelsqe[i+1] > levelsqe)
	      levelsqe = rlevelsqe[i+1];
	    efilt *= 1.0f / 1.5f;
	  }

	  gain = targetlevel / sqrt(levelsqe);
	  if (compressionratio < 0.99f) {
	    if (compressionratio == 0.50f)
	      gain = sqrt(gain);
	    else
	      gain = f_exp(log(gain) * compressionratio);
	  }

	  if (gain < rgain)
	    rgain = gain * RLEVELSQEFILTER/2 +
	      rgain * (1 - RLEVELSQEFILTER/2);
	  else
	    rgain = gain * rgainfilter +
	      rgain * (1 - rgainfilter);

	  lastrgain = rgain;
	  if ( gain < lastrgain)
	    lastrgain = gain;

	skipagc:;

	  tgain = lastrgain;

	  d = delay[ndelayptr];

	  fastgain = tgain;
	  if (fastgain > MAXFASTGAIN)
	    fastgain = MAXFASTGAIN;

	  if (fastgain < 0.0001)
	    fastgain = 0.0001;

	  qgain = f_exp(log(fastgain) * fastgaincompressionratio);

	  tslowgain = tgain / qgain;
	  if (tslowgain > MAXSLOWGAIN)
	    tslowgain = MAXSLOWGAIN;
	  if (tslowgain < rmastergain0)
	    rmastergain0 = tslowgain;
	  else
	    rmastergain0 = tslowgain * RMASTERGAIN0FILTER +
	      (1 - RMASTERGAIN0FILTER) * rmastergain0;

	  slowgain = rmastergain0;
	  npeakgain = slowgain * qgain;

	  neww = d * npeakgain;
	  if (fabs(neww) >= MAXLEVEL)
	    nrgain = MAXLEVEL / fabs(neww);
	  else
	    nrgain = 1.0;

	  ngain = nrgain;

	  ngsq = ngain * ngain;
	  if (ngsq <= rpeakgain0) {
	    rpeakgain0 = ngsq /* * 0.50 + rpeakgain0 * 0.50 */;
	    rpeaklimitdelay = peaklimitdelay;
	  } else if (rpeaklimitdelay == 0) {
	    if (nrgain > 1.0)
	      tnrgain = 1.0;
	    else
	      tnrgain = nrgain;
	    rpeakgain0 = tnrgain * RPEAKGAINFILTER +
	      (1.0 - RPEAKGAINFILTER) * rpeakgain0;
	  }

	  if (rpeakgain0 <= rpeakgain1) {
	    rpeakgain1 = rpeakgain0;
	    rpeaklimitdelay = peaklimitdelay;
	  } else if (rpeaklimitdelay == 0) {
	    rpeakgain1 = RPEAKGAINFILTER * rpeakgain0 +
	      (1.0 - RPEAKGAINFILTER) * rpeakgain1;
	  } else {
	    --rpeaklimitdelay;
	  }

	  sqrtrpeakgain = sqrt(rpeakgain1);
	  totalgain = npeakgain * sqrtrpeakgain;

	  buffer_write(output[pos], neww * sqrtrpeakgain);

	  if (totalgain > maxgain)
	    maxgain = totalgain;
	  if (totalgain < mingain)
	    mingain = totalgain;
	  if (output[pos] > extra_maxlevel)
	    extra_maxlevel = output[pos];
	}

	plugin_data->ndelayptr = ndelayptr;
	plugin_data->rlevelsq0 = rlevelsq0;
	plugin_data->rlevelsq1 = rlevelsq1;
	plugin_data->mingain = mingain;
	plugin_data->maxgain = maxgain;
	plugin_data->rpeaklimitdelay = rpeaklimitdelay;
	plugin_data->rgain = rgain;
	plugin_data->rmastergain0 = rmastergain0;
	plugin_data->rpeakgain0 = rpeakgain0;
	plugin_data->rpeakgain1 = rpeakgain1;
	plugin_data->lastrgain = lastrgain;
	plugin_data->extra_maxlevel = extra_maxlevel;
}
Example #8
0
static void runAddingValveRect(LADSPA_Handle instance, unsigned long sample_count) {
	ValveRect *plugin_data = (ValveRect *)instance;
	LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;

	/* Sag level (float value) */
	const LADSPA_Data sag = *(plugin_data->sag);

	/* Distortion (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;
	unsigned int apos = plugin_data->apos;
	float * avg = plugin_data->avg;
	int avg_size = plugin_data->avg_size;
	float avg_sizer = plugin_data->avg_sizer;
	float avgs = plugin_data->avgs;
	float lp1tm1 = plugin_data->lp1tm1;
	float lp2tm1 = plugin_data->lp2tm1;

#line 48 "valve_rect_1405.xml"
	unsigned long pos;
	float q, x, fx;
	const float dist = dist_p * 40.0f + 0.1f;

	for (pos = 0; pos < sample_count; pos++) {
	  x = fabs(input[pos]);
	  if (x > lp1tm1) {
	    lp1tm1 = x;
	  } else {
	    lp1tm1 = 0.9999f * lp1tm1 + 0.0001f * x;
	  }

	  avgs -= avg[apos];
	  avgs += lp1tm1;
	  avg[apos++] = lp1tm1;
	  apos %= avg_size;

	  lp2tm1 = 0.999f * lp2tm1 + avgs*avg_sizer * 0.001f;
	  q = lp1tm1 * sag - lp2tm1 * 1.02f - 1.0f;
	  if (q > -0.01f) {
	    q = -0.01f;
	  } else if (q < -1.0f) {
	    q = -1.0f;
	  }

	  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));
	  }

	  buffer_write(output[pos], fx);
	}

	plugin_data->lp1tm1 = lp1tm1;
	plugin_data->lp2tm1 = lp2tm1;
	plugin_data->avgs = avgs;
	plugin_data->apos = apos;
}
ConstitutiveModelParameters<EvalT, Traits>::
ConstitutiveModelParameters(Teuchos::ParameterList& p,
    const Teuchos::RCP<Albany::Layouts>& dl) :
    have_temperature_(false),
    dl_(dl)
{
  // get number of integration points and spatial dimensions
  std::vector<PHX::DataLayout::size_type> dims;
  dl_->qp_vector->dimensions(dims);
  num_pts_ = dims[1];
  num_dims_ = dims[2];

  // get the Parameter Library
  Teuchos::RCP<ParamLib> paramLib =
      p.get<Teuchos::RCP<ParamLib> >("Parameter Library", Teuchos::null);

  // get the material parameter list
  Teuchos::ParameterList* mat_params =
      p.get<Teuchos::ParameterList*>("Material Parameters");

  // Check for optional field: temperature
  if (p.isType<std::string>("Temperature Name")) {
    have_temperature_ = true;
    PHX::MDField<ScalarT, Cell, QuadPoint>
    tmp(p.get<std::string>("Temperature Name"), dl_->qp_scalar);
    temperature_ = tmp;
    this->addDependentField(temperature_);
  }

  // step through the possible parameters, registering as necessary
  //
  // elastic modulus
  std::string e_mod("Elastic Modulus");
  if (mat_params->isSublist(e_mod)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(e_mod, dl_->qp_scalar);
    elastic_mod_ = tmp;
    field_map_.insert(std::make_pair(e_mod, elastic_mod_));
    parseParameters(e_mod, p, paramLib);
  }
  // Poisson's ratio
  std::string pr("Poissons Ratio");
  if (mat_params->isSublist(pr)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(pr, dl_->qp_scalar);
    poissons_ratio_ = tmp;
    field_map_.insert(std::make_pair(pr, poissons_ratio_));
    parseParameters(pr, p, paramLib);
  }
  // bulk modulus
  std::string b_mod("Bulk Modulus");
  if (mat_params->isSublist(b_mod)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(b_mod, dl_->qp_scalar);
    bulk_mod_ = tmp;
    field_map_.insert(std::make_pair(b_mod, bulk_mod_));
    parseParameters(b_mod, p, paramLib);
  }
  // shear modulus
  std::string s_mod("Shear Modulus");
  if (mat_params->isSublist(s_mod)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(s_mod, dl_->qp_scalar);
    shear_mod_ = tmp;
    field_map_.insert(std::make_pair(s_mod, shear_mod_));
    parseParameters(s_mod, p, paramLib);
  }
  // yield strength
  std::string yield("Yield Strength");
  if (mat_params->isSublist(yield)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(yield, dl_->qp_scalar);
    yield_strength_ = tmp;
    field_map_.insert(std::make_pair(yield, yield_strength_));
    parseParameters(yield, p, paramLib);
  }
  // hardening modulus
  std::string h_mod("Hardening Modulus");
  if (mat_params->isSublist(h_mod)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(h_mod, dl_->qp_scalar);
    hardening_mod_ = tmp;
    field_map_.insert(std::make_pair(h_mod, hardening_mod_));
    parseParameters(h_mod, p, paramLib);
  }
  // recovery modulus
  std::string r_mod("Recovery Modulus");
  if (mat_params->isSublist(r_mod)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(r_mod, dl_->qp_scalar);
    recovery_mod_ = tmp;
    field_map_.insert(std::make_pair(r_mod, recovery_mod_));
    parseParameters(r_mod, p, paramLib);
  }
  // concentration equilibrium parameter
  std::string c_eq("Concentration Equilibrium Parameter");
  if (mat_params->isSublist(c_eq)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(c_eq, dl_->qp_scalar);
    conc_eq_param_ = tmp;
    field_map_.insert(std::make_pair(c_eq, conc_eq_param_));
    parseParameters(c_eq, p, paramLib);
  }
  // diffusion coefficient
  std::string d_coeff("Diffusion Coefficient");
  if (mat_params->isSublist(d_coeff)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(d_coeff, dl_->qp_scalar);
    diff_coeff_ = tmp;
    field_map_.insert(std::make_pair(d_coeff, diff_coeff_));
    parseParameters(d_coeff, p, paramLib);
  }
  // thermal conductivity
  std::string th_cond("Thermal Conductivity");
  if (mat_params->isSublist(th_cond)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(th_cond, dl_->qp_scalar);
    thermal_cond_ = tmp;
    field_map_.insert(std::make_pair(th_cond, thermal_cond_));
    parseParameters(th_cond, p, paramLib);
  }
  // flow rule coefficient
  std::string f_coeff("Flow Rule Coefficient");
  if (mat_params->isSublist(f_coeff)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(f_coeff, dl_->qp_scalar);
    flow_coeff_ = tmp;
    field_map_.insert(std::make_pair(f_coeff, flow_coeff_));
    parseParameters(f_coeff, p, paramLib);
  }
  // flow rule exponent
  std::string f_exp("Flow Rule Exponent");
  if (mat_params->isSublist(f_exp)) {
    PHX::MDField<ScalarT, Cell, QuadPoint> tmp(f_exp, dl_->qp_scalar);
    flow_exp_ = tmp;
    field_map_.insert(std::make_pair(f_exp, flow_exp_));
    parseParameters(f_exp, p, paramLib);
  }

  // register evaluated fields
  typename
  std::map<std::string, PHX::MDField<ScalarT, Cell, QuadPoint> >::iterator it;
  for (it = field_map_.begin();
      it != field_map_.end();
      ++it) {
    this->addEvaluatedField(it->second);
  }
  this->setName(
      "Constitutive Model Parameters" + PHX::TypeString<EvalT>::value);
}
Example #10
0
bool nf2ff_calc::AddPlane(float **lines, unsigned int* numLines, complex<float>**** E_field, complex<float>**** H_field, int MeshType)
{
	//find normal direction
	int ny = -1;
	int nP,nPP;
	for (int n=0;n<3;++n)
	{
		nP = (n+1)%3;
		nPP = (n+2)%3;
		if ((numLines[n]==1) && (numLines[nP]>2) && (numLines[nPP]>2))
			ny=n;
	}
	nP = (ny+1)%3;
	nPP = (ny+2)%3;
	if (ny<0)
	{
		cerr << "nf2ff_calc::AddPlane: Error can't determine normal direction..." << endl;
		return false;
	}

	complex<float>**** Js = Create_N_3DArray<complex<float> >(numLines);
	complex<float>**** Ms = Create_N_3DArray<complex<float> >(numLines);

	float normDir[3]= {0,0,0};
	if (lines[ny][0]>=m_centerCoord[ny])
		normDir[ny]=1;
	else
		normDir[ny]=-1;
	unsigned int pos[3];

	float edge_length_P[numLines[nP]];
	for (unsigned int n=1;n<numLines[nP]-1;++n)
		edge_length_P[n]=0.5*(lines[nP][n+1]-lines[nP][n-1]);
	edge_length_P[0]=0.5*(lines[nP][1]-lines[nP][0]);
	edge_length_P[numLines[nP]-1]=0.5*(lines[nP][numLines[nP]-1]-lines[nP][numLines[nP]-2]);

	float edge_length_PP[numLines[nPP]];
	for (unsigned int n=1;n<numLines[nPP]-1;++n)
		edge_length_PP[n]=0.5*(lines[nPP][n+1]-lines[nPP][n-1]);
	edge_length_PP[0]=0.5*(lines[nPP][1]-lines[nPP][0]);
	edge_length_PP[numLines[nPP]-1]=0.5*(lines[nPP][numLines[nPP]-1]-lines[nPP][numLines[nPP]-2]);

	//check for cylindrical mesh
	if (MeshType==1)
	{
		if (ny==0) //surface a-z
		{
			for (unsigned int n=0;n<numLines[nP];++n)
				edge_length_P[n]*=lines[0][0]; //angle-width * radius
		}
		else if (ny==2) //surface r-a
		{
			//calculate: area = delta_angle * delta_radius * center_radius
			for (unsigned int n=1;n<numLines[nP]-1;++n)
				edge_length_P[n]*=lines[nP][n];  //radius-width * center-radius
			edge_length_P[0]*=(lines[nP][0]+0.5*edge_length_P[0]);
			edge_length_P[numLines[nP]-1]*=(lines[nP][numLines[nP]-1]-0.5*edge_length_P[numLines[nP]-1]);
		}
	}

	complex<float> power = 0;
	float area;
	for (pos[0]=0; pos[0]<numLines[0]; ++pos[0])
		for (pos[1]=0; pos[1]<numLines[1]; ++pos[1])
			for (pos[2]=0; pos[2]<numLines[2]; ++pos[2])
			{
				area = edge_length_P[pos[nP]]*edge_length_PP[pos[nPP]];
				power = (E_field[nP][pos[0]][pos[1]][pos[2]]*conj(H_field[nPP][pos[0]][pos[1]][pos[2]]) \
						 - E_field[nPP][pos[0]][pos[1]][pos[2]]*conj(H_field[nP][pos[0]][pos[1]][pos[2]]));
				m_radPower += 0.5*area*real(power)*normDir[ny];
			}
	unsigned int numAngles[2] = {m_numTheta, m_numPhi};

	// setup multi-threading jobs
	vector<unsigned int> jpt = AssignJobs2Threads(numLines[nP], m_numThreads, true);
	m_numThreads = jpt.size();
	nf2ff_data thread_data[m_numThreads];
	m_Barrier = new boost::barrier(m_numThreads+1); // numThread workers + 1 controller
	unsigned int start=0;
	unsigned int stop=jpt.at(0)-1;
	for (unsigned int n=0; n<m_numThreads; n++)
	{
		thread_data[n].ny=ny;
		thread_data[n].mesh_type = MeshType;
		thread_data[n].normDir=normDir;
		thread_data[n].numLines=numLines;
		thread_data[n].lines=lines;
		thread_data[n].edge_length_P=edge_length_P;
		thread_data[n].edge_length_PP=edge_length_PP;
		thread_data[n].E_field=E_field;
		thread_data[n].H_field=H_field;
		thread_data[n].Js=Js;
		thread_data[n].Ms=Ms;
		thread_data[n].m_Nt=Create2DArray<complex<float> >(numAngles);
		thread_data[n].m_Np=Create2DArray<complex<float> >(numAngles);
		thread_data[n].m_Lt=Create2DArray<complex<float> >(numAngles);
		thread_data[n].m_Lp=Create2DArray<complex<float> >(numAngles);

		boost::thread *t = new boost::thread( nf2ff_calc_thread(this,start,stop,n,thread_data[n]) );

		m_thread_group.add_thread( t );

		start = stop+1;
		if (n<m_numThreads-1)
			stop = start + jpt.at(n+1)-1;
	}
	//all threads a running and waiting for the barrier

	m_Barrier->wait(); //start

	// threads: calc Js and Ms (eq. 8.15a/b)
	// threads calc their local Nt,Np,Lt and Lp

	m_Barrier->wait(); //combine all thread local Nt,Np,Lt and Lp

	//cleanup E- & H-Fields
	Delete_N_3DArray(E_field,numLines);
	Delete_N_3DArray(H_field,numLines);

	complex<float>** Nt = Create2DArray<complex<float> >(numAngles);
	complex<float>** Np = Create2DArray<complex<float> >(numAngles);
	complex<float>** Lt = Create2DArray<complex<float> >(numAngles);
	complex<float>** Lp = Create2DArray<complex<float> >(numAngles);

	for (unsigned int n=0; n<m_numThreads; n++)
	{
		for (unsigned int tn=0;tn<m_numTheta;++tn)
			for (unsigned int pn=0;pn<m_numPhi;++pn)
			{
				Nt[tn][pn] += thread_data[n].m_Nt[tn][pn];
				Np[tn][pn] += thread_data[n].m_Np[tn][pn];
				Lt[tn][pn] += thread_data[n].m_Lt[tn][pn];
				Lp[tn][pn] += thread_data[n].m_Lp[tn][pn];
			}
		Delete2DArray(thread_data[n].m_Nt,numAngles);
		Delete2DArray(thread_data[n].m_Np,numAngles);
		Delete2DArray(thread_data[n].m_Lt,numAngles);
		Delete2DArray(thread_data[n].m_Lp,numAngles);
	}

	m_Barrier->wait(); //wait for termination
	m_thread_group.join_all(); // wait for termination
	delete m_Barrier;
	m_Barrier = NULL;

	//cleanup Js & Ms
	Delete_N_3DArray(Js,numLines);
	Delete_N_3DArray(Ms,numLines);

	// calc equations 8.23a/b and 8.24a/b
	float k = 2*M_PI*m_freq/__C0__;
	complex<float> factor(0,k/4.0/M_PI/m_radius);
	complex<float> f_exp(0,-1*k*m_radius);
	factor *= exp(f_exp);
	complex<float> Z0 = __Z0__;
	float P_max = 0;
	for (unsigned int tn=0;tn<m_numTheta;++tn)
		for (unsigned int pn=0;pn<m_numPhi;++pn)
		{
			m_E_theta[tn][pn] -= factor*(Lp[tn][pn] + Z0*Nt[tn][pn]);
			m_E_phi[tn][pn] += factor*(Lt[tn][pn] - Z0*Np[tn][pn]);

			m_H_theta[tn][pn] += factor*(Np[tn][pn] - Lt[tn][pn]/Z0);
			m_H_phi[tn][pn] -= factor*(Nt[tn][pn] + Lp[tn][pn]/Z0);

			m_P_rad[tn][pn] = m_radius*m_radius/(2*__Z0__) * abs((m_E_theta[tn][pn]*conj(m_E_theta[tn][pn])+m_E_phi[tn][pn]*conj(m_E_phi[tn][pn])));
			if (m_P_rad[tn][pn]>P_max)
				P_max = m_P_rad[tn][pn];
		}

	//cleanup Nx and Lx
	Delete2DArray(Nt,numAngles);
	Delete2DArray(Np,numAngles);
	Delete2DArray(Lt,numAngles);
	Delete2DArray(Lp,numAngles);

	m_maxDir = 4*M_PI*P_max / m_radPower;

	return true;
}
Example #11
0
void
Opticaltrem::out (float *smpsl, float *smpsr, uint32_t period)
{

    unsigned int i;
    float lfol, lfor, xl, xr, fxl, fxr;
    float rdiff, ldiff;
    lfo->effectlfoout (&lfol, &lfor);

    if(Pinvert) {
    lfol = lfol*fdepth;
    lfor = lfor*fdepth;
    } else {
    lfor = 1.0f - lfor*fdepth;
    lfol = 1.0f - lfol*fdepth;
    }

    if (lfol > 1.0f)
        lfol = 1.0f;
    else if (lfol < 0.0f)
        lfol = 0.0f;
    if (lfor > 1.0f)
        lfor = 1.0f;
    else if (lfor < 0.0f)
        lfor = 0.0f;

    lfor = powf(lfor, 1.9f);
    lfol = powf(lfol, 1.9f);  //emulate lamp turn on/off characteristic

    //lfo interpolation
    rdiff = (lfor - oldgr)/(float)period;
    ldiff = (lfol - oldgl)/(float)period;
    gr = lfor;
    gl = lfol;
    oldgr = lfor;
    oldgl = lfol;

    for (i = 0; i < period; i++) {
        //Left Cds
        stepl = gl*(1.0f - alphal) + alphal*oldstepl;
        oldstepl = stepl;
        dRCl = dTC*f_exp(stepl*minTC);
        alphal = 1.0f - cSAMPLE_RATE/(dRCl + cSAMPLE_RATE);
        xl = CNST_E + stepl*b;
        fxl = f_exp(Ra/logf(xl));
        if(Pinvert) {
        fxl = fxl*Rp/(fxl + Rp); //Parallel resistance
        fxl = fxl/(fxl + R1);
        }
        else fxl = R1/(fxl + R1);
        
        //Right Cds
        stepr = gr*(1.0f - alphar) + alphar*oldstepr;
        oldstepr = stepr;
        dRCr = dTC*f_exp(stepr*minTC);
        alphar = 1.0f - cSAMPLE_RATE/(dRCr + cSAMPLE_RATE);
        xr = CNST_E + stepr*b;
        fxr = f_exp(Ra/logf(xr));
        if(Pinvert) {
        fxr = fxr*Rp/(fxr + Rp); //Parallel resistance
        fxr = fxr/(fxr + R1);
        } 
        else fxr = R1/(fxr + R1);

        //Modulate input signal
        efxoutl[i] = lpanning*fxl*smpsl[i];
        efxoutr[i] = rpanning*fxr*smpsr[i];

        gl += ldiff;
        gr += rdiff;  //linear interpolation of LFO

    };


};
Example #12
0
void
Vibe::out (float *smpsl, float *smpsr)
{

    int i,j;
    float lfol, lfor, xl, xr;
    float  fxl=0.0f;
    float  fxr=0.0f;
    //float vbe,vin;
    float cvolt, ocvolt, evolt, input;
    float emitterfb = 0.0f;
    float outl, outr;

    input = cvolt = ocvolt = evolt = 0.0f;

    lfo.effectlfoout (&lfol, &lfor);

    lfol = fdepth + lfol*fwidth;
    if (lfol > 1.0f)
        lfol = 1.0f;
    else if (lfol < 0.0f)
        lfol = 0.0f;
    lfol = 2.0f - 2.0f/(lfol + 1.0f); //emulate lamp turn on/off characteristic by typical curves

    if(Pstereo) {
        lfor = fdepth + lfor*fwidth;
        if (lfor > 1.0f) lfor = 1.0f;
        else if (lfor < 0.0f) lfor = 0.0f;
        lfor = 2.0f - 2.0f/(lfor + 1.0f);   //
    }

    for (i = 0; i < param->PERIOD; i++) {
        //Left Lamp
        gl = lfol*lampTC + oldgl*ilampTC;
        oldgl = gl;

        //Left Cds
        stepl = gl*alphal + dalphal*oldstepl;
        oldstepl = stepl;
        dRCl = dTC*f_exp(stepl*minTC);
        alphal = cSAMPLE_RATE/(dRCl + cSAMPLE_RATE);
        dalphal = 1.0f - cSAMPLE_RATE/(0.5f*dRCl + cSAMPLE_RATE);     //different attack & release character
        xl = CNST_E + stepl*b;
        fxl = f_exp(Ra/logf(xl));

        //Right Lamp
        if(Pstereo) {
            gr = lfor*lampTC + oldgr*ilampTC;
            oldgr = gr;

            //Right Cds
            stepr = gr*alphar + dalphar*oldstepr;
            oldstepr = stepr;
            dRCr = dTC*f_exp(stepr*minTC);
            alphar = cSAMPLE_RATE/(dRCr + cSAMPLE_RATE);
            dalphar = 1.0f - cSAMPLE_RATE/(0.5f*dRCr + cSAMPLE_RATE);      //different attack & release character
            xr = CNST_E + stepr*b;
            fxr = f_exp(Ra/logf(xr));
        }

        if(i%16 == 0)  modulate(fxl, fxr);

        //Left Channel
        input = bjt_shape(fbl + smpsl[i]);


        /*
        //Inline BJT Shaper bleow
            vin = 7.5f*(1.0f + fbl+smpsl[i]);
            if(vin<0.0f) vin = 0.0f;
            if(vin>15.0f) vin = 15.0f;
            vbe = 0.8f - 0.8f/(vin + 1.0f);  //really rough, simplistic bjt turn-on emulator
            input = vin - vbe;
            input = input*0.1333333333f -0.90588f;  //some magic numbers to return gain to unity & zero the DC

        */

        emitterfb = 25.0f/fxl;
        for(j=0; j<4; j++) { //4 stages phasing
            /*
            //Inline filter implementation below
                float y0 = 0.0f;
                y0 = input*ecvc[j].n0 + ecvc[j].x1*ecvc[j].n1 - ecvc[j].y1*ecvc[j].d1;
                ecvc[j].y1 = y0 + DENORMAL_GUARD;
                ecvc[j].x1 = input;


                float x0 = 0.0f;
                float data = input + emitterfb*oldcvolt[j];
                x0 = data*vc[j].n0 + vc[j].x1*vc[j].n1 - vc[j].y1*vc[j].d1;
                vc[j].y1 = x0 + DENORMAL_GUARD;
                vc[j].x1 = data;

                cvolt=y0+x0;


                ocvolt= cvolt*vcvo[j].n0 + vcvo[j].x1*vcvo[j].n1 - vcvo[j].y1*vcvo[j].d1;
                vcvo[j].y1 = ocvolt + DENORMAL_GUARD;
                vcvo[j].x1 = cvolt;

                oldcvolt[j] = ocvolt;

                evolt = input*vevo[j].n0 + vevo[j].x1*vevo[j].n1 - vevo[j].y1*vevo[j].d1;
                vevo[j].y1 = evolt + DENORMAL_GUARD;
                vevo[j].x1 = input;

                vin = 7.5f*(1.0f + ocvolt+evolt);
                if(vin<0.0f) vin = 0.0f;
                if(vin>15.0f) vin = 15.0f;
                vbe = 0.8f - 0.8f/(vin + 1.0f);  //really rough, simplistic bjt turn-on emulator
                input = vin - vbe;
                input = input*0.1333333333f -0.90588f;  //some magic numbers to return gain to unity & zero the DC
            */

// Orig code, Comment below if instead using inline
            cvolt = vibefilter(input,ecvc,j) + vibefilter(input + emitterfb*oldcvolt[j],vc,j);
            ocvolt = vibefilter(cvolt,vcvo,j);
            oldcvolt[j] = ocvolt;
            evolt = vibefilter(input, vevo,j);

            input = bjt_shape(ocvolt + evolt);
            //Close comment here if using inline

        }
        fbl = fb*ocvolt;
        outl = lpanning*input;

        //Right channel

        if(Pstereo) {
            /*
            //Inline BJT shaper
             vin = 7.5f*(1.0f + fbr+smpsr[i]);
             if(vin<0.0f) vin = 0.0f;
             if(vin>15.0f) vin = 15.0f;
             vbe = 0.8f - 0.8f/(vin + 1.0f);  //really rough, simplistic bjt turn-on emulator
             input = vin - vbe;
             input = input*0.1333333333f -0.90588f;  //some magic numbers to return gain to unity & zero the DC
             */


//Orig code
            input = bjt_shape(fbr + smpsr[i]);
            //Close Comment here if using Inline instead

            emitterfb = 25.0f/fxr;
            for(j=4; j<8; j++) { //4 stages phasing

                /*
                //This is the inline version

                    float y0 = 0.0f;
                    y0 = input*ecvc[j].n0 + ecvc[j].x1*ecvc[j].n1 - ecvc[j].y1*ecvc[j].d1;
                    ecvc[j].y1 = y0 + DENORMAL_GUARD;
                    ecvc[j].x1 = input;


                    float x0 = 0.0f;
                    float data = input + emitterfb*oldcvolt[j];
                    x0 = data*vc[j].n0 + vc[j].x1*vc[j].n1 - vc[j].y1*vc[j].d1;
                    vc[j].y1 = x0 + DENORMAL_GUARD;
                    vc[j].x1 = data;

                    cvolt=y0+x0;


                    ocvolt= cvolt*vcvo[j].n0 + vcvo[j].x1*vcvo[j].n1 - vcvo[j].y1*vcvo[j].d1;
                    vcvo[j].y1 = ocvolt + DENORMAL_GUARD;
                    vcvo[j].x1 = cvolt;

                    oldcvolt[j] = ocvolt;

                    evolt = input*vevo[j].n0 + vevo[j].x1*vevo[j].n1 - vevo[j].y1*vevo[j].d1;
                    vevo[j].y1 = evolt + DENORMAL_GUARD;
                    vevo[j].x1 = input;


                    vin = 7.5f*(1.0f + ocvolt+evolt);
                    if(vin<0.0f) vin = 0.0f;
                    if(vin>15.0f) vin = 15.0f;
                    vbe = 0.8f - 0.8f/(vin + 1.0f);  //really rough, simplistic bjt turn-on emulator
                    input = vin - vbe;
                    input = input*0.1333333333f -0.90588f;  //some magic numbers to return gain to unity & zero the DC

                */

//  Comment block below if using inline code instead
                cvolt = vibefilter(input,ecvc,j) + vibefilter(input + emitterfb*oldcvolt[j],vc,j);
                ocvolt = vibefilter(cvolt,vcvo,j);
                oldcvolt[j] = ocvolt;
                evolt = vibefilter(input, vevo,j);

                input = bjt_shape(ocvolt + evolt);
// Close comment here if inlining
            }

            fbr = fb*ocvolt;
            outr = rpanning*input;

            efxoutl[i] = outl*fcross + outr*flrcross;
            efxoutr[i] = outr*fcross + outl*flrcross;
        }  else {  //if(Pstereo)
            efxoutl[i] = outl;
            efxoutr[i] = outl;
        }

    };

};
Example #13
0
// Set release time in samples
inline static void env_set_release(envelope *e, float r)
{
  e->gr = f_exp(-1.0f/r);
}
Example #14
0
// Set attack time in samples
inline static void env_set_attack(envelope *e, float a)
{
  e->ga = f_exp(-1.0f/a);
}