Replace wpctl volume control with SDL_mixer VolumeMusic
Remove all PipeWire/wpctl system calls (SetDefaultSinkVolume, listSinkIDs, listSinks, SetAllSinkVolumes, parseSinks, parseSinkLine, Sink struct). Volume is now managed entirely through SDL_mixer's VolumeMusic(), making audio fully system-agnostic. Changes: - mixer.go: delete ~170 lines of wpctl code; add SetVolume() public API using mix.VolumeMusic(math.Round(level * MAX_VOLUME)) - Init/Play/SwitchDevice set volume inline (they already hold the mutex) - Play() now uses stored currentVolume instead of hardcoded MAX_VOLUME - AudioOptions: SetAllSinkVolumes -> SetVolume - mixer_test.go: add TestSetVolume (validation + error path coverage)
This commit is contained in:
@@ -7,6 +7,39 @@ import (
|
||||
"rhemawavetech.com/rhemawave/internal/mixer"
|
||||
)
|
||||
|
||||
func TestSetVolume(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
level float64
|
||||
wantErr bool
|
||||
}{
|
||||
{"zero volume", 0.0, false},
|
||||
{"half volume", 0.5, false},
|
||||
{"max volume", 1.0, false},
|
||||
{"above range", 1.5, true},
|
||||
{"negative", -0.1, true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := mixer.SetVolume(tt.level)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Errorf("SetVolume(%v) = nil, want error", tt.level)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
// For valid input, failure is expected when SDL isn't initialized
|
||||
// (that's fine — we're testing validation, not SDL integration)
|
||||
if err.Error() != "audio mixer not initialized" {
|
||||
t.Errorf("SetVolume(%v) = %v, want 'audio mixer not initialized' or nil", tt.level, err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertVolume(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user