コード例 #1
0
ファイル: isal.c プロジェクト: gunnarrb/isal
void create_machine_fail_events() {
    int i;
    float a[20],shift_length;
    shift_length = (float)SHIFT_LENGTH;
    int n = failure_nr;
    memset(a,0,20*sizeof(float));
    float span = shift_length / (float)n+1.0;  //max time between machine failures
    float current_span = 0.0;
    int machine;
    float repair_time ;
    float breakdown_time;
	
    for (i = 0;i<n;i++) {

	current_span+=span;
	machine = (int)unirand(1,number_of_machines+1,stream);
	breakdown_time = unirand(0.0,current_span,stream);
	repair_time =(min_machine_repair_time + expon(max_machine_repair_time ,stream))*60.0;
	if (a[machine]<breakdown_time) {  // 
	    a[machine] = breakdown_time+repair_time;
	}
	else { // if breakdown_time clashes with the same machine then let the breakdown happen after the machine goes up again
	    breakdown_time = a[machine] + 1.0;
	    a[machine] = breakdown_time+repair_time;
	}
	transfer[3] = repair_time;
	transfer[4] = (float)machine;
	fail_list[machine-1].downtime+= repair_time;
	fail_list[machine-1].machine_nr++; 
	event_schedule(sim_time + breakdown_time, EVENT_MACHINE_FAILURE );
    }
	
    event_schedule(sim_time + shift_length, EVENT_GENERATE_FAILURES );
}
コード例 #2
0
ファイル: isal.c プロジェクト: gunnarrb/isal
void wagen_unload_arrival()
{
	
    int i;
    int current_unit = 0;
    float wagen_arrival_zeit = unirand((mean_wagen_arrival-std_wagen_arrival)*60.0,(mean_wagen_arrival+std_wagen_arrival)*60.0,stream); 
	
    for (i = 1; i<NUM_MACHINES+1; i++) {  //delay unload of skaut by the time it takes to repair
	if (machine_broken[i] > 0.0) {
	    event_schedule(sim_time + machine_broken[i], EVENT_WAGEN_UNLOAD_ARRIVAL);
	    return;
	}
    }
	
    if (list_size[number_of_machines + 1] != 0) { // ef allt er enn fullt þá koma með næsta vagn eftir uþb hálftíma
	event_schedule(sim_time + wagen_arrival_zeit, EVENT_WAGEN_UNLOAD_ARRIVAL);
	return;
    }
    
    int vagn_magn =  WAGEN_LOAD-((int)unirand(0.0,3.0,stream));  //12 - 14 skaut á hverjum vagni
    for (i=1; i <= vagn_magn; i++) {
		
	transfer[3]=1.0;
	transfer[4] = sim_time + (i * 0.01); // skaut entering system time
	transfer[6] = (float) skaut_id++;
	//printf("tr4 in wagen: %f\n", transfer[4]);
	event_schedule( sim_time + ( i* 0.01),	EVENT_SKAUT_ARRIVAL);
    }
	
    event_schedule(sim_time+wagen_arrival_zeit, EVENT_WAGEN_UNLOAD_ARRIVAL);
}
コード例 #3
0
// Generate random normal number by Box-Muller transform
double normalrand(__private int* seed)
{
	double u = unirand(seed);
	double v = unirand(seed);

	return sqrt(-2.0*log(u))*cos(2.0*pi*v);
	//return 1.0;
}
コード例 #4
0
ファイル: sndwarp.c プロジェクト: BlakeJarvis/csound
static int sndwarpstgetset(CSOUND *csound, SNDWARPST *p)
{
    int         i;
    int         nsections;
    FUNC        *ftpWind, *ftpSamp;
    WARPSECTION *exp;
    char        *auxp;
    MYFLT       iwsize;

    if (UNLIKELY(p->OUTOCOUNT > 2 && p->OUTOCOUNT < 4)) {
      return csound->InitError(csound, Str("Wrong number of outputs "
                                           "in sndwarpst; must be 2 or 4"));
    }
    nsections = (int)*p->ioverlap;
    if ((auxp = p->auxch.auxp) == NULL || nsections != p->nsections) {
      if (nsections != p->nsections)
        auxp=p->auxch.auxp=NULL;
      csound->AuxAlloc(csound, (size_t)nsections*sizeof(WARPSECTION), &p->auxch);
      auxp = p->auxch.auxp;
      p->nsections = nsections;
    }
    p->exp = (WARPSECTION *)auxp;

    if (UNLIKELY((ftpSamp = csound->FTnp2Find(csound, p->isampfun)) == NULL))
      return NOTOK;
    p->ftpSamp = ftpSamp;
    p->sampflen=ftpSamp->flen;

    if (UNLIKELY((ftpWind = csound->FTnp2Find(csound, p->ifn)) == NULL))
      return NOTOK;
    p->ftpWind = ftpWind;
    p->flen=ftpWind->flen;

    p->maxFr  = -1L + (int32)(ftpSamp->flen*FL(0.5));
    p->prFlg = 1;    /* true */
    p->begin = (int)(*p->ibegin * CS_ESR);
    iwsize = *p->iwsize;
    exp = p->exp;
    for (i=0; i< nsections; i++) {
      if (i==0) {
        exp[i].wsize = (int)iwsize;
        exp[i].cnt=0;
        exp[i].ampphs = FL(0.0);
      }
      else {
        exp[i].wsize = (int) (iwsize + (unirand(csound) * (*p->irandw)));
        exp[i].cnt=(int)(exp[i].wsize*((MYFLT)i/(*p->ioverlap)));
        exp[i].ampphs = p->flen*(i/(*p->ioverlap));
      }
      exp[i].offset = (MYFLT)p->begin;
      exp[i].ampincr = (MYFLT)p->flen/(exp[i].wsize-1);
      /* exp[i].section = i+1;  *//* section number just used for debugging! */

    }
    p->ampcode = IS_ASIG_ARG(p->xamp) ? 1 : 0;
    p->timewarpcode = IS_ASIG_ARG(p->xtimewarp) ? 1 : 0;
    p->resamplecode = IS_ASIG_ARG(p->xresample) ? 1 : 0;
    return OK;
}
コード例 #5
0
int PentatonicComposer::nextDuration() {
  int duration = 250;
  
  switch(_whichNoise) {
    case WHITENOISE:
      duration *= unirand(1, 4, &_rand_ctx);
      break;
    case PINKNOISE:
      duration *= pinkint(1, 4, &_duration_pink);
      break;
    case PINKNOISE_2:
      duration *= pinkint2(1, 4, &_duration_pink);
      break;
  }
  
  return duration;
}
コード例 #6
0
byte PentatonicComposer::nextPitch() {
  byte pos;
  
  switch(_whichNoise) {
    case WHITENOISE:
      pos = unirand(0, _scaleLen - 1, &_rand_ctx);
      break;
    case PINKNOISE:
      pos = pinkint(0, _scaleLen - 1, &_pitch_pink);
      break;
    case PINKNOISE_2:
      pos = pinkint2(0, _scaleLen - 1, &_pitch_pink);
      break;
  }
  
  return pos;
}
コード例 #7
0
ファイル: sndwarp.c プロジェクト: BlakeJarvis/csound
static int sndwarp(CSOUND *csound, SNDWARP *p)
{
    uint32_t offset = p->h.insdshead->ksmps_offset;
    uint32_t early  = p->h.insdshead->ksmps_no_end;
    uint32_t n, nsmps = CS_KSMPS;
    MYFLT       frm_0,frm_1;
    int32       base, longphase;
    MYFLT       frac, frIndx;
    MYFLT       *r1, *r2, *amp, *timewarpby, *resample;
    WARPSECTION *exp;
    FUNC        *ftpWind, *ftpSamp;
    int         i;
    MYFLT       v1, v2, windowamp, fract;
    MYFLT       flen = (MYFLT)p->flen;
    MYFLT       iwsize = *p->iwsize;
    int         overlap = *p->ioverlap;

    if (UNLIKELY(p->auxch.auxp==NULL)) goto err1;
    r1 = p->r1;
    r2 = p->r2;
    memset(r1, 0, nsmps*sizeof(MYFLT));
    if (p->OUTOCOUNT >1) memset(r2, 0, nsmps*sizeof(MYFLT));
/*     for (i=0; i<nsmps; i++) { */
/*       *r1++ = FL(0.0); */
/*       if (p->OUTOCOUNT >1) *r2++ = FL(0.0); */
/*     } */
    exp = p->exp;
    ftpWind = p->ftpWind;
    ftpSamp = p->ftpSamp;

    for (i=0; i<overlap; i++) {
/*       nsmps = CS_KSMPS; */
/*       r1 = p->r1; */
/*       if (p->OUTOCOUNT >1)  r2 = p->r2; */
      resample = p->xresample;
      timewarpby = p->xtimewarp;
      amp = p->xamp;

      if (UNLIKELY(offset)) {
        memset(r1, '\0', offset*sizeof(MYFLT));
        if (p->OUTOCOUNT >1) memset(r2, '\0', offset*sizeof(MYFLT));
      }
     if (UNLIKELY(early)) {
      nsmps -= early;
      memset(&r1[nsmps], '\0', early*sizeof(MYFLT));
      if (p->OUTOCOUNT >1) memset(&r2[nsmps], '\0', early*sizeof(MYFLT));
     }
     for (n=offset; n<nsmps;n++) {
        if (exp[i].cnt < exp[i].wsize) goto skipover;

        if (*p->itimemode!=0)
          exp[i].offset=(CS_ESR * *timewarpby)+p->begin;
        else
          exp[i].offset += (MYFLT)exp[i].wsize/(*timewarpby);

        exp[i].cnt=0;
        exp[i].wsize = (int) (iwsize + (unirand(csound) * (*p->irandw)));
        exp[i].ampphs = FL(0.0);
        exp[i].ampincr = flen/(exp[i].wsize-1);

      skipover:

        frIndx =(MYFLT)((exp[i].cnt * *resample)  + exp[i].offset);
        exp[i].cnt += 1;
        if (frIndx > (MYFLT)p->maxFr) { /* not past last one */
          frIndx = (MYFLT)p->maxFr;
          if (p->prFlg) {
            p->prFlg = 0;   /* false */
            csound->Warning(csound, Str("SNDWARP at last sample frame"));
          }
        }
        longphase = (int32)exp[i].ampphs;
        if (longphase > p->flen-1) longphase = p->flen-1;
        v1 = *(ftpWind->ftable + longphase);
        v2 = *(ftpWind->ftable + longphase + 1);
        fract = (MYFLT)(exp[i].ampphs - (int32)exp[i].ampphs);
        windowamp = v1 + (v2 - v1)*fract;
        exp[i].ampphs += exp[i].ampincr;

        base = (int32)frIndx;    /* index of basis frame of interpolation */
        frac = ((MYFLT)(frIndx - (MYFLT)base));
        frm_0 = *(ftpSamp->ftable + base);
        frm_1 = *(ftpSamp->ftable + (base+1));
        if (frac != FL(0.0)) {
          r1[n] += ((frm_0 + frac*(frm_1-frm_0)) * windowamp) * *amp;
          if (i==0)
           if (p->OUTOCOUNT > 1)
             r2[n] += (frm_0 + frac*(frm_1-frm_0)) * *amp;
        }
        else {
          r1[n] += (frm_0 * windowamp) * *amp;
          if (i==0)
            if (p->OUTOCOUNT > 1)
              r2[n] += frm_0 * *amp;
        }
        if (p->ampcode) amp++;
        if (p->timewarpcode) timewarpby++;
        if (p->resamplecode) resample++;
      }
    }
    return OK;
 err1:
    return csound->PerfError(csound, p->h.insdshead,
                             Str("sndwarp: not initialised"));
}
コード例 #8
0
ファイル: gibbsgrid_c_mtlbrnd.c プロジェクト: can-cs/smc-pgm
/* von-mises pseude-random number generator */
double vmrnd(double mean, double k,
        double* U, const mwSize nuniforms, mwSize *ppU)
{
     /*const mwSize precision = 1; 15 bit per precision value*/   
    double result = 0.0;    
    double a = 1.0 + sqrt(1 + 4.0 * (k * k));
    double b = (a - sqrt(2.0 * a))/(2.0 * k);
    double r = (1.0 + b * b)/(2.0 * b);
    double U1, U2, U3, z, f, c, sign;

    if(k < 0.05) { /* Use uniform proposal */
        while(1) {
            z = 2*M_PI*unirand(U, nuniforms, ppU)-M_PI;
            U1 = unirand(U, nuniforms, ppU);
            
            if(exp(k*(cos(z)-1))-U1 > 0.0) {
                result = z+mean;
                break;
            }
        }
    }
    else { /* Use Cauchy proposal */
        while (1) {
            U1 = unirand(U, nuniforms, ppU);
            z = cos(M_PI * U1);
            f = (1.0 + r * z)/(r + z);
            c = k * (r - f);
            U2 = unirand(U, nuniforms, ppU);
                
            if (c * (2.0 - c) - U2 > 0.0) {
                U3 = unirand(U, nuniforms, ppU);
                sign = 0.0;
                if (U3 - 0.5 < 0.0)
                    sign = -1.0;
                if (U3 - 0.5 > 0.0)
                    sign = 1.0;
                result = sign * acos(f) + mean;
                break;
            }
            else {
                if(log(c/U2) + 1.0 - c >= 0.0) {
                    U3 = unirand(U, nuniforms, ppU);
                    sign = 0.0;
                    if (U3 - 0.5 < 0.0)
                        sign = -1.0;
                    if (U3 - 0.5 > 0.0)
                        sign = 1.0;
                    result = sign * acos(f) + mean;
                    break;
                }
            }
        }
    }

    /* Make sure that we get something in the correct range */
    while (result >= M_PI)
        result -= 2.0 * M_PI;
    while (result <= -M_PI)
        result += 2.0 * M_PI;

    return result;
}