void AnalogFilter::setfreq (REALTYPE frequency) { if (frequency < 0.1) frequency = 0.1; REALTYPE rap = freq / frequency; if (rap < 1.0) rap = 1.0 / rap; oldabovenq = abovenq; abovenq = frequency > (SAMPLE_RATE / 2 - 500.0); int nyquistthresh = (abovenq ^ oldabovenq); if ((rap > 3.0) || (nyquistthresh != 0)) { // if the frequency is changed fast, it needs interpolation // (now, filter and coeficients backup) for (int i = 0; i < 3; i++) { oldc[i] = c[i]; oldd[i] = d[i]; } for (int i = 0; i < MAX_FILTER_STAGES + 1; i++) { oldx[i] = x[i]; oldy[i] = y[i]; } if (firsttime == 0) needsinterpolation = 1; } freq = frequency; computefiltercoefs(); firsttime = 0; }
/* * Initialise the filters */ void SUBnote::initfilter(bpfilter &filter, float freq, float bw, float amp, float mag) { filter.xn1 = 0.0f; filter.xn2 = 0.0f; if(start == 0) { filter.yn1 = 0.0f; filter.yn2 = 0.0f; } else { float a = 0.1f * mag; //empirically float p = RND * 2.0f * PI; if(start == 1) a *= RND; filter.yn1 = a * cosf(p); filter.yn2 = a * cosf(p + freq * 2.0f * PI / synth.samplerate_f); //correct the error of computation the start amplitude //at very high frequencies if(freq > synth.samplerate_f * 0.96f) { filter.yn1 = 0.0f; filter.yn2 = 0.0f; } } filter.amp = amp; filter.freq = freq; filter.bw = bw; computefiltercoefs(filter, freq, bw, 1.0f); }
/* * Initialise the filters */ void SUBnote::initfilter(bpfilter &filter, REALTYPE freq, REALTYPE bw, REALTYPE amp, REALTYPE mag) { filter.xn1=0.0; filter.xn2=0.0; if (start==0) { filter.yn1=0.0; filter.yn2=0.0; } else { REALTYPE a=0.1*mag;//empirically REALTYPE p=RND*2.0*PI; if (start==1) a*=RND; filter.yn1=a*cos(p); filter.yn2=a*cos(p+freq*2.0*PI/SAMPLE_RATE); //correct the error of computation the start amplitude //at very high frequencies if (freq>SAMPLE_RATE*0.96) { filter.yn1=0.0; filter.yn2=0.0; }; }; filter.amp=amp; filter.freq=freq; filter.bw=bw; computefiltercoefs(filter,freq,bw,1.0); };
void RBFilter::settype (int type_) { type = type_; if(!qmode) computefiltercoefs (); else computefiltercoefs_hiQ (); };
void RBFilter::setgain (float dBgain) { gain = dB2rap (dBgain); if(!qmode) computefiltercoefs (); else computefiltercoefs_hiQ (); };
void RBFilter::setq (float q_) { q = q_; if(!qmode) computefiltercoefs (); else computefiltercoefs_hiQ (); };
void RBFilter::setfreq (float frequency) { if (frequency > (fSAMPLE_RATE / 2.0f - 500.0f)) frequency = fSAMPLE_RATE / 2.0f - 500.0f; if (frequency < 0.1) frequency = 0.1f; float rap = freq / frequency; if (rap < 1.0) rap = 1.0f / rap; oldabovenq = abovenq; abovenq = frequency > (fSAMPLE_RATE / 2.0f - 500.0f); int nyquistthresh = (abovenq ^ oldabovenq); if ((rap > 3.0) || (nyquistthresh != 0)) { //if the frequency is changed fast, it needs interpolation (now, filter and coeficients backup) if (firsttime == 0) needsinterpolation = 1; ipar = par; }; freq = frequency; if(!qmode) computefiltercoefs (); else computefiltercoefs_hiQ (); firsttime = 0; };
void AnalogFilter::setfreq(float frequency) { if(frequency < 0.1f) frequency = 0.1f; float rap = freq / frequency; if(rap < 1.0f) rap = 1.0f / rap; oldabovenq = abovenq; abovenq = frequency > (halfsamplerate_f - 500.0f); bool nyquistthresh = (abovenq ^ oldabovenq); //if the frequency is changed fast, it needs interpolation if((rap > 3.0f) || nyquistthresh) { //(now, filter and coeficients backup) oldCoeff = coeff; for(int i = 0; i < MAX_FILTER_STAGES + 1; ++i) oldHistory[i] = history[i]; if(!firsttime) needsinterpolation = true; } freq = frequency; computefiltercoefs(); firsttime = false; }
void SVFilter::setstages(int stages_) { if(stages_ >= MAX_FILTER_STAGES) stages_ = MAX_FILTER_STAGES - 1; stages = stages_; cleanup(); computefiltercoefs(); }
void SUBnote::initfilter_rl(bpfilter &filter,REALTYPE freq,REALTYPE bw,REALTYPE amp,REALTYPE mag) { filter.amp=amp; filter.freq=freq; filter.bw=bw; computefiltercoefs(filter,freq,bw,1.0); };
void AnalogFilter::setSR(unsigned int value) { iSAMPLE_RATE = value; ifSAMPLE_RATE=(float) iSAMPLE_RATE; computefiltercoefs (); }
void setstages (ZEq10ban_t * s, AnalogFilter *filter, int stages_) { if (stages_ >= MAX_FILTER_STAGES) stages_ = MAX_FILTER_STAGES - 1; filter->stages = stages_; AnalogFilter_Cleanup (s,filter); computefiltercoefs (s,filter); };
void RBFilter::setstages (int stages_) { if (stages_ >= MAX_FILTER_STAGES) stages_ = MAX_FILTER_STAGES - 1; stages = stages_; cleanup (); if(!qmode) computefiltercoefs (); else computefiltercoefs_hiQ (); };
void AnalogFilter::setstages(int stages_) { if(stages_ >= MAX_FILTER_STAGES) stages_ = MAX_FILTER_STAGES - 1; if(stages_ != stages) { stages = stages_; cleanup(); computefiltercoefs(); } }
void SVFilter::setfreq(REALTYPE frequency) { if (frequency<0.1) frequency=0.1; REALTYPE rap=freq/frequency; if (rap<1.0) rap=1.0/rap; oldabovenq=abovenq; abovenq=frequency>(SAMPLE_RATE/2-500.0); int nyquistthresh=(abovenq^oldabovenq); if ((rap>3.0)||(nyquistthresh!=0)) { //if the frequency is changed fast, it needs interpolation (now, filter and coeficients backup) if (firsttime==0) needsinterpolation=1; ipar=par; }; freq=frequency; computefiltercoefs(); firsttime=0; };
void SVFilter::setfreq(REALTYPE frequency) { REALTYPE rap; int nyquistthresh; if (frequency < 0.1) { frequency = 0.1; } rap = freq / frequency; if (rap < 1.0) { rap = 1.0 / rap; } oldabovenq = abovenq; abovenq = frequency > (m_sample_rate / 2 - 500.0); nyquistthresh = (abovenq ^ oldabovenq); if (rap > 3.0 || nyquistthresh != 0) { // if the frequency is changed fast, it needs interpolation (now, filter and coeficients backup) if (firsttime == 0) { needsinterpolation = 1; } ipar = par; } freq = frequency; computefiltercoefs(); firsttime = 0; }
void SVFilter::setfreq(float frequency) { if(frequency < 0.1f) frequency = 0.1f; float rap = freq / frequency; if(rap < 1.0f) rap = 1.0f / rap; oldabovenq = abovenq; abovenq = frequency > (synth->samplerate_f / 2 - 500.0f); bool nyquistthresh = (abovenq ^ oldabovenq); //if the frequency is changed fast, it needs interpolation if((rap > 3.0f) || nyquistthresh) { //(now, filter and coeficients backup) if(!firsttime) needsinterpolation = true; ipar = par; } freq = frequency; computefiltercoefs(); firsttime = false; }
void setfreq (ZEq10ban_t * s, AnalogFilter *filter, float frequency) { int i; if (frequency < 0.1) frequency = 0.1; float rap = filter->freq / frequency; if (rap < 1.0) rap = 1.0 / rap; filter->oldabovenq = filter->abovenq; filter->abovenq = frequency > (s->SAMPLE_RATE / 2 - 500.0); int nyquistthresh = (filter->abovenq ^ filter->oldabovenq); if ((rap > 3.0) || (nyquistthresh != 0)) { //if the frequency is changed fast, it needs interpolation (now, filter and coeficients backup) for (i = 0; i < 3; i++) { filter->oldc[i] = filter->c[i]; filter->oldd[i] = filter->d[i]; }; for (i = 0; i < MAX_FILTER_STAGES + 1; i++) { filter->oldx[i] = filter->x[i]; filter->oldy[i] = filter->y[i]; }; if (filter->firsttime == 0) filter->needsinterpolation = 1; }; filter->freq = frequency; computefiltercoefs (s,filter); filter->firsttime = 0; };
void setq (ZEq10ban_t * s, AnalogFilter *filter, float q_) { filter->q = q_; computefiltercoefs (s,filter); };
void SVFilter::setq(float q_) { q = q_; computefiltercoefs(); }
void SVFilter::setgain(float dBgain) { gain = dB2rap(dBgain); computefiltercoefs(); }
void SVFilter::settype(int type_) { type = type_; computefiltercoefs(); }
void setgain (goomf_synth_t * s, AnalogFilter * filter, float dBgain) { filter->gain = dB2rap (dBgain); computefiltercoefs (s, filter); };
void settype (ZEq10ban_t * s, AnalogFilter *filter, int type_) { filter->type = type_; computefiltercoefs (s,filter); };
void setgain (ZEq10ban_t * s, AnalogFilter *filter, float dBgain) { filter->gain = dB2rap (dBgain); computefiltercoefs (s,filter); };
void AnalogFilter::computefiltercoefs(void) { float tmp; bool zerocoefs = false; //this is used if the freq is too high //do not allow frequencies bigger than samplerate/2 float freq = this->freq; if(freq > (halfsamplerate_f - 500.0f)) { freq = halfsamplerate_f - 500.0f; zerocoefs = true; } if(freq < 0.1f) freq = 0.1f; //do not allow bogus Q if(q < 0.0f) q = 0.0f; float tmpq, tmpgain; if(stages == 0) { tmpq = q; tmpgain = gain; } else { tmpq = (q > 1.0f) ? powf(q, 1.0f / (stages + 1)) : q; tmpgain = powf(gain, 1.0f / (stages + 1)); } //Alias Terms float *c = coeff.c; float *d = coeff.d; //General Constants const float omega = 2 * PI * freq / samplerate_f; const float sn = sinf(omega), cs = cosf(omega); float alpha, beta; //most of theese are implementations of //the "Cookbook formulae for audio EQ" by Robert Bristow-Johnson //The original location of the Cookbook is: //http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt switch(type) { case 0: //LPF 1 pole if(!zerocoefs) tmp = expf(-2.0f * PI * freq / samplerate_f); else tmp = 0.0f; c[0] = 1.0f - tmp; c[1] = 0.0f; c[2] = 0.0f; d[1] = tmp; d[2] = 0.0f; order = 1; break; case 1: //HPF 1 pole if(!zerocoefs) tmp = expf(-2.0f * PI * freq / samplerate_f); else tmp = 0.0f; c[0] = (1.0f + tmp) / 2.0f; c[1] = -(1.0f + tmp) / 2.0f; c[2] = 0.0f; d[1] = tmp; d[2] = 0.0f; order = 1; break; case 2: //LPF 2 poles if(!zerocoefs) { alpha = sn / (2.0f * tmpq); tmp = 1 + alpha; c[1] = (1.0f - cs) / tmp; c[0] = c[2] = c[1] / 2.0f; d[1] = -2.0f * cs / tmp * -1.0f; d[2] = (1.0f - alpha) / tmp * -1.0f; } else { c[0] = 1.0f; c[1] = c[2] = d[1] = d[2] = 0.0f; } order = 2; break; case 3: //HPF 2 poles if(!zerocoefs) { alpha = sn / (2.0f * tmpq); tmp = 1 + alpha; c[0] = (1.0f + cs) / 2.0f / tmp; c[1] = -(1.0f + cs) / tmp; c[2] = (1.0f + cs) / 2.0f / tmp; d[1] = -2.0f * cs / tmp * -1.0f; d[2] = (1.0f - alpha) / tmp * -1.0f; } else c[0] = c[1] = c[2] = d[1] = d[2] = 0.0f; order = 2; break; case 4: //BPF 2 poles if(!zerocoefs) { alpha = sn / (2.0f * tmpq); tmp = 1.0f + alpha; c[0] = alpha / tmp *sqrtf(tmpq + 1.0f); c[1] = 0.0f; c[2] = -alpha / tmp *sqrtf(tmpq + 1.0f); d[1] = -2.0f * cs / tmp * -1.0f; d[2] = (1.0f - alpha) / tmp * -1.0f; } else c[0] = c[1] = c[2] = d[1] = d[2] = 0.0f; order = 2; break; case 5: //NOTCH 2 poles if(!zerocoefs) { alpha = sn / (2.0f * sqrtf(tmpq)); tmp = 1.0f + alpha; c[0] = 1.0f / tmp; c[1] = -2.0f * cs / tmp; c[2] = 1.0f / tmp; d[1] = -2.0f * cs / tmp * -1.0f; d[2] = (1.0f - alpha) / tmp * -1.0f; } else { c[0] = 1.0f; c[1] = c[2] = d[1] = d[2] = 0.0f; } order = 2; break; case 6: //PEAK (2 poles) if(!zerocoefs) { tmpq *= 3.0f; alpha = sn / (2.0f * tmpq); tmp = 1.0f + alpha / tmpgain; c[0] = (1.0f + alpha * tmpgain) / tmp; c[1] = (-2.0f * cs) / tmp; c[2] = (1.0f - alpha * tmpgain) / tmp; d[1] = -2.0f * cs / tmp * -1.0f; d[2] = (1.0f - alpha / tmpgain) / tmp * -1.0f; } else { c[0] = 1.0f; c[1] = c[2] = d[1] = d[2] = 0.0f; } order = 2; break; case 7: //Low Shelf - 2 poles if(!zerocoefs) { tmpq = sqrtf(tmpq); alpha = sn / (2.0f * tmpq); beta = sqrtf(tmpgain) / tmpq; tmp = (tmpgain + 1.0f) + (tmpgain - 1.0f) * cs + beta * sn; c[0] = tmpgain * ((tmpgain + 1.0f) - (tmpgain - 1.0f) * cs + beta * sn) / tmp; c[1] = 2.0f * tmpgain * ((tmpgain - 1.0f) - (tmpgain + 1.0f) * cs) / tmp; c[2] = tmpgain * ((tmpgain + 1.0f) - (tmpgain - 1.0f) * cs - beta * sn) / tmp; d[1] = -2.0f * ((tmpgain - 1.0f) + (tmpgain + 1.0f) * cs) / tmp * -1.0f; d[2] = ((tmpgain + 1.0f) + (tmpgain - 1.0f) * cs - beta * sn) / tmp * -1.0f; } else { c[0] = tmpgain; c[1] = c[2] = d[1] = d[2] = 0.0f; } order = 2; break; case 8: //High Shelf - 2 poles if(!zerocoefs) { tmpq = sqrtf(tmpq); alpha = sn / (2.0f * tmpq); beta = sqrtf(tmpgain) / tmpq; tmp = (tmpgain + 1.0f) - (tmpgain - 1.0f) * cs + beta * sn; c[0] = tmpgain * ((tmpgain + 1.0f) + (tmpgain - 1.0f) * cs + beta * sn) / tmp; c[1] = -2.0f * tmpgain * ((tmpgain - 1.0f) + (tmpgain + 1.0f) * cs) / tmp; c[2] = tmpgain * ((tmpgain + 1.0f) + (tmpgain - 1.0f) * cs - beta * sn) / tmp; d[1] = 2.0f * ((tmpgain - 1.0f) - (tmpgain + 1.0f) * cs) / tmp * -1.0f; d[2] = ((tmpgain + 1.0f) - (tmpgain - 1.0f) * cs - beta * sn) / tmp * -1.0f; } else { c[0] = 1.0f; c[1] = c[2] = d[1] = d[2] = 0.0f; } order = 2; break; default: //wrong type type = 0; computefiltercoefs(); break; } }
void computefiltercoefs (ZEq10ban_t * s, AnalogFilter *filter) { float tmp; float omega, sn, cs, alpha, beta; int zerocoefs = 0; //this is used if the freq is too high //do not allow frequencies bigger than samplerate/2 float freq = filter->freq; if (freq > (s->SAMPLE_RATE / 2 - 500.0)) { freq = s->SAMPLE_RATE / 2 - 500.0; zerocoefs = 1; }; if (freq < 0.1) freq = 0.1; //do not allow bogus Q if (filter->q < 0.0) filter->q = 0.0; float tmpq, tmpgain; if (filter->stages == 0) { tmpq = filter->q; tmpgain = filter->gain; } else { tmpq = (filter->q > 1.0 ? powf (filter->q, 1.0 / (filter->stages + 1)) : filter->q); tmpgain = powf (filter->gain, 1.0 / (filter->stages + 1)); }; //most of theese are implementations of //the "Cookbook formulae for audio EQ" by Robert Bristow-Johnson //The original location of the Cookbook is: //http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt switch (filter->type) { case 0: //LPF 1 pole if (zerocoefs == 0) tmp = expf (-2.0 * M_PI * freq / s->SAMPLE_RATE); else tmp = 0.0; filter->c[0] = 1.0 - tmp; filter->c[1] = 0.0; filter->c[2] = 0.0; filter->d[1] = tmp; filter->d[2] = 0.0; filter->order = 1; break; case 1: //HPF 1 pole if (zerocoefs == 0) tmp = expf (-2.0 * M_PI * freq / s->SAMPLE_RATE); else tmp = 0.0; filter->c[0] = (1.0 + tmp) / 2.0; filter->c[1] = -(1.0 + tmp) / 2.0; filter->c[2] = 0.0; filter->d[1] = tmp; filter->d[2] = 0.0; filter->order = 1; break; case 2: //LPF 2 poles if (zerocoefs == 0) { omega = 2 * M_PI * freq / s->SAMPLE_RATE; sn = sinf (omega); cs = cosf (omega); alpha = sn / (2 * tmpq); tmp = 1 + alpha; filter->c[0] = (1.0 - cs) / 2.0 / tmp; filter->c[1] = (1.0 - cs) / tmp; filter->c[2] = (1.0 - cs) / 2.0 / tmp; filter->d[1] = -2 * cs / tmp * (-1); filter->d[2] = (1 - alpha) / tmp * (-1); } else { filter->c[0] = 1.0; filter->c[1] = 0.0; filter->c[2] = 0.0; filter->d[1] = 0.0; filter->d[2] = 0.0; }; filter->order = 2; break; case 3: //HPF 2 poles if (zerocoefs == 0) { omega = 2 * M_PI * freq / s->SAMPLE_RATE; sn = sinf (omega); cs = cosf (omega); alpha = sn / (2 * tmpq); tmp = 1 + alpha; filter->c[0] = (1.0 + cs) / 2.0 / tmp; filter->c[1] = -(1.0 + cs) / tmp; filter->c[2] = (1.0 + cs) / 2.0 / tmp; filter->d[1] = -2 * cs / tmp * (-1); filter->d[2] = (1 - alpha) / tmp * (-1); } else { filter->c[0] = 0.0; filter->c[1] = 0.0; filter->c[2] = 0.0; filter->d[1] = 0.0; filter->d[2] = 0.0; }; filter->order = 2; break; case 4: //BPF 2 poles if (zerocoefs == 0) { omega = 2 * M_PI * freq / s->SAMPLE_RATE; sn = sinf (omega); cs = cosf (omega); alpha = sn / (2 * tmpq); tmp = 1 + alpha; filter->c[0] = alpha / tmp * sqrtf (tmpq + 1); filter->c[1] = 0; filter->c[2] = -alpha / tmp * sqrtf (tmpq + 1); filter->d[1] = -2 * cs / tmp * (-1); filter->d[2] = (1 - alpha) / tmp * (-1); } else { filter->c[0] = 0.0; filter->c[1] = 0.0; filter->c[2] = 0.0; filter->d[1] = 0.0; filter->d[2] = 0.0; }; filter->order = 2; break; case 5: //NOTCH 2 poles if (zerocoefs == 0) { omega = 2 * M_PI * freq / s->SAMPLE_RATE; sn = sinf (omega); cs = cosf (omega); alpha = sn / (2 * sqrtf (tmpq)); tmp = 1 + alpha; filter->c[0] = 1 / tmp; filter->c[1] = -2 * cs / tmp; filter->c[2] = 1 / tmp; filter->d[1] = -2 * cs / tmp * (-1); filter->d[2] = (1 - alpha) / tmp * (-1); } else { filter->c[0] = 1.0; filter->c[1] = 0.0; filter->c[2] = 0.0; filter->d[1] = 0.0; filter->d[2] = 0.0; }; filter->order = 2; break; case 6: //PEAK (2 poles) if (zerocoefs == 0) { omega = 2 * M_PI * freq / s->SAMPLE_RATE; sn = sinf (omega); cs = cosf (omega); tmpq *= 3.0; alpha = sn / (2 * tmpq); tmp = 1 + alpha / tmpgain; filter->c[0] = (1.0 + alpha * tmpgain) / tmp; filter->c[1] = (-2.0 * cs) / tmp; filter->c[2] = (1.0 - alpha * tmpgain) / tmp; filter->d[1] = -2 * cs / tmp * (-1); filter->d[2] = (1 - alpha / tmpgain) / tmp * (-1); } else { filter->c[0] = 1.0; filter->c[1] = 0.0; filter->c[2] = 0.0; filter->d[1] = 0.0; filter->d[2] = 0.0; }; filter->order = 2; break; case 7: //Low Shelf - 2 poles if (zerocoefs == 0) { omega = 2 * M_PI * freq / s->SAMPLE_RATE; sn = sinf (omega); cs = cosf (omega); tmpq = sqrtf (tmpq); alpha = sn / (2 * tmpq); beta = sqrtf (tmpgain) / tmpq; tmp = (tmpgain + 1.0) + (tmpgain - 1.0) * cs + beta * sn; filter->c[0] = tmpgain * ((tmpgain + 1.0) - (tmpgain - 1.0) * cs + beta * sn) / tmp; filter->c[1] = 2.0 * tmpgain * ((tmpgain - 1.0) - (tmpgain + 1.0) * cs) / tmp; filter->c[2] = tmpgain * ((tmpgain + 1.0) - (tmpgain - 1.0) * cs - beta * sn) / tmp; filter->d[1] = -2.0 * ((tmpgain - 1.0) + (tmpgain + 1.0) * cs) / tmp * (-1); filter->d[2] = ((tmpgain + 1.0) + (tmpgain - 1.0) * cs - beta * sn) / tmp * (-1); } else { filter->c[0] = tmpgain; filter->c[1] = 0.0; filter->c[2] = 0.0; filter->d[1] = 0.0; filter->d[2] = 0.0; }; filter->order = 2; break; case 8: //High Shelf - 2 poles if (zerocoefs == 0) { omega = 2 * M_PI * freq / s->SAMPLE_RATE; sn = sinf (omega); cs = cosf (omega); tmpq = sqrtf (tmpq); alpha = sn / (2 * tmpq); beta = sqrtf (tmpgain) / tmpq; tmp = (tmpgain + 1.0) - (tmpgain - 1.0) * cs + beta * sn; filter->c[0] = tmpgain * ((tmpgain + 1.0) + (tmpgain - 1.0) * cs + beta * sn) / tmp; filter->c[1] = -2.0 * tmpgain * ((tmpgain - 1.0) + (tmpgain + 1.0) * cs) / tmp; filter->c[2] = tmpgain * ((tmpgain + 1.0) + (tmpgain - 1.0) * cs - beta * sn) / tmp; filter->d[1] = 2.0 * ((tmpgain - 1.0) - (tmpgain + 1.0) * cs) / tmp * (-1); filter->d[2] = ((tmpgain + 1.0) - (tmpgain - 1.0) * cs - beta * sn) / tmp * (-1); } else { filter->c[0] = 1.0; filter->c[1] = 0.0; filter->c[2] = 0.0; filter->d[1] = 0.0; filter->d[2] = 0.0; }; filter->order = 2; break; default: //wrong type filter->type = 0; computefiltercoefs (s,filter); break; }; };
void setq (goomf_synth_t * s, AnalogFilter * filter, float q_) { filter->q = q_; computefiltercoefs (s, filter); };
/* * Compute Parameters of SUBnote for each tick */ void SUBnote::computecurrentparameters() { if(FreqEnvelope || BandWidthEnvelope || (oldpitchwheel != ctl.pitchwheel.data) || (oldbandwidth != ctl.bandwidth.data) || portamento) { float envfreq = 1.0f; float envbw = 1.0f; float gain = 1.0f; if(FreqEnvelope) { envfreq = FreqEnvelope->envout() / 1200; envfreq = powf(2.0f, envfreq); } envfreq *= powf(ctl.pitchwheel.relfreq, BendAdjust); //pitch wheel if(portamento) { //portamento is used envfreq *= ctl.portamento.freqrap; if(!ctl.portamento.used) //the portamento has finished portamento = false; //this note is no longer "portamented" } if(BandWidthEnvelope) { envbw = BandWidthEnvelope->envout(); envbw = powf(2, envbw); } envbw *= ctl.bandwidth.relbw; //bandwidth controller float tmpgain = 1.0f / sqrt(envbw * envfreq); for(int n = 0; n < numharmonics; ++n) { overtone_rolloff[n] = computerolloff(overtone_freq[n] * envfreq); } for(int n = 0; n < numharmonics; ++n) for(int nph = 0; nph < numstages; ++nph) { if(nph == 0) gain = tmpgain; else gain = 1.0f; computefiltercoefs(lfilter[nph + n * numstages], lfilter[nph + n * numstages].freq * envfreq, lfilter[nph + n * numstages].bw * envbw, gain); } if(stereo) for(int n = 0; n < numharmonics; ++n) for(int nph = 0; nph < numstages; ++nph) { if(nph == 0) gain = tmpgain; else gain = 1.0f; computefiltercoefs( rfilter[nph + n * numstages], rfilter[nph + n * numstages].freq * envfreq, rfilter[nph + n * numstages].bw * envbw, gain); } oldbandwidth = ctl.bandwidth.data; oldpitchwheel = ctl.pitchwheel.data; } newamplitude = volume * AmpEnvelope->envout_dB() * 2.0f; //Filter if(GlobalFilterL != NULL) { float globalfilterpitch = GlobalFilterCenterPitch + GlobalFilterEnvelope->envout(); float filterfreq = globalfilterpitch + ctl.filtercutoff.relfreq + GlobalFilterFreqTracking; filterfreq = Filter::getrealfreq(filterfreq); GlobalFilterL->setfreq_and_q(filterfreq, globalfiltercenterq * ctl.filterq.relq); if(GlobalFilterR != NULL) GlobalFilterR->setfreq_and_q( filterfreq, globalfiltercenterq * ctl.filterq.relq); } }
void settype (goomf_synth_t * s, AnalogFilter * filter, int type_) { filter->type = type_; computefiltercoefs (s, filter); };