Skip to content

Audio refactor#3678

Merged
ZehMatt merged 33 commits intoOpenLoco:masterfrom
ZehMatt:audio-refactor
Mar 30, 2026
Merged

Audio refactor#3678
ZehMatt merged 33 commits intoOpenLoco:masterfrom
ZehMatt:audio-refactor

Conversation

@ZehMatt
Copy link
Copy Markdown
Contributor

@ZehMatt ZehMatt commented Mar 25, 2026

Quite a big refactor and this has been on my list for quite some time, here are the key changes:

  • New standalone audio library with handle-based API
  • Independent volume channels: Master, Music, Effects, Vehicles, UI, Ambient
  • Per-channel volume sliders in Options window, saved to config
  • Reverb effect for vehicles in tunnels
  • Vehicle audio handles stored on entities, no more channel limits
  • Viewports following a vehicle always play its sound, before sometimes it could use the primary viewport even when its dead center on the secondary one.
  • Split audio code into Audio.cpp, VehicleAudio.cpp, AmbientAudio.cpp, Music.cpp

The options window is quite frankly a bit ugly but I think the juke-box is also out of place there, we should make the juke-box just a standalone window at some point.
image

Also I wasn't sure if I should make the reverb an additional option, I was also thinking about adding a small reverb in general to most sounds as all of it is viewed from above, would give it a nice spatial sense. Something to keep in mind is that due to the limit being removed it might get loud when a lot of vehicles are visible on screen, we either keep the arbitrary limit or we slightly lower the volume the more of them are active, this needs some testing.

@LeeSpork
Copy link
Copy Markdown
Contributor

The reverb feature appears to cause the game to crash if it is built with the Debug solution configuration.
There is a debug assertion failed pop up when the game is loading, and the game stops the moment any audio is going to play (including the title music).
This does not happen if I disable the reverb by removing the line of code that sets _reverbAvailable. It also does not happen if I build the game using the Release configuration.

@LeeSpork
Copy link
Copy Markdown
Contributor

When a vehicle2 is imported, its sound.audioHandle is 0. updateVehicleNoise() then destroys any audio that was using audio handle 0. Thus, when the title sequence is first loaded, the title music gets killed.

@ZehMatt
Copy link
Copy Markdown
Contributor Author

ZehMatt commented Mar 25, 2026

This should address all the comments, the assertion is an OpenAL bug which is already fixed upstream so we have to wait for a release and updated vcpkg port, since its only a debug assertion I guarded the reverb code under NDEBUG, the code is technically functional and since we ship Release builds this has to do for now.

@ZehMatt ZehMatt added changelog Requires a changelog entry audio Music or sound related labels Mar 25, 2026
@LeftofZen
Copy link
Copy Markdown
Contributor

all but the bottom thumb are cut off on the bottom pixel - need more vertical spacing between sliders:
image

@LeftofZen
Copy link
Copy Markdown
Contributor

this was always a pet peeve of mine - but lowering the slider to the lowest setting does not mute the channel as expected. this is vanilla behaviour because the sliders directly work with decibels instead of a linear range of 0-100 (or whatever). would be great to fix that if possible here

@LeftofZen
Copy link
Copy Markdown
Contributor

i think the tooltip colours can be improved:
image

@ZehMatt
Copy link
Copy Markdown
Contributor Author

ZehMatt commented Mar 25, 2026

i think the tooltip colours can be improved: image

The last commit should do that

this was always a pet peeve of mine - but lowering the slider to the lowest setting does not mute the channel as expected. this is vanilla behaviour because the sliders directly work with decibels instead of a linear range of 0-100 (or whatever). would be great to fix that if possible here

Hmm, will have look into it.

@LeeSpork
Copy link
Copy Markdown
Contributor

Vehicle sounds now continue playing infinitely if a vehicle is on your screen and you load a game, and when the title sequence loops.

@LeeSpork
Copy link
Copy Markdown
Contributor

Less importantly, vehicle sounds also now play when the load game browse prompt is open, which they did not in 26.02 (This one was already present before my first reviews to be clear)

@ZehMatt ZehMatt force-pushed the audio-refactor branch 2 times, most recently from ff9c99e to c80bfd7 Compare March 26, 2026 01:19
@LeeSpork
Copy link
Copy Markdown
Contributor

I see you fixed the vehicle and ambient noises for PromptBrowseWindow and PromptOkCancel, but I noticed that you have missed (at least):

  • PromptSave (the 'are you sure you want to quit' prompt, which can be difficult to see especially if you have autosaving enabled), and
  • ObjectSelectionWindow (as it nowdays pauses the game when opened during play mode).

I suggest a more robust solution would probably be to stop the sounds when any pause flag is set (Related: #3185).

@LeeSpork
Copy link
Copy Markdown
Contributor

Vehicle sounds now continue playing infinitely if a vehicle is on your screen and you load a game, and when the title sequence loops.

Looks (well, sounds) that this has been fixed 😄

@LeeSpork
Copy link
Copy Markdown
Contributor

Difference from master: If the selected sound device is not plugged in when you start the game, the game now fails to open the sound device instead of incorrectly(?) playing audio from a different device. This fixes #3632 (maybe not in an ideal way, but this is probably not a priority anyway).

Also fixes a small bug that I don't think an issue was made for, where the dropdown could display "Default sound device" when it shouldn't, and look bugged when partially invalidated.

@ZehMatt
Copy link
Copy Markdown
Contributor Author

ZehMatt commented Mar 28, 2026

I see you fixed the vehicle and ambient noises for PromptBrowseWindow and PromptOkCancel, but I noticed that you have missed (at least):

  • PromptSave (the 'are you sure you want to quit' prompt, which can be difficult to see especially if you have autosaving enabled), and
  • ObjectSelectionWindow (as it nowdays pauses the game when opened during play mode).

I suggest a more robust solution would probably be to stop the sounds when any pause flag is set (Related: #3185).

I fixed this, the issue was not of a missing pauseSound call but the update function ignoring the paused state. I will leave this now as is, it should work correctly. I want to refactor the entire state flow at some point, its pretty spaghetti currently, things are happening all over the place.

If that is the last of the issues I will commit the changelog entries.

Copy link
Copy Markdown
Member

@AaronVanGeffen AaronVanGeffen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The individual volume sliders appear to work as expected. This is a really nice change!

I've taken the liberty to tweak the window a little, separating the group boxes and using a two-column layout. I think this makes for a more balanced UI.

Just needs a changelog entry for the channels and reverb effects. Other than that, I think this is good to go!

Image

@AaronVanGeffen AaronVanGeffen added this to the v26.02+ milestone Mar 30, 2026
@ZehMatt ZehMatt merged commit bd35fe3 into OpenLoco:master Mar 30, 2026
14 checks passed
@ZehMatt ZehMatt deleted the audio-refactor branch March 30, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audio Music or sound related changelog Requires a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants