History

clip freq setting tSVF

Matthew Wang committed 6 years ago

Commit f2d7e1a1 parent d594c1a1 file · +11 −3Browse files

Unified · Split

leaf/Src/leaf-filters.c+11−3
@@ -791,8 +791,10 @@ void tSVF_initToPool (tSVF* const svff, SVFType type, float freq, float Q · 790 unmodified lines
791791 svf->a1 = 1.0f/(1.0f + svf->g * (svf->g + svf->k));
792792 svf->a2 = svf->g*svf->a1;
793793 svf->a3 = svf->g*svf->a2;
794+
794795 svf->cH = 0.0f;
795796 svf->cB = 0.0f;
797+ svf->cBK = 0.0f;
796798 svf->cL = 1.0f;
797799
798800 if (type == SVFTypeLowpass)
@@ -854,6 +856,11 @@ float tSVF_tick(tSVF* const svff, float v0) · 55 unmodified lines
854856 svf->ic1eq = (2.0f * v1) - svf->ic1eq;
855857 svf->ic2eq = (2.0f * v2) - svf->ic2eq;
856858
859+ if (isnan(svf->ic1eq))
860+ {
861+ return 0.0f;
862+ }
863+
857864 return (v0 * svf->cH) + (v1 * svf->cB) + (svf->k * v1 * svf->cBK) + (v2 * svf->cL);
858865 }
859866
@@ -862,8 +869,8 @@ void tSVF_setFreq(tSVF* const svff, float freq) · 2 unmodified lines
862869 _tSVF* svf = *svff;
863870 LEAF* leaf = svf->mempool->leaf;
864871
865− svf->cutoff = freq;
866− svf->g = tanf(PI * freq * leaf->invSampleRate);
872+ svf->cutoff = LEAF_clip(0.0f, freq, leaf->sampleRate * 0.5f);
873+ svf->g = tanf(PI * svf->cutoff * leaf->invSampleRate);
867874 svf->a1 = 1.0f/(1.0f + svf->g * (svf->g + svf->k));
868875 svf->a2 = svf->g * svf->a1;
869876 svf->a3 = svf->g * svf->a2;
@@ -885,8 +892,9 @@ void tSVF_setFreqAndQ(tSVF* const svff, float freq, float Q) · 15 unmodified lines
885892 _tSVF* svf = *svff;
886893 LEAF* leaf = svf->mempool->leaf;
887894
895+ svf->cutoff = LEAF_clip(0.0f, freq, leaf->sampleRate * 0.5f);
888896 svf->k = 1.0f/Q;
889− svf->g = tanf(PI * freq * leaf->invSampleRate);
897+ svf->g = tanf(PI * svf->cutoff * leaf->invSampleRate);
890898 svf->a1 = 1.0f/(1.0f + svf->g * (svf->g + svf->k));
891899 svf->a2 = svf->g * svf->a1;
892900 svf->a3 = svf->g * svf->a2;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t