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

[AudioFilterSW] Fix audio cutting out due to numerical errors #102210

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

Geometror
Copy link
Member

This aims to fix a long-standing audio issue which someone at my local user group brought up.
When interpolating the cutoff frequency of the AudioEffectFilterHighPass towards 1.0, at a certain point the audio becomes unstable until it suddenly stops working and clips (+- 1.0 on both channels).
After investigation I found out that this problem (probably) occurs due to numerical cancelation/inprecision when calculation the coefficients of the biquad filter.
For some reason, the coefficients were of type float while the rest of the code used double.
After increasing the precision, the issue was gone for me. There might be a better solution, but for now this is probably the quickest and safest way to fix it.
Other filter effects which use AudioFilterSW under the hood might benefit from this too.

@Geometror Geometror added this to the 4.4 milestone Jan 30, 2025
@Geometror Geometror requested a review from a team as a code owner January 30, 2025 22:01
@akien-mga
Copy link
Member

Do you have a test project that can be used to reproduce the bug and validate the fix? I suspect such issues may also be system/OS specific so some testing to confirm the fix would be good.

I checked the code a bit, as I was wondering whether other things should be updated from float to double. There's notably the "history" floats in Processor which seemed relevant. I followed the trail a bit, noticed that Processor::process is never used, nor Processor::process_one_interp, and Processor::process_one indeed takes floats from servers/audio/effects/audio_effect_filter.cpp.

So that means in process_one we're now multiplying floats and doubles. I guess that promotes the calculation to double precision before casting back to float in p_sample?

@Geometror Geometror force-pushed the audioeffect-fix-cutout branch from e6d7fa7 to a35c351 Compare January 31, 2025 02:52
@Geometror
Copy link
Member Author

Geometror commented Jan 31, 2025

The audio part of the engine still contains lots of dead and legacy code, e.g. AudioFilterSW::get_response is also unused.
float/double seems to be used rather arbitrarily. I also noticed the history floats, but the computations using those are numerically stable, so it should be fine. However, I'm not opposed to changing those also to double (or all in the filter code), which shouldn't make a difference performance-wise.

I could provide a test project after asking the person for permission tomorrow.

@Geometror
Copy link
Member Author

Here it is. Audio cuts out at around 15s in.
Like you suspected, the problem depends on the platform, hardware, audio processing workload, etc. so it might work fine for you.

Since it's too large for github, you can download it here:
https://bwsyncandshare.kit.edu/s/Jq5CwjTEgenw5QZ

@adamscott
Copy link
Member

Here it is. Audio cuts out at around 15s in. Like you suspected, the problem depends on the platform, hardware, audio processing workload, etc. so it might work fine for you.

Since it's too large for github, you can download it here: https://bwsyncandshare.kit.edu/s/Jq5CwjTEgenw5QZ

I confirm that this PR fixes the issue with the project.

Currently investigating what could be done with this file.

@Repiteo Repiteo merged commit 5da6dea into godotengine:master Feb 11, 2025
19 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Feb 11, 2025

Thanks!

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.

4 participants