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

Remove low-quality/limited IMA-ADPCM compression from the WAV importer #4264

Open
Calinou opened this issue Mar 23, 2022 · 7 comments
Open
Labels
breaks compat Proposal will inevitably break compatibility topic:audio

Comments

@Calinou
Copy link
Member

Calinou commented Mar 23, 2022

Related to #1144.

Describe the project you are working on

The Godot editor 🙂

Describe the problem or limitation you are having in your project

Godot supports several audio formats:

  • WAV (uncompressed, or lossy compression with IMA-ADPCM)
  • MP3 (lossy compression)
  • Ogg Vorbis (lossy compression, higher quality than MP3)

WAV supports lossy compression via IMA-ADPCM, which is a compression technique originally developed in the 1970s:

image

Unfortunately, this compression is considered very low-quality by today's standards, with Ogg Vorbis or even MP3 performing significantly better in terms of quality. Unlike Ogg Vorbis and MP3, IMA-ADPCM compression also doesn't offer any way to balance between file size and quality with a bitrate control.

In Godot, IMA-ADPCM compression also doesn't support playing audio from a given position.

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

Remove the IMA-ADPCM encoder and its associated import option in the WAV import dock, but keep the IMA-ADPCM decoder for run-time WAV loading once it's implemented. There are still WAV files out there with IMA-ADPCM compression, and loading those should remain supported.

Any CPU released in the last 12 years can decode several Ogg Vorbis or MP3 streams at the same time (even on mobile), so IMA-ADPCM's comparatively faster decoding speed is not relevant anymore.

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

Projects upgrading from Godot 3.x will still be able to use WAV files (including IMA-ADPCM compressed ones). However, if the Compression option was enabled and the original WAV files are uncompressed, those files will no longer be imported with compression enabled.

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

No.

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

This is about removing an option from a core importer.

This proposal is about avoiding "footguns" in terms of audio quality, by steering users towards higher quality audio compression options when needed.

@Calinou Calinou added this to the 4.0 milestone Mar 23, 2022
@reduz
Copy link
Member

reduz commented Mar 23, 2022

IMA ADPCM is super cheap to decode and resample, orders of magnitude more than mp3 or ogg. Not a good idea to remove.

You can have hundreds of these decoding at no cost.

@Calinou Calinou added the breaks compat Proposal will inevitably break compatibility label May 10, 2022
@USBDongleGoblin
Copy link

USBDongleGoblin commented Jun 28, 2022

I think a better idea is to just improve/fix/replace the encoder & decoder all together. No (or significantly less) compatibility breaking here.

For some reason Godot's encoder (atleast in versions up to and including 3.4.4) in my experience produces results ranging from fine/acceptable, to "this literally sounds like the file was corrupted in export." Some sampling rates tend to sound 8 times worse than they should too (I.E. 32khz sounds much more like 16khz to me).

If you export a file with IMA-ADPCM from Audacity, and compare it to a file encoded via Godot, the file from Audacity is going to sound much better.

I've included a sample project (using a voice line from Half-Life 2 if that's ok) which shows what I'm talking about (although believe it or not, this is one the less egregious instances I've encountered. If I find a sound that causes this, I'll share it). At the start of the IMA-ADPCM encoded sounds there is some very obvious popping.

I've also included some files exported from Audacity to show how the files encoded by Godot should probably sound much more like.

adpcm sucks.zip

adpcm DOESN'T suck.zip

I am also wondering if it might be a good idea to basically just use a different ADPCM format altogether (maybe even a custom one lol).

@Calinou
Copy link
Member Author

Calinou commented Jun 29, 2022

reduz recently suggested that we look into adding support for FLAC decoding. This would provide the same quality as uncompressed WAV, but with smaller file sizes. This would also benefit games that can load user-provided music (as FLAC has been increasingly replacing MP3 in people's local music libraries). There's a BSD0-licensed library for it: https://github.com/jprjr/miniflac

I don't know how much CPU FLAC decoding requires though – probably more than IMA-ADPCM, but maybe less than Ogg Vorbis?

@Calinou
Copy link
Member Author

Calinou commented Sep 9, 2022

Note that lossy WAV is an alternative that can be explored if Ogg Vorbis or even MP3 decoding are too expensive in your project. It's compatible with any program that can read WAV files, without requiring dedicated support.

@caimantilla
Copy link

I think a better idea is to just improve/fix/replace the encoder & decoder all together. No (or significantly less) compatibility breaking here.

For some reason Godot's encoder (atleast in versions up to and including 3.4.4) in my experience produces results ranging from fine/acceptable, to "this literally sounds like the file was corrupted in export." Some sampling rates tend to sound 8 times worse than they should too (I.E. 32khz sounds much more like 16khz to me).

If you export a file with IMA-ADPCM from Audacity, and compare it to a file encoded via Godot, the file from Audacity is going to sound much better.

I've included a sample project (using a voice line from Half-Life 2 if that's ok) which shows what I'm talking about (although believe it or not, this is one the less egregious instances I've encountered. If I find a sound that causes this, I'll share it). At the start of the IMA-ADPCM encoded sounds there is some very obvious popping.

I've also included some files exported from Audacity to show how the files encoded by Godot should probably sound much more like.

adpcm sucks.zip

adpcm DOESN'T suck.zip

I am also wondering if it might be a good idea to basically just use a different ADPCM format altogether (maybe even a custom one lol).

I just thought it might be because the audio is unfiltered, and that's indeed the case. The encoding is fine, it's a bug.
I tested by using IMA-ADPCM compression on a 44.1khz song. With my system sound set to 48khz, it sounds awful, but with the system sound set to 44.1khz (so no resampling), it sounds totally fine.
Godot uses Cubic resampling for all other formats, doesn't it? I even tried using zero order hold for the same track in Foobar2000, it sounds almost identical (sans the actual compression, so a little better).

Anyways, sorry for rambling, my final comment is that this leads to a slightly cleaner sound when max rate is set to 24khz than off.
I think that the audio filter should be an import option if possible, if not then just fix IMA-ADPCM to use cubic.

@aaronfranke aaronfranke removed this from the 4.0 milestone Feb 24, 2023
@unfa
Copy link

unfa commented Feb 24, 2023

If FLAC import was added, I'd use that instead of WAV just to save space in the game repository.

@fire
Copy link
Member

fire commented Aug 4, 2023

@unfa I posted godotengine/godot#80160 pull request for FLAC import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaks compat Proposal will inevitably break compatibility topic:audio
Projects
None yet
Development

No branches or pull requests

7 participants