MockbaTheBorg / MockbaModular

Mockba's plugin for VCV Rack
MIT License
15 stars 2 forks source link

filtah seems to run into rounding errors with lower sampling rates #13

Closed hexdump0815 closed 3 years ago

hexdump0815 commented 4 years ago

it looks like i discovered a similar problem with filtah as i some months ago discovered with pErCO from bidoo: if used with low sample rates like 22.05khz (which i'm sometimes using on the sonaremin to reduce the cpu usage - you have to set it in the vcvrack settings file as 22050 as its not available from the menu) then something simlar happens like described here in the old pErCO issue: https://github.com/sebastien-bouffier/Bidoo/issues/142 ... with filtah i saw it at 22.05khz and when the frequency knob goes to the end - then the module at some point gets lost and can not be brought back to normal operation anymore ... please let me know in case you cannot reproduce it, then i can try to make the description more detailed ... it would be nice if it could be made working also for such low sample rates - maybe the bidoo solution gives a hint about how to fix it?

best wishes and a lot of thanks in advance - hexdump

hexdump0815 commented 4 years ago

here is btw. the commit which fixed it for bidoo's pErCO: https://github.com/sebastien-bouffier/Bidoo/commit/20ac119df0db3180a8be5e12b2cd5643a0862506#diff-565b1fc20f1c6db5b3c26ec689dea88f

MockbaTheBorg commented 4 years ago

Hi @hexdump0815 , I have moved away from VCV for a while now (planning to come back for VCV2). A quick look at the code points to line 449 of MockbaModular.hpp: image

Where I set frequency (f) to two times the cutoff divided by the sample rate. You can try to change that math a little bit and see if it helps. I would do it but I have removed all the building environments and VCV source code from my computer, as I do not have any plans to get back to VCV until VCV2 is released.

Thanks, Marcelo.

hexdump0815 commented 4 years ago

thanks a lot for the hint and i think i understand now the problem a bit (without really understanding the details of the filter algorithm) - the solution for pErCO seems to have been to clamp the cutoff frequency to 8khz which was for my reported case back then 1/4 of the sample frequency to avoid the relation of cutoff and sample rate to reach some unwanted numbers (see https://github.com/sebastien-bouffier/Bidoo/issues/142#issuecomment-687868942 too) ... i tried this now for filtah and it seems to work:

diff --git a/src/MockbaModular.hpp b/src/MockbaModular.hpp
index 6757916..e08a4a7 100644
--- a/src/MockbaModular.hpp
+++ b/src/MockbaModular.hpp
@@ -433,7 +433,8 @@ struct _Filter {
        }

        void setCutoff(float_4 cutoffV) {
-               cutoff = cutoffV;
+//             cutoff = cutoffV;
+               cutoff = simd::clamp(cutoffV, 1.0f, 8000.0f);
        }

        void setRes(float_4 resV) {

does that make sense?