static MYFLT SingWave_tick(CSOUND *csound, SingWave *p) { MYFLT lastOutput; int32 temp, temp1; MYFLT alpha, temp_rate; MYFLT mytime = p->mytime; temp_rate = Envelope_tick(&p->pitchEnvelope); // printf("SingWave_tick: %f\n", temp_rate); mytime += temp_rate; /* Update current time */ mytime += temp_rate*Modulatr_tick(csound,&p->modulator); /* Add vibratos */ //printf(" : %f %d\n", mytime, p->wave->flen); while (mytime >= (MYFLT)p->wave->flen) { /* Check for end of sound */ mytime -= p->wave->flen; /* loop back to beginning */ } while (mytime < FL(0.0)) { /* Check for end of sound */ mytime += p->wave->flen; /* loop back to beginning */ } temp = (int32) mytime; /* Integer part of time address */ alpha = mytime - (MYFLT) temp; /* fractional part of time address */ temp1 = temp + 1; if (temp1==(int32_t)p->wave->flen) temp1 = temp; /* Wrap!! */ lastOutput = alpha * p->wave->ftable[temp1]; /* Do linear */ // printf(" : (%d %d) %f %f ", temp, temp1, alpha, lastOutput); lastOutput += (FL(1.0)-alpha) * p->wave->ftable[temp]; /* interpolation */ // printf("%f ", lastOutput); lastOutput *= Envelope_tick(&p->envelope); // printf("%f\n", lastOutput); p->mytime = mytime; return lastOutput; }
int32_t voicform(CSOUND *csound, VOICF *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; if (p->basef != *p->frequency) { p->basef = *p->frequency; SingWave_setFreq(csound, &p->voiced, p->basef); } /* OnePole_setPole(&p->onepole, 0.95 - (amp * 0.1)); */ /* Envelope_setTarget(&(p->voiced.envelope), amp); */ /* Envelope_setTarget(&p->noiseEnv, 0.95 - (amp * 0.1)); */ SingWave_setVibFreq(p->voiced, *p->vibf); Modulatr_setVibAmt(p->voiced.modulator, *p->vibAmt); /* Set phoneme */ if (p->oldform != *p->formant || p->ph != (int32_t)(0.5+*p->phoneme)) { p->oldform = *p->formant; p->ph = (int32_t)(0.5 + *p->phoneme); csound->Warning(csound, Str("Setting Phoneme: %d %f\n"), p->ph, p->oldform); VoicForm_setPhoneme(csound, p, (int32_t) *p->phoneme, p->oldform); } /* voicprint(csound, p); */ 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 temp; MYFLT lastOutput; temp = OnePole_tick(&p->onepole, OneZero_tick(&p->onezero, SingWave_tick(csound, &p->voiced))); // printf("%d: temp=%f ", n, temp); temp += Envelope_tick(&p->noiseEnv) * Noise_tick(csound, &p->noise); // printf("%f\n", temp); lastOutput = FormSwep_tick(csound, &p->filters[0], temp); // printf("%d: output=%f ", lastOutput); lastOutput = FormSwep_tick(csound, &p->filters[1], lastOutput); // printf("%f ", lastOutput); lastOutput = FormSwep_tick(csound, &p->filters[2], lastOutput); // printf("%f ", lastOutput); lastOutput = FormSwep_tick(csound, &p->filters[3], lastOutput); // printf("%f ", lastOutput); lastOutput *= p->lastGain; // printf("%f ", lastOutput); // printf("->%f\n", lastOutput* AMP_SCALE); ar[n] = lastOutput * FL(0.22) * AMP_SCALE * *p->amp; } return OK; }
static void Modal4_strike(CSOUND *csound, Modal4 *m, MYFLT amplitude) { int i; MYFLT temp; Envelope_setRate(csound, &m->envelope, FL(1.0)); Envelope_setTarget(&m->envelope, amplitude); OnePole_setPole(&m->onepole, FL(1.0) - amplitude); Envelope_tick(&m->envelope); m->w_time = FL(0.0); //m->w_lastOutput = FL(0.0); m->w_allDone = 0; /* wave->reset(); */ for (i=0;i<4;i++) { if (m->ratios[i] < 0) temp = - m->ratios[i]; else temp = m->ratios[i] * m->baseFreq; BiQuad_setFreqAndReson(m->filters[i], temp, m->resons[i]); } }
static MYFLT Modal4_tick(Modal4 *m) { MYFLT temp,temp2; int32 itemp; MYFLT temp_time, alpha, lastOutput; int length = (int)m->wave->flen; m->w_time += m->w_rate; /* Update current time */ if (m->w_time >= length) { /* Check for end of sound */ m->w_time = (MYFLT)(length-1); /* stick at end */ m->w_allDone = 1; /* Information for one-shot use */ } else if (m->w_time < FL(0.0)) /* Check for end of sound */ m->w_time = FL(0.0); /* stick at beg */ temp_time = m->w_time; #ifdef phase_offset if (m->w_phaseOffset != FL(0.0)) { temp_time += m->w_phaseOffset; /* Add phase offset */ if (temp_time >= length) /* Check for end of sound */ temp_time = length-1; /* stick at end */ else if (temp_time < FL(0.0)) /* check for end of sound */ temp_time = FL(0.0); /* stick at beg */ } #endif itemp = (int32) temp_time; /* Integer part of time address */ alpha = temp_time - (MYFLT)itemp; /* fractional part of time address */ lastOutput = m->wave->ftable[itemp]; /* Do linear interpolation */ lastOutput = lastOutput + /* same as alpha*data[temp+1] */ (alpha * (m->wave->ftable[itemp+1] - lastOutput)); /* + (1-alpha)data[temp] */ temp = m->masterGain * OnePole_tick(&m->onepole, lastOutput * Envelope_tick(&m->envelope)); temp2 = BiQuad_tick(&m->filters[0], temp); temp2 += BiQuad_tick(&m->filters[1], temp); temp2 += BiQuad_tick(&m->filters[2], temp); temp2 += BiQuad_tick(&m->filters[3], temp); temp2 = temp2 - (temp2 * m->directGain); temp2 += m->directGain * temp; if (m->vibrGain != 0.0) { /* Tick on vibrato table */ m->v_time += m->v_rate; /* Update current time */ while (m->v_time >= m->vibr->flen) /* Check for end of sound */ m->v_time -= m->vibr->flen; /* loop back to beginning */ while (m->v_time < FL(0.0)) /* Check for end of sound */ m->v_time += m->vibr->flen; /* loop back to beginning */ temp_time = m->v_time; #ifdef phase_offset if (m->v_phaseOffset != FL(0.0)) { temp_time += m->v_phaseOffset; /* Add phase offset */ while (temp_time >= m->vibr->flen) /* Check for end of sound */ temp_time -= m->vibr->flen; /* loop back to beginning */ while (temp_time < FL(0.0)) /* Check for end of sound */ temp_time += m->vibr->flen; /* loop back to beginning */ } #endif itemp = (int32) temp_time; /* Integer part of time address */ /* fractional part of time address */ alpha = temp_time - (MYFLT)itemp; lastOutput = m->vibr->ftable[itemp]; /* Do linear interpolation */ /* same as alpha*data[itemp+1] + (1-alpha)data[temp] */ lastOutput = /*m->v)*/lastOutput + (alpha * (m->vibr->ftable[itemp+1] - lastOutput)); /* End of vibrato tick */ temp = FL(1.0) + (lastOutput * m->vibrGain); /* Calculate AM */ temp2 = temp * temp2; /* and apply to master out */ } return (temp2 + temp2); }
int clarin(CSOUND *csound, CLARIN *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 */ MYFLT nGain = *p->noiseGain; int v_len = (int)p->vibr->flen; MYFLT *v_data = p->vibr->ftable; MYFLT vibGain = *p->vibAmt; MYFLT vTime = p->v_time; if (p->envelope.rate==FL(0.0)) { p->envelope.rate = amp /(*p->attack*CS_ESR); p->envelope.value = p->envelope.target = FL(0.55) + amp*FL(0.30); } p->outputGain = amp + FL(0.001); DLineL_setDelay(&p->delayLine, /* length - approx filter delay */ (CS_ESR/ *p->frequency) * FL(0.5) - FL(1.5)); p->v_rate = *p->vibFreq * p->vibr->flen * csound->onedsr; /* Check to see if into decay yet */ if (p->kloop>0 && p->h.insdshead->relesing) p->kloop=1; if ((--p->kloop) == 0) { p->envelope.state = 1; /* Start change */ p->envelope.rate = p->envelope.value / (*p->dettack * CS_ESR); p->envelope.target = FL(0.0); #ifdef BETA csound->Message(csound, "Set off phase time = %f Breath v,r = %f, %f\n", (MYFLT) CS_KCNT * CS_ONEDKR, p->envelope.value, p->envelope.rate); #endif } 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 pressureDiff; MYFLT breathPressure; int32 temp; MYFLT temp_time, alpha; MYFLT nextsamp; MYFLT v_lastOutput; MYFLT lastOutput; breathPressure = Envelope_tick(&p->envelope); breathPressure += breathPressure * nGain * Noise_tick(csound,&p->noise); /* Tick on vibrato table */ vTime += p->v_rate; /* Update current time */ while (vTime >= v_len) /* Check for end of sound */ vTime -= v_len; /* loop back to beginning */ while (vTime < FL(0.0)) /* Check for end of sound */ vTime += v_len; /* loop back to beginning */ temp_time = vTime; #ifdef have_phase if (p->v_phaseOffset != FL(0.0)) { temp_time += p->v_phaseOffset; /* Add phase offset */ while (temp_time >= v_len) /* Check for end of sound */ temp_time -= v_len; /* loop back to beginning */ while (temp_time < FL(0.0)) /* Check for end of sound */ temp_time += v_len; /* loop back to beginning */ } #endif temp = (int32) temp_time; /* Integer part of time address */ /* fractional part of time address */ alpha = temp_time - (MYFLT)temp; v_lastOutput = v_data[temp]; /* Do linear interpolation */ /* same as alpha*data[temp+1] + (1-alpha)data[temp] */ v_lastOutput += (alpha * (v_data[temp+1] - v_lastOutput)); /* End of vibrato tick */ breathPressure += breathPressure * vibGain * v_lastOutput; pressureDiff = OneZero_tick(&p->filter, /* differential pressure */ DLineL_lastOut(&p->delayLine)); pressureDiff = (-FL(0.95)*pressureDiff) - breathPressure; /* of reflected and mouth */ nextsamp = pressureDiff * ReedTabl_LookUp(&p->reedTable,pressureDiff); nextsamp = breathPressure + nextsamp; /* perform scattering in economical way */ lastOutput = DLineL_tick(&p->delayLine, nextsamp); lastOutput *= p->outputGain; ar[n] = lastOutput*AMP_SCALE; } p->v_time = vTime; return OK; }