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

Add a project setting to configure the audio resampling algorithm #2298

Closed
Calinou opened this issue Feb 16, 2021 · 6 comments
Closed

Add a project setting to configure the audio resampling algorithm #2298

Calinou opened this issue Feb 16, 2021 · 6 comments

Comments

@Calinou
Copy link
Member

Calinou commented Feb 16, 2021

Describe the project you are working on

The Godot editor 🙂

Describe the problem or limitation you are having in your project

Godot's audio resampling algorithm is currently hardcoded and there is no way to change it.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

There are a few reasons to change the audio resampling algorithm used in a game:

  • Improve audio quality for sounds that have a low sample rate (< 44 kHz).
  • Get a "punchier" feeling for low-sample rate sounds in retro games.
  • Decrease CPU usage when many sounds are playing (only relevant on low-power machines like the Raspberry Pi and perhaps mobile).

Here's an example with Freedoom's shotgun sound played with nearest resampling, then cubic resampling, then 23th order sinc resampling:

freedoom_shotgun_sound_resampler_comparison.mp4

Of course, nothing prevents you from using nearest-neighbor resampling in your DAW then exporting the sample in 44 kHz or more, but doing so will increase file size. This can be a problem when targeting mobile/web platforms where distribution size needs to be kept as small as possible.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Add a project setting to configure the audio resampling algorithm used by Godot. I think having an option to use nearest-neighbor resampling in addition to the default high-quality mode would be a good start already.

godotengine/godot#46086 is working on adding a new audio resampling mode which is of higher quality but also more demanding than the current cubic resampler. Therefore, we may need to keep the Cubic option available as well.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, as this resampling is done in C++ in the audio engine.

Is there a reason why this should be core and not an add-on in the asset library?

See above.

@troy-lamerton
Copy link

troy-lamerton commented Jul 6, 2021

Maybe the resampling algorithm needs improvement? It should be possible to have a one-size-fits-all resampling algorithm.

In Unity, audio assets are resampled quite well, and I don't choose any options for this.

Can you point out the hardcoded resampling code? Didn't see it in a quick search

EDIT: this is the hardcoded algorithm?

https://github.com/godotengine/godot/blob/8f7f5846397297fff6e8a08f89bc60ce658699cc/servers/audio/audio_rb_resampler.cpp

@Calinou
Copy link
Member Author

Calinou commented Jul 6, 2021

Maybe the resampling algorithm needs improvement? It should be possible to have a one-size-fits-all resampling algorithm.

This proposal is effectively stating that there is no "one size fits all" resampler. It all depends on your needs, performance constraints and even personal preference 🙂

EDIT: this is the hardcoded algorithm?

https://github.com/godotengine/godot/blob/8f7f5846397297fff6e8a08f89bc60ce658699cc/servers/audio/audio_rb_resampler.cpp

AudioRBResampler only seems to be used within VideoPlayer. The AudioStreamPlayer nodes have their own resamplers (linear for WAV, "4 point, 4th order optimal" for OGG and MP3). See #2299.

@troy-lamerton
Copy link

So this proposal asks for an option to play an audio asset differently. Change an option to tweak the sound of the original asset.

@Calinou Am I understanding this correctly?

Resampling algorithms are complex. I would advise against touching this if there is an alternative to achieve what you would like.

@Calinou
Copy link
Member Author

Calinou commented Jul 24, 2021

Idk what options Godot already has for this.

Godot doesn't expose a way to configure the resampler; there is one one and it's hardcoded. However, I'm not sure if Unity and UE4 expose a way to change the resampling algorithm either.

The option I'm proposing here is global to the project. It's not per-sample or per-audio bus.

@troy-lamerton
Copy link

This proposal is effectively stating that there is no "one size fits all" resampler. It all depends on your needs, performance constraints and even personal preference 🙂

Can you elaborate on this? I don't understand this.

Why would you want to distort all your audio assets? They should sound the same in-game as when you listen to them in your music player.

@Calinou
Copy link
Member Author

Calinou commented Jul 24, 2021

Why would you want to distort all your audio assets? They should sound the same in-game as when you listen to them in your music player.

This is about improving perceived sound quality for retro games. In my experience, sounds with a sample rate below 44.1 kHz will often sound better when using a low-quality resampler compared to a high-quality one. There are exceptions here and there, but this is what I noticed on my hardware at least.

That said, reduz told me that he'd prefer users to modify the sounds in question in a DAW to resample them, then export the sounds in 44.1 kHz. This isn't ideal in terms of file size, but it's the simpler option in terms of engine implementation. Therefore, I'll close this proposal as it's unlikely to be implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants