-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LB302: Prevent cutoff frequency modification when the sampling rate changes. #5618
Conversation
🤖 Hey, I'm @LmmsBot from github.com/lmms/bot and I made downloads for this pull request, click me to make them magically appear! 🎩
Linux
Windows
macOS
🤖{"platform_name_to_artifacts": {"Linux": [{"artifact": {"title": {"title": "(AppImage)", "platform_name": "Linux"}, "link": {"link": "https://8123-15778896-gh.circle-artifacts.com/0/lmms-1.2.2.686-linux-x86_64.AppImage"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/8123?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}], "Windows": [{"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://8125-15778896-gh.circle-artifacts.com/0/lmms-1.2.2.686-mingw-win64.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/8125?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://8124-15778896-gh.circle-artifacts.com/0/lmms-1.2.2.686-mingw-win32.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/8124?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/7n5p9pdpriwftoe4/artifacts/build/lmms-1.2.2-msvc2017-win32.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/34583286"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/km2m4lr2timeq722/artifacts/build/lmms-1.2.2-msvc2017-win64.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/34583286"}], "macOS": [{"artifact": {"title": {"title": "", "platform_name": "macOS"}, "link": {"link": "https://8122-15778896-gh.circle-artifacts.com/0/lmms-1.2.2.686-mac10.13.dmg"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/8122?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}]}, "commit_sha": "048a3084d05985e7f7217ed0c0404a3e8f04ed1d"} |
If this is and really should be a constant In fact, that commit replaces the original author's |
plugins/lb302/lb302.cpp
Outdated
@@ -229,7 +229,7 @@ void lb302Filter3Pole::envRecalc() | |||
w = vcf_e0 + vcf_c0; | |||
k = (fs->cutoff > 0.975)?0.975:fs->cutoff; | |||
kfco = 50.f + (k)*((2300.f-1600.f*(fs->envmod))+(w) * | |||
(700.f+1500.f*(k)+(1500.f+(k)*(Engine::mixer()->processingSampleRate()/2.f-6000.f)) * | |||
(700.f+1500.f*(k)+(1500.f+(k)*(44100.f/2.f-6000.f)) * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation there. It seems really odd at face value, but DSP still doesn't come naturally to me, especially filter coefficients and such. I think it's fine as long as it's easy to see that 44100.0f
is intentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is just the kfco
in the code, for which I think it is at least approximately the cutoff frequency at the start of a note, plotted against the knob position. I just noticed that if the plots above are valid then only for short notes. The vcf_c0
in w = vcf_e0 + vcf_c0
is set to 1
at the beginning of a note (for which I generated the plots) and then gets successively multiplied with the decay vcf_c0 *= fs->envdecay
in lb302filter::envRecalc()
. After a few moments w
is nearly zero and the kfco
reduces to 50.f + (k)*((2300.f-1600.f*(fs->envmod))
so the Env Mod knob is decreasing the cutoff now instead of increasing it like at the beginning of a note. You can hear this very well when you adjust the Env Mod knob for a pattern of many short notes versus a single long note.
Anyways, this does not change my opinion that there shouldn't be a dependency of kfco
on the dynamic sampling rate, which changes the filters behavior completely for the same knob positions. What do you think?
Looks good to me. I'll merge this in a day or two if there are no objections. |
Fixes issue #5615. It turned out that the problem appears when the 24dB Filter is switched on and Env Mod > 0.
Findings:
The term where I made the change gets normalized a few lines down by
1/(Engine::mixer()->processingSampleRate()/2)
, so the term is most likely the cutoff frequency and should therefore not depend on the sampling rate.Yet, the calculation of the cutoff frequency involves a term with the current sampling rate times the value of the knob
k
:(k)*(w)*(k)*(Engine::mixer()->processingSampleRate()/2.f)
. Thew
should be set proportional to1/Engine::mixer()->processingSampleRate()
by the base class, but the author of the code explicitly set his own static values along with the comment "// do not call base class". When the sampling rate changes during the export, this term also changes and consequently the cutoff frequency.A simple fix is to calculate the cutoff frequency with 44.1kHz fixed and maybe also check if the cutoff is above the nyquist frequency which might happen at a lower samplerate than 44.1kHz. Cutoffs up to 22.05kHz are sufficient in all cases.