Ejemplo n.º 1
0
StkFloat Shakers :: ratchet_tick() {
  StkFloat data;
  if (my_random(1024) < nObjects_) {
    sndLevel_ += 512 * ratchet_ * totalEnergy_;
  }
  inputs_[0] = sndLevel_;
  inputs_[0] *= noise_tick() * ratchet_;
  sndLevel_ *= soundDecay_;
		 
  inputs_[1] = inputs_[0];
  inputs_[0] -= outputs_[0][0]*coeffs_[0][0];
  inputs_[0] -= outputs_[0][1]*coeffs_[0][1];
  outputs_[0][1] = outputs_[0][0];
  outputs_[0][0] = inputs_[0];
  inputs_[1] -= outputs_[1][0]*coeffs_[1][0];
  inputs_[1] -= outputs_[1][1]*coeffs_[1][1];
  outputs_[1][1] = outputs_[1][0];
  outputs_[1][0] = inputs_[1];
     
  finalZ_[2] = finalZ_[1];
  finalZ_[1] = finalZ_[0];
  finalZ_[0] = gains_[0]*outputs_[0][1] + gains_[1]*outputs_[1][1];
  data = finalZ_[0] - finalZ_[2];
  return data;
}
Ejemplo n.º 2
0
StkFloat Shakers :: tbamb_tick() {
  StkFloat data, temp;
  static int which = 0;
  int i;

  if (shakeEnergy_ > MIN_ENERGY)	{
      shakeEnergy_ *= systemDecay_;    // Exponential system decay
      if (float_random(1024.0) < nObjects_) {
	    sndLevel_ += shakeEnergy_;
	    which = my_random(7);
	  }  
      temp = sndLevel_ * noise_tick();      // Actual Sound is Random
	  for (i=0;i<nFreqs_;i++)	inputs_[i] = 0;
	  inputs_[which] = temp;
      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;
      data = data * 0.0001;
  }
  else data = 0.0;
  return data;
}
Ejemplo n.º 3
0
float guiro_tick(t_guiro *x) {
  float data;
  if (my_random(1024) < x->num_objects) {
    x->sndLevel += 512. * x->ratchet * x->totalEnergy;
  }
  x->input = x->sndLevel;
  x->input *= noise_tick() * x->ratchet;
  x->sndLevel *= x->soundDecay;
		 
  x->input2 = x->input;
  x->input -= x->output[0]*x->coeffs[0];
  x->input -= x->output[1]*x->coeffs[1];
  x->output[1] = x->output[0];
  x->output[0] = x->input;
  x->input2 -= x->output2[0]*x->coeffs2[0];
  x->input2 -= x->output2[1]*x->coeffs2[1];
  x->output2[1] = x->output2[0];
  x->output2[0] = x->input2;
     
  x->finalZ[2] = x->finalZ[1];
  x->finalZ[1] = x->finalZ[0];
  x->finalZ[0] = x->output[1] + x->output2[1];
  data = x->finalZ[0] - x->finalZ[2];
		
  return data;
}
Ejemplo n.º 4
0
float cabasa_tick(t_cabasa *x) {
  float data;
  x->shakeEnergy *= x->systemDecay;         	// Exponential system decay
  if (my_random(1024) < x->num_objects)  		// If collision
  	x->sndLevel += x->gain * x->shakeEnergy;   	//   add energy
  x->input = x->sndLevel * noise_tick();    	// Actual Sound is Random
  x->sndLevel *= x->soundDecay;             	// Exponential Sound decay 
  x->input -= x->output[0]*x->coeffs[0];       	// Do gourd
  x->input -= x->output[1]*x->coeffs[1];       	//   resonance
  x->output[1] = x->output[0];              	//     filter
  x->output[0] = x->input;                  	//       calculations
  data = x->output[0] - x->output[1];
		
  return data;
}
Ejemplo n.º 5
0
float wuter_tick(t_wuter *x) {
  float data;
  int j;
  if (my_random(32767) < (long)x->num_objects) {     
    x->sndLevel = x->shakeEnergy;
    x->pandropL = (float)rand()*RANDNORM;  
    x->pandropR = 1. - x->pandropL;
    x->pandropL = powf(x->pandropL, 0.5);
    x->pandropR = powf(x->pandropR, 0.5);
    
    j = my_random(3);
	  if (j == 0)   {
      x->freq = x->res_freq * (1. - x->res_spread + (x->res_random * noise_tick()));
	    x->gain = fabs(noise_tick());
	  }
	  else if (j == 1)      {
      x->freq1 = x->res_freq * (1.0 + (x->res_random * noise_tick()));
	   x->gain1 = fabs(noise_tick());
	  }
	  else  {
      x->freq2 = x->res_freq * (1. + 2.*x->res_spread + (2.*x->res_random * noise_tick()));
	    x->gain2 = fabs(noise_tick());
	  }
	}
	
  x->gain  *= WUTR_FILT_POLE;
  if (x->gain >  0.001) {
    x->freq  *= WUTR_FREQ_SWEEP;
    x->coeffs[0] = -WUTR_FILT_POLE * 2.0 * 
      cos(x->freq * TWO_PI / x->srate);
  }
  x->gain1 *= WUTR_FILT_POLE;
  if (x->gain1 > 0.001) {
    x->freq1 *= WUTR_FREQ_SWEEP;
    x->coeffs1[0] = -WUTR_FILT_POLE * 2.0 * 
      cos(x->freq1 * TWO_PI / x->srate);
  }
  x->gain2 *= WUTR_FILT_POLE;
  if (x->gain2 > 0.001) {
    x->freq2 *= WUTR_FREQ_SWEEP;
    x->coeffs2[0] = -WUTR_FILT_POLE * 2.0 * 
      cos(x->freq2 * TWO_PI / x->srate);
  }
	
  x->sndLevel *= x->soundDecay;        // Each (all) event(s) 
  // decay(s) exponentially 
  x->input = x->sndLevel;
  x->input *= noise_tick();         // Actual Sound is Random
  x->input1 = x->input * x->gain1;
  x->input2 = x->input * x->gain2;
  x->input *= x->gain;
  x->input -= x->output[0]*x->coeffs[0];
  x->input -= x->output[1]*x->coeffs[1];
  x->output[1] = x->output[0];
  x->output[0] = x->input;
  data = x->output[0];
  x->input1 -= x->output1[0]*x->coeffs1[0];
  x->input1 -= x->output1[1]*x->coeffs1[1];
  x->output1[1] = x->output1[0];
  x->output1[0] = x->input1;
  data += x->output1[0];
  x->input2 -= x->output2[0]*x->coeffs2[0];
  x->input2 -= x->output2[1]*x->coeffs2[1];
  x->output2[1] = x->output2[0];
  x->output2[0] = x->input2;
  data += x->output2[0];
 
  x->finalZ[2] = x->finalZ[1];
  x->finalZ[1] = x->finalZ[0];
  x->finalZ[0] = data * 4.;

  data = x->finalZ[2] - x->finalZ[0];
  return data;
}
Ejemplo n.º 6
0
StkFloat Shakers :: wuter_tick() {
  StkFloat data;
  int j;
  shakeEnergy_ *= systemDecay_;               // Exponential system decay
  if (my_random(32767) < nObjects_) {     
    sndLevel_ = shakeEnergy_;   
    j = my_random(3);
	  if (j == 0)   {
      center_freqs_[0] = WUTR_CENTER_FREQ1 * (0.75 + (0.25 * noise_tick()));
	    gains_[0] = fabs(noise_tick());
	  }
	  else if (j == 1)      {
      center_freqs_[1] = WUTR_CENTER_FREQ1 * (1.0 + (0.25 * noise_tick()));
	    gains_[1] = fabs(noise_tick());
	  }
	  else  {
      center_freqs_[2] = WUTR_CENTER_FREQ1 * (1.25 + (0.25 * noise_tick()));
	    gains_[2] = fabs(noise_tick());
	  }
	}
	
  gains_[0] *= resons_[0];
  if (gains_[0] >  0.001) {
    center_freqs_[0]  *= WUTR_FREQ_SWEEP;
    coeffs_[0][0] = -resons_[0] * 2.0 * 
      cos(center_freqs_[0] * TWO_PI / Stk::sampleRate());
  }
  gains_[1] *= resons_[1];
  if (gains_[1] > 0.001) {
    center_freqs_[1] *= WUTR_FREQ_SWEEP;
    coeffs_[1][0] = -resons_[1] * 2.0 * 
      cos(center_freqs_[1] * TWO_PI / Stk::sampleRate());
  }
  gains_[2] *= resons_[2];
  if (gains_[2] > 0.001) {
    center_freqs_[2] *= WUTR_FREQ_SWEEP;
    coeffs_[2][0] = -resons_[2] * 2.0 * 
      cos(center_freqs_[2] * TWO_PI / Stk::sampleRate());
  }
	
  sndLevel_ *= soundDecay_;        // Each (all) event(s) 
                                   // decay(s) exponentially 
  inputs_[0] = sndLevel_;
  inputs_[0] *= noise_tick();     // Actual Sound is Random
  inputs_[1] = inputs_[0] * gains_[1];
  inputs_[2] = inputs_[0] * gains_[2];
  inputs_[0] *= gains_[0];
  inputs_[0] -= outputs_[0][0]*coeffs_[0][0];
  inputs_[0] -= outputs_[0][1]*coeffs_[0][1];
  outputs_[0][1] = outputs_[0][0];
  outputs_[0][0] = inputs_[0];
  data = gains_[0]*outputs_[0][0];
  inputs_[1] -= outputs_[1][0]*coeffs_[1][0];
  inputs_[1] -= outputs_[1][1]*coeffs_[1][1];
  outputs_[1][1] = outputs_[1][0];
  outputs_[1][0] = inputs_[1];
  data += gains_[1]*outputs_[1][0];
  inputs_[2] -= outputs_[2][0]*coeffs_[2][0];
  inputs_[2] -= outputs_[2][1]*coeffs_[2][1];
  outputs_[2][1] = outputs_[2][0];
  outputs_[2][0] = inputs_[2];
  data += gains_[2]*outputs_[2][0];
 
  finalZ_[2] = finalZ_[1];
  finalZ_[1] = finalZ_[0];
  finalZ_[0] = data * 4;

  data = finalZ_[2] - finalZ_[0];
  return data;
}
Ejemplo n.º 7
0
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_;
}
Ejemplo n.º 8
0
int sp_drip_compute(sp_data *sp, sp_drip *p, SPFLOAT *trig, SPFLOAT *out)
{
    SPFLOAT data;
    SPFLOAT lastOutput;

    SPFLOAT tpidsr = 2.0 * M_PI / sp->sr;

    if(*trig) {
        sp_drip_init(sp, p, p->dettack);
    }
    if (p->num_tubes != 0.0 && p->num_tubes != p->num_objects) {
        p->num_objects = p->num_tubes;
        if (p->num_objects < 1.0) p->num_objects = 1.0;
    }
    if (p->freq != 0.0 && p->freq != p->res_freq0) {
        p->res_freq0 = p->freq;
        p->coeffs00 = -WUTR_RESON * 2.0 *
        cos(p->res_freq0 * tpidsr);
    }
    if (p->damp != 0.0 && p->damp != p->shake_damp) {
        p->shake_damp = p->damp;
        p->systemDecay = WUTR_SYSTEM_DECAY + (p->shake_damp * 0.002);
    }
    if (p->shake_max != 0.0 && p->shake_max != p->shake_maxSave) {
        p->shake_maxSave = p->shake_max;
        p->shakeEnergy += p->shake_maxSave * MAX_SHAKE * 0.1;
        if (p->shakeEnergy > MAX_SHAKE) p->shakeEnergy = MAX_SHAKE;
    }
    if (p->freq1 != 0.0 && p->freq1 != p->res_freq1) {
        p->res_freq1 = p->freq1;
        p->coeffs10 = -WUTR_RESON * 2.0 *
        cos(p->res_freq1 * tpidsr);
    }
    if (p->freq2 != 0.0 && p->freq2 != p->res_freq2) {
        p->res_freq2 = p->freq2;
        p->coeffs20 = -WUTR_RESON * 2.0 *
        cos(p->res_freq2 * tpidsr);
    }
    if ((--p->kloop) == 0) {
        p->shakeEnergy = 0.0;
    }

    SPFLOAT shakeEnergy = p->shakeEnergy;
    SPFLOAT systemDecay = p->systemDecay;
    SPFLOAT sndLevel = p->sndLevel;
    SPFLOAT num_objects = p->num_objects;
    SPFLOAT soundDecay = p->soundDecay;
    SPFLOAT inputs0, inputs1, inputs2;

    shakeEnergy *= systemDecay; /* Exponential system decay */

    sndLevel = shakeEnergy;
    if (my_random(sp, 32767) < num_objects) {
        int j;
        j = my_random(sp, 3);
        if (j == 0) {
            p->center_freqs0 = p->res_freq1 *
            (0.75 + (0.25 * noise_tick(sp)));
            p->gains0 = fabs(noise_tick(sp));
        } else if (j == 1) {
            p->center_freqs1 = p->res_freq1 *
            (1.0 + (0.25 * noise_tick(sp)));
            p->gains1 = fabs(noise_tick(sp));
        } else  {
            p->center_freqs2 = p->res_freq1 *
            (1.25 + (0.25 * noise_tick(sp)));
            p->gains2 = fabs(noise_tick(sp));
        }
    }

    p->gains0 *= WUTR_RESON;
    if (p->gains0 > 0.001) {
        p->center_freqs0  *= WUTR_FREQ_SWEEP;
        p->coeffs00 = -WUTR_RESON * 2.0 *
        cos(p->center_freqs0 * tpidsr);
    }
    p->gains1 *= WUTR_RESON;
    if (p->gains1 > 0.00) {
        p->center_freqs1 *= WUTR_FREQ_SWEEP;
        p->coeffs10 = -WUTR_RESON * 2.0 *
        cos(p->center_freqs1 * tpidsr);
    }
    p->gains2 *= WUTR_RESON;
    if (p->gains2 > 0.001) {
        p->center_freqs2 *= WUTR_FREQ_SWEEP;
        p->coeffs20 = -WUTR_RESON * 2.0 *
        cos(p->center_freqs2 * tpidsr);
    }

    sndLevel *= soundDecay;
    inputs0 = sndLevel;
    inputs0 *= noise_tick(sp);
    inputs1 = inputs0 * p->gains1;
    inputs2 = inputs0 * p->gains2;
    inputs0 *= p->gains0;
    inputs0 -= p->outputs00*p->coeffs00;
    inputs0 -= p->outputs01*p->coeffs01;
    p->outputs01 = p->outputs00;
    p->outputs00 = inputs0;
    data = p->gains0*p->outputs00;
    inputs1 -= p->outputs10*p->coeffs10;
    inputs1 -= p->outputs11*p->coeffs11;
    p->outputs11 = p->outputs10;
    p->outputs10 = inputs1;
    data += p->gains1*p->outputs10;
    inputs2-= p->outputs20*p->coeffs20;
    inputs2 -= p->outputs21*p->coeffs21;
    p->outputs21 = p->outputs20;
    p->outputs20 = inputs2;
    data += p->gains2*p->outputs20;

    p->finalZ2 = p->finalZ1;
    p->finalZ1 = p->finalZ0;
    p->finalZ0 = data * 4.0;

    lastOutput = p->finalZ2 - p->finalZ0;
    lastOutput *= 0.005;
    *out = lastOutput;
    p->shakeEnergy = shakeEnergy;
    p->sndLevel = sndLevel;
    return SP_OK;
}
Ejemplo n.º 9
0
static int wuter(CSOUND *csound, WUTER *p)
{
    MYFLT *ar = p->ar;
    uint32_t offset = p->h.insdshead->ksmps_offset;
    uint32_t early  = p->h.insdshead->ksmps_no_end;
    uint32_t n, nsmps = CS_KSMPS;
    MYFLT data;
    MYFLT lastOutput;

    if (*p->num_tubes != FL(0.0) && *p->num_tubes != p->num_objects) {
      p->num_objects = *p->num_tubes;
      if (p->num_objects < FL(1.0)) p->num_objects = FL(1.0);
    }
    if (*p->freq != FL(0.0) && *p->freq != p->res_freq0) {
      p->res_freq0 = *p->freq;
      p->coeffs00 = -WUTR_RESON * FL(2.0) *
        COS(p->res_freq0 * csound->tpidsr);
    }
    if (*p->damp != FL(0.0) && *p->damp != p->shake_damp) {
      p->shake_damp = *p->damp;
      p->systemDecay = WUTR_SYSTEM_DECAY + (p->shake_damp * FL(0.002));
    }
    if (*p->shake_max != FL(0.0) && *p->shake_max != p->shake_maxSave) {
      p->shake_maxSave = *p->shake_max;
      p->shakeEnergy += p->shake_maxSave * MAX_SHAKE * FL(0.1);
      if (p->shakeEnergy > MAX_SHAKE) p->shakeEnergy = MAX_SHAKE;
    }
    if (*p->freq1 != FL(0.0) && *p->freq1 != p->res_freq1) {
      p->res_freq1 = *p->freq1;
      p->coeffs10 = -WUTR_RESON * FL(2.0) *
        COS(p->res_freq1 * csound->tpidsr);
    }
    if (*p->freq2 != FL(0.0) && *p->freq2 != p->res_freq2) {
      p->res_freq2 = *p->freq2;
      p->coeffs20 = -WUTR_RESON * FL(2.0) *
        COS(p->res_freq2 * csound->tpidsr);
    }
    //if (p->kloop>0 && p->h.insdshead->relesing) p->kloop=1;
    if ((--p->kloop) == 0) {
      p->shakeEnergy = FL(0.0);
    }

    {
      MYFLT shakeEnergy = p->shakeEnergy;
      MYFLT systemDecay = p->systemDecay;
      MYFLT sndLevel = p->sndLevel;
      MYFLT num_objects = p->num_objects;
      MYFLT soundDecay = p->soundDecay;
      MYFLT inputs0, inputs1, inputs2;

      if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT));
      if (UNLIKELY(early)) {
        nsmps -= early;
        memset(&ar[nsmps], '\0', early*sizeof(MYFLT));
      }
      for (n=offset;n<nsmps;n++) {

        shakeEnergy *= systemDecay;               /* Exponential system decay */
        if (my_random(csound, 32767) < num_objects) {
          int j;
          sndLevel = shakeEnergy;
          j = my_random(csound, 3);
          /* ******** Stange that there is no use of freq0 and freq2  */
          if (j == 0)   {
            p->center_freqs0 = p->res_freq1 *
              (FL(0.75) + (FL(0.25) * noise_tick(csound)));
            p->gains0 = FABS(noise_tick(csound));
          }
          else if (j == 1)      {
            p->center_freqs1 = p->res_freq1 *
              (FL(1.0) + (FL(0.25) * noise_tick(csound)));
            p->gains1 = FABS(noise_tick(csound));
          }
          else  {
            p->center_freqs2 = p->res_freq1 *
              (FL(1.25) + (FL(0.25) * noise_tick(csound)));
            p->gains2 = FABS(noise_tick(csound));
          }
        }

        p->gains0 *= WUTR_RESON;
        if (p->gains0 >  FL(0.001)) {
          p->center_freqs0  *= WUTR_FREQ_SWEEP;
          p->coeffs00 = -WUTR_RESON * FL(2.0) *
            COS(p->center_freqs0 * csound->tpidsr);
        }
        p->gains1 *= WUTR_RESON;
        if (p->gains1 > FL(0.001)) {
          p->center_freqs1 *= WUTR_FREQ_SWEEP;
          p->coeffs10 = -WUTR_RESON * FL(2.0) *
            COS(p->center_freqs1 * csound->tpidsr);
        }
        p->gains2 *= WUTR_RESON;
        if (p->gains2 > FL(0.001)) {
          p->center_freqs2 *= WUTR_FREQ_SWEEP;
          p->coeffs20 = -WUTR_RESON * FL(2.0) *
            COS(p->center_freqs2 * csound->tpidsr);
        }

        sndLevel    *= soundDecay;          /* Each (all) event(s)  */
        /* decay(s) exponentially  */
        inputs0      = sndLevel;
        inputs0     *= noise_tick(csound);  /* Actual Sound is Random */
        inputs1      = inputs0 * p->gains1;
        inputs2      = inputs0 * p->gains2;
        inputs0     *= p->gains0;
        inputs0     -= p->outputs00*p->coeffs00;
        inputs0     -= p->outputs01*p->coeffs01;
        p->outputs01 = p->outputs00;
        p->outputs00 = inputs0;
        data         = p->gains0*p->outputs00;
        inputs1     -= p->outputs10*p->coeffs10;
        inputs1     -= p->outputs11*p->coeffs11;
        p->outputs11 = p->outputs10;
        p->outputs10 = inputs1;
        data        += p->gains1*p->outputs10;
        inputs2     -= p->outputs20*p->coeffs20;
        inputs2     -= p->outputs21*p->coeffs21;
        p->outputs21 = p->outputs20;
        p->outputs20 = inputs2;
        data        += p->gains2*p->outputs20;

        p->finalZ2   = p->finalZ1;
        p->finalZ1   = p->finalZ0;
        p->finalZ0   = data * FL(4.0);

        lastOutput   = p->finalZ2 - p->finalZ0;
        lastOutput  *= FL(0.005);
        ar[n]        = lastOutput*csound->e0dbfs;
      }
      p->shakeEnergy = shakeEnergy;
      p->sndLevel = sndLevel;
    }
    return OK;
}
Ejemplo n.º 10
0
static int bamboo(CSOUND *csound, BAMBOO *p)
{
    MYFLT *ar = p->ar;
    uint32_t offset = p->h.insdshead->ksmps_offset;
    uint32_t early  = p->h.insdshead->ksmps_no_end;
    uint32_t n, nsmps = CS_KSMPS;
    MYFLT data;
    MYFLT temp_rand;
    MYFLT lastOutput;

    if (*p->num_tubes != FL(0.0) && *p->num_tubes != p->num_objects) {
      p->num_objects = *p->num_tubes;
      if (p->num_objects < FL(1.0)) p->num_objects = FL(1.0);
    }
    if (*p->freq != FL(0.0) && *p->freq != p->res_freq0) {
      p->res_freq0 = *p->freq;
      p->coeffs00 = -BAMB_RESON * FL(2.0) *
        COS(p->res_freq0 * csound->tpidsr);
    }
    if (*p->damp != FL(0.0) && *p->damp != p->shake_damp) {
      p->shake_damp = *p->damp;
      p->systemDecay = BAMB_SYSTEM_DECAY + (p->shake_damp * FL(0.002));
    }
    if (*p->shake_max != FL(0.0) && *p->shake_max != p->shake_maxSave) {
      p->shake_maxSave = *p->shake_max;
      p->shakeEnergy += p->shake_maxSave * MAX_SHAKE * FL(0.1);
      if (p->shakeEnergy > MAX_SHAKE) p->shakeEnergy = MAX_SHAKE;
    }
    if (*p->freq1 != FL(0.0) && *p->freq1 != p->res_freq1) {
      p->res_freq1 = *p->freq1;
      p->coeffs10 = -BAMB_RESON * FL(2.0) *
        COS(p->res_freq1 * csound->tpidsr);
    }
    if (*p->freq2 != FL(0.0) && *p->freq2 != p->res_freq2) {
      p->res_freq2 = *p->freq2;
      p->coeffs20 = -BAMB_RESON * FL(2.0) *
        COS(p->res_freq2 * csound->tpidsr);
    }
    if (p->kloop>0 && p->h.insdshead->relesing) p->kloop=1;
    if ((--p->kloop) == 0) {
      p->shakeEnergy = FL(0.0);
    }

    {
      MYFLT shakeEnergy = p->shakeEnergy;
      MYFLT systemDecay = p->systemDecay;
      MYFLT sndLevel    = p->sndLevel;
      MYFLT soundDecay  = p->soundDecay;
      MYFLT inputs0, inputs1, inputs2;
      if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT));
      if (UNLIKELY(early)) {
        nsmps -= early;
        memset(&ar[nsmps], '\0', early*sizeof(MYFLT));
      }
      for (n=offset;n<nsmps;n++) {
        shakeEnergy *= systemDecay; /* Exponential system decay */
        if (my_random(csound, 1024) < p->num_objects) {
          sndLevel += shakeEnergy;
          temp_rand = p->res_freq0 * (FL(1.0) + (FL(0.2) * noise_tick(csound)));
          p->coeffs00 = -BAMB_RESON * FL(2.0) *
            COS(temp_rand * csound->tpidsr);
          temp_rand = p->res_freq1 * (FL(1.0) +
                                      (FL(0.2) * noise_tick(csound)));
          p->coeffs10 = -BAMB_RESON * FL(2.0) *
            COS(temp_rand * csound->tpidsr);
          temp_rand = p->res_freq2 * (FL(1.0) +
                                      (FL(0.2) * noise_tick(csound)));
          p->coeffs20 = -BAMB_RESON * FL(2.0) *
            COS(temp_rand * csound->tpidsr);
        }
        inputs0 = sndLevel * noise_tick(csound); /* Actual Sound is Random */
        inputs1      = inputs0;
        inputs2      = inputs0;
        sndLevel    *= soundDecay;               /* Exponential Sound decay  */
        inputs0     -= p->outputs00*p->coeffs00; /* Do */
        inputs0     -= p->outputs01*p->coeffs01; /* resonant */
        p->outputs01 = p->outputs00;             /* filter */
        p->outputs00 = inputs0;                  /* calculations */
        data         = p->gain * p->outputs01;
        inputs1     -= p->outputs10*p->coeffs10; /* Do */
        inputs1     -= p->outputs11*p->coeffs11; /* resonant */
        p->outputs11 = p->outputs10;             /* filter */
        p->outputs10 = inputs1;                  /* calculations */
        data        += p->gain * p->outputs11;
        inputs2     -= p->outputs20*p->coeffs20; /* Do */
        inputs2     -= p->outputs21*p->coeffs21; /* resonant */
        p->outputs21 = p->outputs20;             /* filter */
        p->outputs20 = inputs2;                  /* calculations */
        data        += p->gain * p->outputs21;
/*            if (data > 10000.0f)      data = 10000.0f; */
/*            if (data < -10000.0f) data = -10000.0f; */
        lastOutput   = data * FL(0.00051);
        ar[n]        = lastOutput*csound->e0dbfs;
      }
      p->shakeEnergy = shakeEnergy;
      p->sndLevel    = sndLevel;
    }
    return OK;
}
Ejemplo n.º 11
0
static int guiro(CSOUND *csound, GUIRO *p)
{
    MYFLT *ar = p->ar;
    uint32_t offset = p->h.insdshead->ksmps_offset;
    uint32_t early  = p->h.insdshead->ksmps_no_end;
    uint32_t n, nsmps = CS_KSMPS;
    MYFLT lastOutput;

    if (*p->num_teeth != FL(0.0) &&
        (int32)(*p->num_teeth+FL(0.5)) != p->num_objects) {
      p->num_objects = *p->num_teeth;
      if (p->num_objects < FL(1.0)) p->num_objects = FL(1.0);
      p->gains0 = p->gains1 = LOG((MYFLT)p->num_objects) * GUIR_GAIN /
        (MYFLT) p->num_objects;
    }

    if (*p->damp != FL(0.0) && *p->damp != p->shake_damp) {
      p->shake_damp = *p->damp;
/*        p->systemDecay = TAMB_SYSTEM_DECAY + (p->shake_damp * FL(0.002)); */
/*        p->scrapeVel = p->shake_damp; */
    }
    if (*p->shake_max != FL(0.0) && *p->shake_max != p->shake_maxSave) {
      p->shake_maxSave = *p->shake_max;
      p->shakeEnergy += p->shake_maxSave * MAX_SHAKE * FL(0.1);
      if (p->shakeEnergy > MAX_SHAKE) p->shakeEnergy = MAX_SHAKE;
    }
    if (*p->freq != FL(0.0) && *p->freq !=  p->res_freqSave) {
      p->res_freqSave = *p->freq;
      p->coeffs00 = -GUIR_GOURD_RESON * FL(2.0) *
        COS(p->res_freqSave * csound->tpidsr);
    }
    if (*p->freq2 != p->res_freq2) {
      p->res_freq2 = *p->freq2;
      p->coeffs10 = -GUIR_GOURD_RESON2 * FL(2.0) *
        COS(p->res_freq2 * csound->tpidsr);
    }
    if (p->kloop>0 && p->h.insdshead->relesing) p->kloop=1;
    if ((--p->kloop) == 0) {
      p->shakeEnergy = FL(0.0);
      p->ratchetPos = 0;
    }

    {
      MYFLT sndLevel     = p->sndLevel;
      MYFLT ratchet      = p->ratchet;
      int ratchetPos     = p->ratchetPos;
      MYFLT totalEnergy  = p->totalEnergy;
      MYFLT num_objects  = p->num_objects;
      MYFLT soundDecay   = p->soundDecay;
      MYFLT ratchetDelta = p->ratchetDelta;
      MYFLT inputs0, inputs1;
      MYFLT outputs00    = p->outputs00;
      MYFLT outputs01    = p->outputs01;
      MYFLT outputs10    = p->outputs10;
      MYFLT outputs11    = p->outputs11;
      MYFLT coeffs00     = p->coeffs00;
      MYFLT coeffs01     = p->coeffs01;
      MYFLT coeffs10     = p->coeffs10;
      MYFLT coeffs11     = p->coeffs11;
      MYFLT finalZ0      = p->finalZ0;
      MYFLT finalZ1      = p->finalZ1;
      MYFLT finalZ2      = p->finalZ2;
      MYFLT gains0       = p->gains0;
      MYFLT gains1       = p->gains1;
      MYFLT amp          = *p->amp;
      if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT));
      if (UNLIKELY(early)) {
        nsmps -= early;
        memset(&ar[nsmps], '\0', early*sizeof(MYFLT));
      }
      for (n=offset;n<nsmps;n++) {
        if (ratchetPos > 0) {
          ratchet -= (ratchetDelta + (FL(0.002)*totalEnergy));
          if (ratchet < FL(0.0)) {
            ratchet = FL(1.0);
            ratchetPos -= 1;
          }
          totalEnergy = ratchet;
          if (my_random(csound, 1024) < num_objects) {
            sndLevel += FL(512.0) * ratchet * totalEnergy;
          }
          inputs0     = sndLevel;
          inputs0    *= noise_tick(csound) * ratchet;
          sndLevel   *= soundDecay;

          inputs1     = inputs0;
          inputs0    -= outputs00*coeffs00;
          inputs0    -= outputs01*coeffs01;
          outputs01   = outputs00;
          outputs00   = inputs0;
          inputs1    -= outputs10*coeffs10;
          inputs1    -= outputs11*coeffs11;
          outputs11   = outputs10;
          outputs10   = inputs1;

          finalZ2     = finalZ1;
          finalZ1     = finalZ0;
          finalZ0     = gains0*outputs01 + gains1*outputs11;
          lastOutput  = finalZ0 - finalZ2;
          lastOutput *= FL(0.0001);
        }
        else
          lastOutput = FL(0.0);
        ar[n] = FL(1.33)*lastOutput*amp;
      }
      p->sndLevel    = sndLevel;
      p->ratchet     = ratchet;
      p->ratchetPos  = ratchetPos;
      p->totalEnergy = totalEnergy;
      p->outputs00   = outputs00;
      p->outputs01   = outputs01;
      p->outputs10   = outputs10;
      p->outputs11   = outputs11;
      p->finalZ0     = finalZ0;
      p->finalZ1     = finalZ1;
      p->finalZ2     = finalZ2;

  }
    return OK;
}
Ejemplo n.º 12
0
static int sekere(CSOUND *csound, SEKERE *p)
{
    MYFLT *ar = p->ar;
    uint32_t offset = p->h.insdshead->ksmps_offset;
    uint32_t early  = p->h.insdshead->ksmps_no_end;
    uint32_t n, nsmps = CS_KSMPS;
    MYFLT data;
                                /* Use locals for speed */
    MYFLT shakeEnergy = p->shakeEnergy;
    MYFLT systemDecay = p->systemDecay;
    MYFLT sndLevel = p->sndLevel;
    MYFLT soundDecay = p->soundDecay;
    MYFLT input;
    MYFLT outputs0 = p->outputs0;
    MYFLT outputs1 = p->outputs1;
    MYFLT coeff0   = p->coeffs0;
    MYFLT coeff1   = p->coeffs1;
    MYFLT gain     = p->gain;

    if (*p->num_beads != p->last_num) {
      p->last_num = *p->num_beads;
      if ((int32)(*p->num_beads+FL(0.5)) != p->num_objects) {
        p->num_objects = *p->num_beads;
        if (p->num_objects >= 1) {
          gain = p->gain = LOG((MYFLT)p->num_objects) /
            FL(1.38629436111989061883) /* (MYFLT)log(4.0)*/ * FL(120.0) /
            (MYFLT) p->num_objects;
        }
      }
    }

    if (*p->damp != FL(0.0)) {
      systemDecay = p->systemDecay = FL(0.998) + (*p->damp * FL(0.002));
    }

    if (*p->shake_max != FL(0.0)) {
      shakeEnergy = p->shakeEnergy +=
        CS_KSMPS * *p->shake_max * MAX_SHAKE * FL(0.1);
      if (shakeEnergy > MAX_SHAKE) shakeEnergy = MAX_SHAKE;
    }

    if (p->kloop>0 && p->h.insdshead->relesing) p->kloop=1;
    if ((--p->kloop) == 0) {
      shakeEnergy = FL(0.0);
    }

    if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT));
    if (UNLIKELY(early)) {
      nsmps -= early;
      memset(&ar[nsmps], '\0', early*sizeof(MYFLT));
    }
    for (n=offset;n<nsmps;n++) {
/*        if (shakeEnergy > MIN_ENERGY) { */
      shakeEnergy *= systemDecay;           /* Exponential system decay */
      if (my_random(csound, 1024) < p->num_objects) {
        sndLevel += gain * shakeEnergy;
      }
      input = sndLevel * noise_tick(csound);  /* Actual Sound is Random */
      sndLevel *= soundDecay;               /* Exponential Sound decay  */
      input -= outputs0*coeff0;             /* Do */
      input -= outputs1*coeff1;             /* resonant */
      outputs1 = outputs0;                  /* filter */
      outputs0 = input;                     /* calculations */
      p->finalZ2 = p->finalZ1;
      p->finalZ1 = p->finalZ0;
      p->finalZ0 = p->outputs1;
      data = p->finalZ0 - p->finalZ2;
/*          if (data > 10000.0f)        data = 10000.0f; */
/*          if (data < -10000.0f) data = -10000.0f; */
      ar[n] = data * FL(0.0005) * csound->e0dbfs ;
/*        } */
/*        else { */
/*          ar[n] = 0.0f; */
/*        } */
    }
    printf("%d/%d:\n", offset, early);
    p->shakeEnergy = shakeEnergy;
    p->sndLevel = sndLevel;
    p->outputs0 = outputs0;
    p->outputs1 = outputs1;
    return OK;
}