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 an option to decode Ogg Vorbis at load time to save space and have good performance #1144

Closed
jitspoe opened this issue Jun 30, 2020 · 12 comments

Comments

@jitspoe
Copy link

jitspoe commented Jun 30, 2020

Describe the project you are working on: 2.5d Platformer (Fist of the Forgotten)

Describe the problem or limitation you are having in your project: I'd like to use ogg vorbis files for all sounds to keep the file size down, but I don't want to impact runtime performance.

Describe the feature / enhancement and how it helps to overcome the problem or limitation: Decoding ogg files at load would allow the file size to remain small and not decoding in realtime will allow the performance to be better when playing lots of sounds.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams: This would probably make the most sense as an import checkbox. Like [] Decode sample into memory on load.

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?: Not sure if this can be done as an add-on. Seems pretty engine-level.

@Calinou Calinou changed the title Option to decode ogg vorbis at load time to save space and have good performance. Option to decode OGG Vorbis at load time to save space and have good performance Jun 30, 2020
@Calinou Calinou changed the title Option to decode OGG Vorbis at load time to save space and have good performance Option to decode Ogg Vorbis at load time to save space and have good performance Jun 30, 2020
@TheDuriel
Copy link

What do you estimate would be the savings in disk space comparing OGG and WAV for sub 3 second long sounds. Assuming reverb tails are already stripped.

@Calinou
Copy link
Member

Calinou commented Jul 13, 2020

@jitspoe Have you measured the performance impact of using Ogg Vorbis sounds in your project? Is it significant enough to warrant doing this?

Maybe you can use Ogg Vorbis for music and ambient tracks only and keep using WAV for the rest. The compression gains are generally not as interesting in shorter samples.

@jitspoe
Copy link
Author

jitspoe commented Jul 13, 2020

@TheDuriel It looks like the wav files are about 4-8x larger for short sounds like footsteps. I actually have a bunch of larger ambient sounds like wind and rain and thunder that I'd like to layer together.

@Calinou I'm not sure what the perf hit for ogg vorbis is. I haven't actually done a profile. I was just basing this off of the documentation: https://docs.godotengine.org/en/stable/tutorials/audio/audio_streams.html I'd be interested to test on mobile, but I haven't gotten a build for that, yet. I'd like to have possibly 20+ sounds layered, which I have a feeling would start impacting performance on low-end hardware. If it doesn't have a significant impact, the documentation should probably be updated. :)

@jitspoe
Copy link
Author

jitspoe commented Apr 13, 2021

I created a test project with 600 stream players that can switch between wav and ogg. The audio thread has spikes at a regular interval at around 17-19ms for wav and 80-85 for ogg (where it's doing the mixing, I assume). In short, ogg is about 4-5x slower than wav. Not sure if that'll have much of an impact in a realistic scenario, since it's already in its own thread, unless cores are limited. Once you hit a certain threshold, though, the sound gets choppy.

Here's the project:
Test Ogg Performance.zip

Space bar switches between ogg and wav streams.

@Calinou
Copy link
Member

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.

@Calinou Calinou changed the title Option to decode Ogg Vorbis at load time to save space and have good performance Add an option to decode Ogg Vorbis at load time to save space and have good performance Sep 9, 2022
@jitspoe
Copy link
Author

jitspoe commented Jan 25, 2023

The Rocket Bot Royale post mortem mentions perf issues decoding a bunch of ogg files and implemented a "Decode once" option, which I think is a great (and tested) solution. godotengine/godot#62291

Also just realized I never answered TheDuriel's question. I have a mix of ogg and wav files for footstep sounds. Wav files average around 40KB. Ogg vorbis files average around 8KB, so that's about a 5x difference on really short sounds. Probably a lot more on longer sounds with quiet sections that can benefit from VBR and such. Also depends on the compression rate.

@Kersoph
Copy link

Kersoph commented Aug 16, 2023

I think that can be a great feature and I was searching for ways to get something like that for me as well and found this proposal. I have players with a bit weaker CPU where the audio could not keep up the pace at some locations (audio seems to be single core, so more cores does not really help) with around 80-120 AudioStreamPlayer 2D/3D tested on Godot 3.5. I'm currently reducing the number but as well reduce the decoding load.

I've hit the wall on my machine with ogg with around 520 AudioStreamPlayer3D at 4.4GHz CPU where it takes up 100% of one core without any special effects. But as realistically the CPU is busy with other things as well and may has a lower CPU frequency, only a part of this is possible I think.
On my machine wav Ima-ADPCM takes around 5x less CPU than ogg (quality 2).
Pause or stop the stream reduces the cpu load practically to 0.

With this proposal the advantages of small disk space and low decoding load for frequent sounds can be combined on the cost of RAM.

@sergeevabc
Copy link

sergeevabc commented Feb 14, 2024

Dear @jitspoe, why did you choose Vorbis over the next development of the same team, Opus? And are you familiar with the relatively new lossy QOA format? Its author, @phoboslab, emphasizes the decoding speed, especially in games.

It decodes audio 3x faster than Ogg-Vorbis, while offering better quality and compression (278 kbits/s for 44khz stereo) than ADPCM. The reference en-/decoder fits in about 400 lines of C. (Official website)

A possible application for QOA is games, where you need to play dozens of audio files immediately. I haven't done any formal benchmarks, but with a simple time on the command line QOA encodes 10x faster and decodes 7x faster than Opus. (Hacker News)

@Calinou
Copy link
Member

Calinou commented Feb 14, 2024

@sergeevabc Godot lacks support for Opus, hence this proposal focusing on Vorbis only.

Regarding QOA support, see #7599 where it was mentioned in passing. It's more of a replacement for IMA-ADPCM compression (which is simplistic but low-quality) than complex lossy formats like Vorbis and Opus.

@DeeJayLSP
Copy link

DeeJayLSP commented Feb 19, 2024

Regarding QOA support, see #7599 where it was mentioned in passing.

Just a note: my statement about it having a better quality than Vorbis at max bitrate was wrong. It's actually comparable to it on lower bitrates like 96kbps with a bit of noise.

Regardless, it's still much better than IMA-ADPCM and the quality loss is pretty acceptable, unless you're an audiophile listening with Hi-Fi headphones.

@DeeJayLSP
Copy link

DeeJayLSP commented May 2, 2024

Regarding QOA support,

And it's supported now, for those interested :)

While it does not add the "option to decode Ogg Vorbis at load time", it is something to "save space and have good performance".

@Calinou
Copy link
Member

Calinou commented May 6, 2024

Closing, as QOA support effectively supersedes this by providing lossy audio compression with very low CPU requirements (lower than MP3). QOA is most suited to sound effects and ambience, but it can technically be used for music as well (although Ogg Vorbis remains a better tradeoff here).

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

6 participants