EQAditu / AdvancedCombatTracker

Advanced Combat Tracker
https://advancedcombattracker.com
116 stars 25 forks source link

ActGlobals.oFormActMain.TTS does not reset audio volume #60

Open xpdota opened 1 year ago

xpdota commented 1 year ago
  1. Open ACT, navigate to sound settings, set Wav Vol to 20% and TTS Vol to 100%
  2. Call ActGlobals.oFormActMain.TTS("something"), observe it is at full volume
  3. Call ActGlobals.oFormActMain.PlaySound("some_file.wav"), observe it has the correct reduced volume
  4. Call the TTS method again - now, it still has the reduced volume from WAV (and the windows volume mixer still shows the reduced volume)

This also happens if you call ActGlobals.oFormActMain.PlaySoundMethod(file, volume), and the issue persists until you either go into volume mixer and reset the level manually, or you call PlaySoundMethod with a new volume level.

Reading through PlaySound, the if statement involving "sapi.wav" makes it seem like this should work.

EQAditu commented 1 year ago

The real problem is that the WMP API is the thing that is changing the mixer volume. When I started using it, I thought it had an internal mixer and did not realize it modified the Windows mixer for the host program. This should have the side effect of changing the volume of one sound mid-way through if the types change. Obviously this isn't great.

I'm suspicious that this reported issue is also related to how WMP alters the Windows Mixer and does it haphazardly. Other sound APIs do not change the host process mixer volume.

I imagine using TTS in SAPI direct mode should not have this bug occur because WMP will no longer be called for TTS at all.

xpdota commented 1 year ago

I think this bug wouldn't happen in SAPI mode regardless because of this:

        if (pszSound.EndsWith("sapi.wav"))
          this.PlaySoundMethod(pszSound, this.opSound.tbarTtsVol.Value);
        else
          this.PlaySoundMethod(pszSound, this.opSound.tbarWavVol.Value);

If this works how I think it does, TTS is supposed to set the volume to the selected TTS volume setting, but this code path is only used when playing TTS via SAPI?

EQAditu commented 1 year ago

Direct SAPI does not use PlaySound() at all... so WAV files would go to the else.

EQAditu commented 1 year ago

This and other problems would be fixed if ACT no longer used WMP as the default sound engine. ACT does not change the volume mixer, the WMP API does.

WMP API was attractive because it was preinstalled on every version of Windows. There may be newer options that are similarly ubiquitous, but I would have to do a bit of research.