-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
WAV importer: Use cubic interpolation on resampler #89071
Conversation
One last thing: But then I resampled the same way with libsamplerate's best sinc interpolation, and the result had a similar distortion too (when playing inside Godot), therefore not caused by this change but by Godot's own AudioStreamPlaybackWAV resample (because playing 36000Hz within AudioStreamPlaybackResampled sounds fine, see #58216). I assume this is the most precise we can have. |
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.
During our recent discussion in RocketChat, we discovered that the new code we were considering is identical to Math::cubic_interpolate()
, which is already present in our codebase. This has led us to reconsider the use of libresample
.
I propose the following test plan:
- Record samples with the current code and after the implementation of the new code.
- Provide alternative methods for verifying the audio, either as a recording or as part of a project.
This will allow us to compare the output and verify whether the new piece of code are indeed better.
We currently do not have an active audio team. However, contributions from anyone in the community would be greatly appreciated. If you're interested in helping out with this issue, please feel free to get involved.
Thanks! |
Just realized this could be simplified by passing |
I found this while playing around with ResourceImporterWAV's resampling procedure.
After importing one of Kenney's Interface Sounds (specifically confirm2, converted to WAV) with a mix rate at 32000Hz, I noticed a significant distortion on the sound from the original.
I thought that was a side effect of downsampling, and decided to play around with the resampling code (because why not, maybe I could accidentally find a way to improve it). At one point however, I found a cubic interpolation function online that was different than the one in the importer, and decided to replace the one in resampling with it out of curiosity.
With this new cubic interpolation, the distortion became much less noticeable after reimporting. There is still a bit of distortion, the quality isn't anywhere close to libsamplerate's sinc interpolators, which would be the ideal approach for an importer, but it's still better than before.
In the end, I accidentally found a way of improving it. Since it's just 3 lines of code (+ one comment) I decided to submit.
Due to simplicity, I think this is cherrypickable for 3.x.
Edit: after finding the same algorithm was already used in AudioStreamPlaybackResampled, I decided to copypaste it into ResourceImporterWAV.
Edit 2: The algorithm used in AudioStreamPlaybackResampled was an adaptation from
Math::cubic_interpolate()
to be used with AudioFrames. Changed to use that instead.In few words: all this PR does is replacing the resample interpolation in ResourceImporterWAV with
Math::cubic_interpolate()
, which yields much better results.