static void pluck(t_bowedbar *x, float amplitude) { long i,j; int pluckLen; float temp; pluckLen = (int)(x->length/x->modes[x->NR_MODES-1]); for (j=1;j<pluckLen/2;j++) { temp = amplitude*2.0*Noise_tick(); for(i=0; i<x->NR_MODES; i++) DLineN_tick(&x->delay[i], temp*j/pluckLen*x->gains[i]); } for (j=pluckLen/2;j>0;j--) { temp = amplitude*2.0*Noise_tick(); for(i=0; i<x->NR_MODES; i++) DLineN_tick(&x->delay[i], temp*j/pluckLen*x->gains[i]);; } }
static t_int *bowedbar_perform(t_int *w) { t_bowedbar *x = (t_bowedbar *)(w[1]); float bp = x->x_bp; float bpos = x->x_bpos; float bv = x->x_bv; float GAIN = x->x_GAIN; float integration_const_ = x->x_integration_const_; float fr = x->x_freq; t_float *out = (t_float *)(w[2]); long n = w[3]; float temp, input, data; long k; if(fr != x->fr_save) { setFreq(x, fr); x->fr_save = fr; } x->bowTabl.slope = bp; x->slope = bp; setStrikePosition(x, bpos); while(n--) { data = 0.0; input = 0.0; if(integration_const_ == 0.0) x->velinput = 0.0; else x->velinput = integration_const_ * x->velinput; for(k=0; k<x->NR_MODES; k++) { x->velinput += GAIN * x->delay[k].lastOutput; } input = bv - x->velinput; input = input * BowTabl_lookup(&x->bowTabl, input); input = input/(float)x->NR_MODES; for(k=0; k<x->NR_MODES; k++) { BiQuad_tick(&x->bandpass_[k], input*x->gains[k] + GAIN * x->delay[k].lastOutput); DLineN_tick(&x->delay[k], x->bandpass_[k].lastOutput); data += x->bandpass_[k].lastOutput; } *out++ = data * 4.0; } return w + 4; }
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; }