Exemple #1
0
void wuter_perform64(t_wuter *x, t_object *dsp64, double **ins, long numins, double **outs, long numouts, long sampleframes, long flags, void *userparam)
{
    t_double num_objects	= x->num_objectsConnected	? 	*(t_double *)(ins[0]) : x->num_objects;
    t_double res_freq 		= x->res_freqConnected		? 	*(t_double *)(ins[1]) : x->res_freq;
    t_double shake_damp 	= x->shake_dampConnected	? 	*(t_double *)(ins[2]) : x->shake_damp;
    t_double shake_max      = x->shake_maxConnected		? 	*(t_double *)(ins[3]) : x->shake_max;
    
    t_double *outL = (t_double *)(outs[0]);
    t_double *outR = (t_double *)(outs[1]);
    long n = sampleframes;

    t_double lastOutput;
    
    if(num_objects != x->num_objectsSave) {
        if(num_objects < 1.) num_objects = 1.;
        x->num_objects = (long)num_objects;
        x->num_objectsSave = (long)num_objects;
        x->gain = log(num_objects) * 30. / (float)num_objects;
    }
    
    if(res_freq != x->res_freqSave) {
        x->res_freqSave = x->res_freq = res_freq;
        //temp = 900. * pow(1.015,res_freq);
        //x->coeffs[0] = -0.96 * 2.0 * cos(temp * TWO_PI / x->srate);
        //x->coeffs[1] = 0.96*0.96;
    }
    
    if(shake_damp != x->shake_dampSave) {
        x->res_spread = x->shake_dampSave = x->shake_damp = shake_damp;
        x->systemDecay = .998 + (shake_damp * .002);
    }
    
    if(shake_max != x->shake_maxSave) {
        x->res_random = x->shake_maxSave = x->shake_max = shake_max;
        //x->shakeEnergy += shake_max * MAX_SHAKE * 0.1;
        //if (x->shakeEnergy > MAX_SHAKE) x->shakeEnergy = MAX_SHAKE;
    }	
    
    while(n--) {
        lastOutput = wuter_tick(x);		
        *outL++ = lastOutput*x->pandropL;
        *outR++ = lastOutput*x->pandropR;
    }
}
StkFloat Shakers :: computeSample()
{
  StkFloat data;
  StkFloat temp_rand;
  int i;

  if (instType_ == 4) {
  	if (shakeEnergy_ > MIN_ENERGY)	{
      lastOutput_ = wuter_tick();
      lastOutput_ *= 0.0001;
    }
    else {
      lastOutput_ = 0.0;
    }
  }
  else if (instType_ == 22) {
    lastOutput_ = tbamb_tick();
  }
  else if (instType_ == 10 || instType_ == 3) {
    if (ratchetPos_ > 0) {
      ratchet_ -= (ratchetDelta_ + (0.002*totalEnergy_));
      if (ratchet_ < 0.0) {
        ratchet_ = 1.0;
        ratchetPos_ -= 1;
	    }
      totalEnergy_ = ratchet_;
      lastOutput_ = ratchet_tick();
      lastOutput_ *= 0.0001;
    }
    else lastOutput_ = 0.0;
  }
  else  { // generic_tick()
    if (shakeEnergy_ > MIN_ENERGY) {
      shakeEnergy_ *= systemDecay_;               // Exponential system decay
      if (float_random(1024.0) < nObjects_) {
        sndLevel_ += shakeEnergy_;   
        for (i=0;i<nFreqs_;i++) {
          if (freqalloc_[i])	{
            temp_rand = t_center_freqs_[i] * (1.0 + (freq_rand_[i] * noise_tick()));
            coeffs_[i][0] = -resons_[i] * 2.0 * cos(temp_rand * TWO_PI / Stk::sampleRate());
          }
        }
    	}
      inputs_[0] = sndLevel_ * noise_tick();      // Actual Sound is Random
      for (i=1; i<nFreqs_; i++)	{
        inputs_[i] = inputs_[0];
      }
      sndLevel_ *= soundDecay_;                   // Exponential Sound decay 
      finalZ_[2] = finalZ_[1];
      finalZ_[1] = finalZ_[0];
      finalZ_[0] = 0;
      for (i=0;i<nFreqs_;i++)	{
        inputs_[i] -= outputs_[i][0]*coeffs_[i][0];  // Do
        inputs_[i] -= outputs_[i][1]*coeffs_[i][1];  // resonant
        outputs_[i][1] = outputs_[i][0];            // filter
        outputs_[i][0] = inputs_[i];                // calculations
        finalZ_[0] += gains_[i] * outputs_[i][1];
      }
      data = finalZCoeffs_[0] * finalZ_[0];     // Extra zero(s) for shape
      data += finalZCoeffs_[1] * finalZ_[1];    // Extra zero(s) for shape
      data += finalZCoeffs_[2] * finalZ_[2];    // Extra zero(s) for shape
      if (data > 10000.0)	data = 10000.0;
      if (data < -10000.0) data = -10000.0;
      lastOutput_ = data * 0.0001;
    }
    else lastOutput_ = 0.0;
  }

  return lastOutput_;
}