FS#5807 - Sound effect volume is too low when the music volume is low.

Attached to Project: OpenTTD
Opened by Jaap (Jaap) - Monday, 18 November 2013, 12:46 GMT
Type Bug
Category Core
Status New
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version 1.3.3-RC1
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


I used Windows 7 x64, but I think this issue is also reproducible at other operating systems.

Steps to reproduce this issue:
1. Start a new game and open the Jazz Jukebox.
2. Turn on the music (play).
3. Set the Effects Volume to max.
4. Set the Music Volume to almost the minimum position.
5. Open the Landscaping toolbox and get the Demolish tool.
5. Demolish some items in the game, and listen to the sound effects.

You'll hear almost nothing because the Music Volume is set to low. When you increase the Music Volume, and demolish some items, the sound effects hearable now.

I did some research and saw that the Windows Volume Mixer for OpenTTD is synchronized with the Music Volume control in the Jazz Jukebox. The sound effect volume cannot be set louder, so the only way to hear the sound effects is to turn off the music.

In my opinion the Music Volume control in the Jazz Jukebox should not affect the value of the Windows Volume Mixer. The Music Volume and Effects Volume should be controlled independently of each other.

And an other small bug:
1. Turn off the music.
2. Change the value of the Music Volume.
3. Turn on the music.

The volume change at step 2 wasn't executed.
This task depends upon

Comment by LuHa (munhyunsu) - Tuesday, 19 November 2013, 04:22 GMT
In linux, i can't change music volume.

Known-bugs: At  FS#4416 (
Can't change volume inside OpenTTD [ FS#4416 ]
Some backends do not provide a means to change the volume of sound
effects or music. The mixing of music and sound is left to external
libraries/the operating system we can't handle the volume control
in OpenTTD. As a result you can't change the volume inside OpenTTD
for backends such as SDL; just use the volume control provided by
your operating system.

may be it seems to similary.
Comment by Niels M H (nielsm) - Tuesday, 06 March 2018, 18:29 GMT
This patch should fix the issue. Instead of using the master volume control, it implements a "tool" that intercepts all MIDI messages and adjusts their velocity (volume) based on the controller setting.
It's not a perfect fix, since now the volume changes aren't instant, especially noticeable in some long notes like in "Easy Driver". It also affects the dynamics of the music further, and will probably completely silence some already soft notes.

Code quality-wise, I'll be the first to admit this isn't a good implementation of a COM object, but I believe it shouldn't cause issues in practice.

It may also be possible to implement volume control via a MIDI SysEx message instead, which would solve all the above problems if it actually works.
Comment by Niels M H (nielsm) - Tuesday, 06 March 2018, 21:06 GMT
Here is a better patch than the above, it's based on adjusting per-channel volume control messages instead of note-on velocities. This makes it act instantly and on already-playing notes.
The patch currently has some issues with uneven music playback if the volume slider is dragged continuously.

This is tested to work with both the Microsoft GM soft-synth in Windows 10, and with a hardware MIDI synth.
Comment by Niels M H (nielsm) - Sunday, 11 March 2018, 15:26 GMT
Here's yet another slightly updated version of the patch. It's intended to be applied before the patches in FS#6684 and after FS#6683.