示例#1
0
static void setFreq(t_bowedbar *x, float freq)
{
	int i;
	if(freq < 20.) freq = 20.;
  	x->x_freq = freq;
  	if(x->x_freq > 1568.0) x->x_freq = 1568.0;
  	x->length = (int)(x->srate/x->x_freq);

	x->NR_MODES = 4;
  	for(i = 0; i<x->NR_MODES; i++) {
      if((int)(x->length/x->modes[i]) > 4)
        DLineN_setDelay(&x->delay[i], (int)(x->length/x->modes[i]));
      else	{
        x->NR_MODES = i;
        break;
      }
      
      /*   FIX THIS BETTER!!!!! */
      DLineN_clear(&x->delay[i]);
    
	  BiQuad_clear(&x->bandpass_[i]);    

      x->Zs[i][0] = 0.0;
      x->Zs[i][1] = 0.0;
      x->filtOut[i] = 0.0;
      x->filtIn[i] = 0.0;
    }
  
  	tuneBandPasses(x);
}
示例#2
0
文件: modal4.c 项目: anton-k/csound
static int make_Modal4(CSOUND *csound,
                       Modal4 *m, MYFLT *ifn, MYFLT vgain, MYFLT vrate)
{
    FUNC        *ftp;

    if (LIKELY((ftp = csound->FTnp2Find(csound,ifn)) != NULL))
      m->vibr = ftp;
    else {                                              /* Expect sine wave */
     csound->ErrorMsg(csound, Str("No table for Modal4 case"));
     return NOTOK;
    }
    make_Envelope(&m->envelope);
        /*  We do not make the excitation wave here yet,   */
        /*  because we do not know what it's going to be.  */
    make_BiQuad(&m->filters[0]);
    make_BiQuad(&m->filters[1]);
    make_BiQuad(&m->filters[2]);
    make_BiQuad(&m->filters[3]);
    make_OnePole(&m->onepole);

    m->v_rate = vrate; /* 6.0; */
    m->vibrGain = vgain; /* 0.05; */

/*     m->directGain = 0.0; */
    m->masterGain = FL(1.0);
/*     m->baseFreq = 440.0; */
/*     Modal4_setRatioAndReson(m, 0, 1.00, 0.9997); */    /*  Set some      */
/*     Modal4_setRatioAndReson(m, 1, 1.30, 0.9997); */    /*  silly         */
/*     Modal4_setRatioAndReson(m, 2, 1.77, 0.9997); */    /*  default       */
/*     Modal4_setRatioAndReson(m, 3, 2.37, 0.9997); */    /*  values here   */
/*     Modal4_setFiltGain(m, 0, 0.01); */
/*     Modal4_setFiltGain(m, 1, 0.01); */
/*     Modal4_setFiltGain(m, 2, 0.01); */
/*     Modal4_setFiltGain(m, 3, 0.01); */
/*     OnePole_clear(&m->onepole); */
    BiQuad_clear(&m->filters[0]);
    BiQuad_clear(&m->filters[1]);
    BiQuad_clear(&m->filters[2]);
    BiQuad_clear(&m->filters[3]);
    BiQuad_setEqualGainZeroes(m->filters[0]);
    BiQuad_setEqualGainZeroes(m->filters[1]);
    BiQuad_setEqualGainZeroes(m->filters[2]);
    BiQuad_setEqualGainZeroes(m->filters[3]);
/*     stickHardness = 0.5; */
/*     strikePosition = 0.561; */
    return OK;
}
示例#3
0
void *bowedbar_new(double initial_coeff)
{
	int i;

    t_bowedbar *x = (t_bowedbar *)newobject(bowedbar_class);
     //zero out the struct, to be careful (takk to jkclayton)
    if (x) { 
        for(i=sizeof(t_pxobject)-1;i<sizeof(t_bowedbar);i++)  
                ((char *)x)[i]=0; 
	} 
    dsp_setup((t_pxobject *)x,6);
    outlet_new((t_object *)x, "signal");
    
    x->x_bp = 0.5;
    x->x_bpos = 0.15;
    x->x_bv = 0.5;
    x->x_freq = 440.;
    
    x->modes[0] = 1.0;
    x->modes[1] = 2.756;
  	x->modes[2] = 5.404;
  	x->modes[3] = 8.933;
  	
    x->length = 100.;
  	
  	for (i=0;i<4;i++)	{
    	x->gains[i] = pow(0.9,(double) i);
    	DLineN_alloc(&x->delay[i], 2408);
    	DLineN_setDelay(&x->delay[i], (int)(x->length/x->modes[i]));
    	DLineN_clear(&x->delay[i]);
    	BiQuad_init(&x->bandpass_[i]);
    	BiQuad_clear(&x->bandpass_[i]);
      	x->Zs[i][0] = 0.0;
      	x->Zs[i][1] = 0.0;
      	x->filtOut[i] = 0.0;
      	x->filtIn[i] = 0.0;
  	}
    
    x->srate = sys_getsr();
    x->one_over_srate = 1./x->srate;
    
    //initialize things
    BowTabl_init(&x->bowTabl);
    x->bowTabl.slope = 3.0;
    x->slope = 3.;
  	x->R = 0.97;
  	x->x_GAIN = 0.999;
  	x->integration_const_ = 0.;
  	x->velinput = 0.;

    x->fr_save = x->x_freq;
    
    post("some people do this for a living...");
    
    return (x);
}
示例#4
0
int bowedbarset(CSOUND *csound, BOWEDBAR *p)
{
    int32 i;
    MYFLT amplitude = *p->amp * AMP_RSCALE;

    p->modes[0] = FL(1.0);
    p->modes[1] = FL(2.756);
    p->modes[2] = FL(5.404);
    p->modes[3] = FL(8.933);

    make_BiQuad(&p->bandpass[0]);
    make_BiQuad(&p->bandpass[1]);
    make_BiQuad(&p->bandpass[2]);
    make_BiQuad(&p->bandpass[3]);
    make_ADSR(&p->adsr);
    ADSR_setAllTimes(csound, &p->adsr, FL(0.02), FL(0.005), FL(0.9), FL(0.01));

    if (*p->lowestFreq>=FL(0.0)) {      /* If no init skip */
      if (*p->lowestFreq!=FL(0.0))
        p->length = (int32) (CS_ESR / *p->lowestFreq + FL(1.0));
      else if (*p->frequency!=FL(0.0))
        p->length = (int32) (CS_ESR / *p->frequency + FL(1.0));
      else {
        csound->Warning(csound,
                        Str("unknown lowest frequency for bowed bar -- "
                            "assuming 50Hz\n"));
        p->length = (int32) (CS_ESR / FL(50.0) + FL(1.0));
      }
    }

    p->nr_modes = NR_MODES;
    for (i = 0; i<NR_MODES; i++) {
      make_DLineN(csound, &p->delay[i], p->length);
      DLineN_setDelay(csound, &p->delay[i], (int)(p->length/p->modes[i]));
      BiQuad_clear(&p->bandpass[i]);
    }
/*     p->gains[0] = FL(0.0); */
/*     p->gains[1] = FL(0.0); */
/*     p->gains[2] = FL(0.0); */
/*     p->gains[3] = FL(0.0); */
    p->adsr.target = FL(0.0);
    p->adsr.value = FL(0.0);
    p->adsr.rate = amplitude * FL(0.001);
    p->adsr.state = ATTACK;
    p->lastBowPos = FL(0.0);
    p->bowTarg = FL(0.0);
    p->freq = -FL(1.0);
    p->lastpos = -FL(1.0);
    p->lastpress = p->bowvel = p->velinput = FL(0.0);
    p->kloop = 0;
    p->bowTabl.offSet = p->bowTabl.slope = FL(0.0);
    return OK;
}
示例#5
0
static void clear(t_bowedbar *x)
{
  long i;  
  for(i = 0; i<x->NR_MODES; i++)
    {
      DLineN_clear(&x->delay[i]);
      BiQuad_clear(&x->bandpass_[i]);
      x->Zs[i][0] = 0.0;
      x->Zs[i][1] = 0.0;
      x->filtOut[i] = 0.0;
      x->filtIn[i] = 0.0;
    }
}
示例#6
0
int bowedbar(CSOUND *csound, BOWEDBAR *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       amp = (*p->amp)*AMP_RSCALE; /* Normalise */
    int32 k;
    int i;
    MYFLT       maxVelocity;
    MYFLT       integration_const = *p->integration_const;

    if (p->lastpress != *p->bowPress)
      p->bowTabl.slope = p->lastpress = *p->bowPress;
    if (p->freq != *p->frequency) {
      p->freq = *p->frequency;
      if (p->freq > FL(1568.0)) p->freq = FL(1568.0);

      p->length = (int)(CS_ESR/p->freq);
      p->nr_modes = NR_MODES;   /* reset for frequency shift */
      for (i = 0; i<NR_MODES; i++) {
        if ((int)(p->length/p->modes[i]) > 4)
          DLineN_setDelay(csound, &p->delay[i], (int)(p->length/p->modes[i]));
        else    {
          p->nr_modes = i;
          break;
        }
      }
      if (p->nr_modes==0)
        return csound->InitError(csound,
                                 Str("Bowedbar: cannot have zero modes\n"));
      for (i=0; i<p->nr_modes; i++) {
        MYFLT R = FL(1.0) - p->freq * p->modes[i] * csound->pidsr;
        BiQuad_clear(&p->bandpass[i]);
        BiQuad_setFreqAndReson(p->bandpass[i], p->freq * p->modes[i], R);
        BiQuad_setEqualGainZeroes(p->bandpass[i]);
        BiQuad_setGain(p->bandpass[i], (FL(1.0)-R*R)*FL(0.5));
      }
    }
                                /* Bow position as well */
    if (*p->position != p->lastpos) {
      MYFLT temp2 = *p->position * PI_F;
      p->gains[0] = FABS(SIN(temp2 * FL(0.5))) /*  * pow(0.9,0))*/;
      p->gains[1] = FABS(SIN(temp2) * FL(0.9));
      p->gains[2] = FABS(SIN(temp2 * FL(1.5)) * FL(0.9)*FL(0.9));
      p->gains[3] = FABS(SIN(temp2 * FL(2.0)) * FL(0.9)*FL(0.9)*FL(0.9));
      p->lastpos = *p->position;
    }
    if (*p->bowposition != p->lastBowPos) { /* Not sure what this control is? */
      p->bowTarg += FL(0.02) * (*p->bowposition - p->lastBowPos);
      p->lastBowPos = *p->bowposition;
      ADSR_setTarget(csound, &p->adsr, p->lastBowPos);
      p->lastBowPos = *p->bowposition;
    }
    if (p->kloop>0 && p->h.insdshead->relesing) p->kloop=1;
    if ((--p->kloop) == 0) {
      ADSR_setReleaseRate(csound, &p->adsr, (FL(1.0) - amp) * FL(0.005));
      p->adsr.target = FL(0.0);
      p->adsr.rate = p->adsr.releaseRate;
      p->adsr.state = RELEASE;
    }
    maxVelocity = FL(0.03) + (FL(0.5) * 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++) {
      MYFLT data = FL(0.0);
      MYFLT input = FL(0.0);
      if (integration_const == FL(0.0))
        p->velinput = FL(0.0);
      else
        p->velinput = integration_const * p->velinput;

      for (k=0; k<p->nr_modes; k++) {
        p->velinput += *p->GAIN * p->delay[k].lastOutput;
      }

      if (*p->trackVel) {
        p->bowvel *= FL(0.9995);
        p->bowvel += p->bowTarg;
        p->bowTarg *= FL(0.995);
      }
      else
        p->bowvel = ADSR_tick(&p->adsr)*maxVelocity;

      input = p->bowvel - p->velinput;
      input = input * BowTabl_lookup(csound, &p->bowTabl, input);
      input = input/(MYFLT)p->nr_modes;

      for (k=0; k<p->nr_modes; k++) {
        BiQuad_tick(&p->bandpass[k],
                    input*p->gains[k] + *p->GAIN * p->delay[k].lastOutput);
        DLineN_tick(&p->delay[k], p->bandpass[k].lastOutput);
        data += p->bandpass[k].lastOutput;
      }

      ar[n] = data * AMP_SCALE * FL(20.0); /* 20 is an experimental value */
    }
    return OK;
}