Prevent distortion filter from introducing NaNs in the audio buffer #46199
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 causepowf()
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 thepowf()
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 theundenormalise
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 forpowf
. 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.