Esempio n. 1
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;
}
Esempio n. 2
0
void test(int nb_cnst, int nb_var, int nb_elem)
{
  lmm_system_t Sys = NULL;
  lmm_constraint_t *cnst = xbt_new0(lmm_constraint_t, nb_cnst);
  lmm_variable_t *var = xbt_new0(lmm_variable_t, nb_var);
  int *used = xbt_new0(int, nb_cnst);
  int i, j, k;

  Sys = lmm_system_new(1);

  for (i = 0; i < nb_cnst; i++) {
    cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0));
  }

  for (i = 0; i < nb_var; i++) {
    var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem);
    for (j = 0; j < nb_cnst; j++)
      used[j] = 0;
    for (j = 0; j < nb_elem; j++) {
      k = int_random(nb_cnst);
      if (used[k]) {
        j--;
        continue;
      }
      lmm_expand(Sys, cnst[k], var[i], float_random(1.0));
      used[k] = 1;
    }
  }

  printf("Starting to solve\n");
  date = xbt_os_time() * 1000000;
  lmm_solve(Sys);
  date = xbt_os_time() * 1000000 - date;

  for (i = 0; i < nb_var; i++)
    lmm_variable_free(Sys, var[i]);
  lmm_system_free(Sys);
  free(cnst);
  free(var);
  free(used);
}
Esempio n. 3
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_;
}
Esempio n. 4
0
static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limit, unsigned int pw_max_limit,
                 float rate_no_limit, int max_share, int mode)
{
  lmm_system_t Sys = NULL;
  lmm_constraint_t *cnst = xbt_new0(lmm_constraint_t, nb_cnst);
  lmm_variable_t *var = xbt_new0(lmm_variable_t, nb_var);
  int *used = xbt_new0(int, nb_cnst);
  int i;
  int j;
  int k;
  int l;
  int concurrency_share;

  Sys = lmm_system_new(1);

  for (i = 0; i < nb_cnst; i++) {
    cnst[i] = lmm_constraint_new(Sys, NULL, float_random(10.0));
    if(rate_no_limit>float_random(1.0))
      //Look at what happens when there is no concurrency limit 
      l=-1;
    else
      //Badly logarithmically random concurrency limit in [2^pw_base_limit+1,2^pw_base_limit+2^pw_max_limit]
      l=(1<<pw_base_limit)+(1<<int_random(pw_max_limit));

    lmm_constraint_concurrency_limit_set(cnst[i],l );
  }

  for (i = 0; i < nb_var; i++) {
    var[i] = lmm_variable_new(Sys, NULL, 1.0, -1.0, nb_elem);
    //Have a few variables with a concurrency share of two (e.g. cross-traffic in some cases)
    concurrency_share=1+int_random(max_share);
    lmm_variable_concurrency_share_set(var[i],concurrency_share);

    for (j = 0; j < nb_cnst; j++)
      used[j] = 0;
    for (j = 0; j < nb_elem; j++) {
      k = int_random(nb_cnst);
      if (used[k]>=concurrency_share) {
        j--;
        continue;
      }
      lmm_expand(Sys, cnst[k], var[i], float_random(1.5));
      lmm_expand_add(Sys, cnst[k], var[i], float_random(1.5));
      used[k]++;
    }
  }

  fprintf(stderr,"Starting to solve(%i)\n",myrand()%1000);
  date = xbt_os_time() * 1000000;
  lmm_solve(Sys);
  date = xbt_os_time() * 1000000 - date;

  if(mode==2){
    fprintf(stderr,"Max concurrency:\n");
    l=0;
    for (i = 0; i < nb_cnst; i++) {
      j=lmm_constraint_concurrency_maximum_get(cnst[i]);
      k=lmm_constraint_concurrency_limit_get(cnst[i]);
      xbt_assert(k<0 || j<=k);
      if(j>l)
        l=j;
      fprintf(stderr,"(%i):%i/%i ",i,j,k);
      lmm_constraint_concurrency_maximum_reset(cnst[i]);
      xbt_assert(!lmm_constraint_concurrency_maximum_get(cnst[i]));
      if(i%10==9)
        fprintf(stderr,"\n");
    }
    fprintf(stderr,"\nTotal maximum concurrency is %i\n",l);

    lmm_print(Sys);
  }

  for (i = 0; i < nb_var; i++)
    lmm_variable_free(Sys, var[i]);
  lmm_system_free(Sys);
  free(cnst);
  free(var);
  free(used);
}