Skip to content

Add: Implement support for loading sounds in Ogg Opus format.#13055

Merged
PeterN merged 5 commits intoOpenTTD:masterfrom
PeterN:opus
Dec 6, 2024
Merged

Add: Implement support for loading sounds in Ogg Opus format.#13055
PeterN merged 5 commits intoOpenTTD:masterfrom
PeterN:opus

Conversation

@PeterN
Copy link
Copy Markdown
Member

@PeterN PeterN commented Nov 3, 2024

Motivation / Problem

Uncompressed .wav files are quite large. Including high quality sounds in basesets and NewGRFs increases the size of these files, increasing download time and size.

If OpenTTD could load sounds with lossy compression then the file sizes could be smaller, or more sounds could be included.

Description

Implement support for Ogg Opus encoded audio files. This format was chosen because it is open and modern, and doesn't suffer some limitations of other formats (something like MP3 adds 25-50ms delay at the start)

This is achieved by breaking out the sound loading code into a provider interface, so that loading of different formats (raw, .wav and .opus) is self-contained.

Audio files are decompressed once on load, and remaining in an uncompressed form in memory until a game is ended or sound packs are changes.

As the framerate window already has a memory size column for AI/GS scripts, this is now used to show the memory used by audio samples. This part is not really necessary and could easily be removed.

This will require changes to catcodec, grfcodec and NML to actually support Ogg Opus sound effects.

This is based the original MP3 version that I wrote in March.

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@PeterN
Copy link
Copy Markdown
Member Author

PeterN commented Nov 3, 2024

Here is an Ogg Opus version of OpenSFX:

opensfx-20240307-opus-ge0a915b6d4.tar.gz

@PeterN
Copy link
Copy Markdown
Member Author

PeterN commented Nov 3, 2024

Comparison of file sizes between .wav and .opus baseset:

File Size
OpenSFX with .wav files 13,291,520
OpenSFX with .opus files 1,443,840

…n memory.

Sounds are loaded into memory on first use, using the SoundLoader interface to support format conversion. Sounds are retained in memory to avoid reloading every time a sound is played.

This deduplicates WAV header parsing between NewGRF and baseset sounds, and will allow different audio formats to be supported.
@PeterN PeterN merged commit 560ee24 into OpenTTD:master Dec 6, 2024
@PeterN PeterN deleted the opus branch December 6, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants