fix: restore SDL volume to MAX after device switch

Remove dead 'currentVolume' variable that was never written to, causing
SwitchDevice to always restore volume to 0 after switching audio devices.

- Remove currentVolume from package state
- SwitchDevice now sets mix.MAX_VOLUME after reopening device
- GetVolume128 now queries SDL directly instead of reading stale variable
- Add unit tests for parseSinks, parseSinkLine, and ConvertVolume
- Add changelog.txt tracking all audio bug fixes
This commit is contained in:
NeilClack
2026-07-10 13:56:06 -05:00
parent fd10201f75
commit 2bcb36669f
4 changed files with 221 additions and 10 deletions
+6 -10
View File
@@ -23,10 +23,9 @@ var (
deviceOpen bool
deviceName string
currentMusic *mix.Music
currentPath string
currentLoops int // 0 = once, -1 = forever
currentVolume int // 0..128, defaults to MAX_VOLUME
currentMusic *mix.Music
currentPath string
currentLoops int // 0 = once, -1 = forever
// Config knobs (could be made public or read from your config)
defaultFreq = 48000
@@ -411,11 +410,8 @@ func SwitchDevice(newName string) error {
wasPlaying := mix.PlayingMusic()
savedPath := currentPath
savedLoops := currentLoops
savedVolume := currentVolume
// Stop and release current music before reopening device
if wasPlaying {
}
mix.HaltMusic()
if currentMusic != nil {
currentMusic.Free()
@@ -441,8 +437,8 @@ func SwitchDevice(newName string) error {
return err
}
// Restore volume
mix.VolumeMusic(savedVolume)
// Restore volume to MAX after reopening device (matches Play() behavior)
mix.VolumeMusic(mix.MAX_VOLUME)
// Optionally resume previous track if there was one
if wasPlaying && savedPath != "" {
@@ -471,7 +467,7 @@ func SwitchDevice(newName string) error {
func GetVolume128() int {
mu.Lock()
defer mu.Unlock()
return currentVolume
return mix.VolumeMusic(-1)
}
// Shutdown fully tears everything down. Call at app exit.