Skip to content
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

Prevent distortion filter from introducing NaNs in the audio buffer #46199

Merged
merged 1 commit into from
Feb 19, 2021

Conversation

ellenhp
Copy link
Contributor

@ellenhp ellenhp commented Feb 19, 2021

Fixes #38372

Currently the base argument passed to powf() is negative sometimes. I don't understand the math here well enough to catch what that means conceptually or if it's indicative of a larger problem, but I do understand that for non-integer exponents that's going to cause powf() to NaN, which propagates a discontinuity in the output beyond just this filter. I tried this change and it works well. Distorted audio sounds nice and distorted, and undistorted audio also sounds clear since there aren't NaNs propagating through.

Notably, I tried to just clamp the value of a before the powf() step to the range [0,inf), but the distortion didn't sound good and the parameters applied to the filter didn't seem like they were changing things much. I dug a bit deeper and noticed that the undenormalise step if I understand it correctly seems to have an output range of (-inf,-1] and [1,inf). So I figured that sign was important and decided to try passing the sign bit through and only using the magnitude of the number for powf. This sounds great, but will definitely need a closer look by someone who knows what this filter is actually doing (reduz?).

Test using the minimal repro project for #38372.

@ellenhp ellenhp marked this pull request as ready for review February 19, 2021 01:13
@ellenhp ellenhp requested a review from a team as a code owner February 19, 2021 01:13
@Calinou Calinou added bug cherrypick:3.x Considered for cherry-picking into a future 3.x release topic:audio labels Feb 19, 2021
@Calinou Calinou added this to the 4.0 milestone Feb 19, 2021
@akien-mga akien-mga merged commit 5a9cab4 into godotengine:master Feb 19, 2021
@akien-mga
Copy link
Member

Thanks!

@ellenhp ellenhp deleted the fix_distortion_filter branch February 19, 2021 07:29
@akien-mga
Copy link
Member

Cherry-picked for 3.2.4.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AudioEffectDistortion in an Audio Bus that is playing, affects other Audio Bus sound
4 participants