Improve sound initialization.

This commit is contained in:
Storm Dragon committed 2026-10-28 18:17:06 -04:00
1 parent 46dc520854
commit b887f6ea95
4 files changed
+14 -11

No files matched your search

+5 -3
View File
@@ -75,9 +75,11 @@ server or ALSA device. The [PulseAudio](tools/configure_pulse.sh) and
[PipeWire](tools/configure_pipewire.sh) configuration scripts are included for
systems that need root audio access.
The default sound driver tries the user session first, then the system-wide
PulseAudio-compatible socket at `/run/pulse/native`, including when provided by
PipeWire. Set `PULSE_SERVER` to select a different socket or server explicitly.
The default sound driver tries the user session first, then `/tmp/pulse.sock`
created by the PipeWire configuration script, then the system-wide
PulseAudio-compatible socket at `/run/pulse/native`. Set `PULSE_SERVER` to select
a different socket or server explicitly. The sound driver does not read
PulseAudio's `client.conf`.
Speech output uses Speech Dispatcher's own audio configuration.
### X11 terminal
+2 -2
View File
@@ -29,8 +29,8 @@ import (
func open_pulse(s *Service, _ string) error {
options := []pulse.ClientOption{pulse.ClientApplicationName("Fenrir sounds"), pulse.ClientTimeout(500 * time.Millisecond)}
// Try the invoking user's session, then the system-wide service, unless
// PULSE_SERVER explicitly selects a server.
// Try the invoking user's session, then the bundled PipeWire helper's
// socket and the system-wide service, unless PULSE_SERVER selects a server.
options = append(options, pulse.ClientServerString(Server(os.Getenv("PULSE_SERVER"), os.Getenv("SUDO_UID"))))
client, err := pulse.NewClient(options...)
if err != nil {
+4 -3
View File
@@ -86,8 +86,9 @@ func (s *Service) Set_volume(volume float64) {
s.volume.Store(math.Float32bits(float32(volume)))
}
// Server returns PulseAudio protocol addresses in connection order. PipeWire's
// PulseAudio service can expose the system-wide /run/pulse/native socket.
// Server returns PulseAudio protocol addresses in connection order. The bundled
// PipeWire helper exposes /tmp/pulse.sock for console clients; system-wide
// PulseAudio services can expose /run/pulse/native.
// The client library tries each address, including after authentication errors.
func Server(explicit, sudoUID string) string {
if explicit != "" {
@@ -99,7 +100,7 @@ func Server(explicit, sudoUID string) string {
} else if runtimeDir == "" {
runtimeDir = fmt.Sprintf("/run/user/%d", os.Getuid())
}
return "unix:" + filepath.Join(runtimeDir, "pulse/native") + " unix:/run/pulse/native"
return "unix:" + filepath.Join(runtimeDir, "pulse/native") + " unix:/tmp/pulse.sock unix:/run/pulse/native"
}
// Play only replaces a mailbox pointer. Startup has its own slot so initial
+3 -3
View File
@@ -270,11 +270,11 @@ func TestSoundServerFollowsExplicitAndSudoSession(t *testing.T) {
if got := Server("unix:/tmp/example-pulse", "1000"); got != "unix:/tmp/example-pulse" {
t.Fatal(got)
}
if got := Server("", "1000"); got != "unix:/run/user/1000/pulse/native unix:/run/pulse/native" {
if got := Server("", "1000"); got != "unix:/run/user/1000/pulse/native unix:/tmp/pulse.sock unix:/run/pulse/native" {
t.Fatal(got)
}
for _, uid := range []string{"", "invalid", "../other"} {
if got := Server("", uid); got != "unix:/run/user/2000/pulse/native unix:/run/pulse/native" {
if got := Server("", uid); got != "unix:/run/user/2000/pulse/native unix:/tmp/pulse.sock unix:/run/pulse/native" {
t.Fatal(got)
}
}
@@ -282,7 +282,7 @@ func TestSoundServerFollowsExplicitAndSudoSession(t *testing.T) {
func TestSoundServerWithoutRuntimeDirectoryUsesCurrentUserAndSystemFallback(t *testing.T) {
t.Setenv("XDG_RUNTIME_DIR", "")
want := fmt.Sprintf("unix:/run/user/%d/pulse/native unix:/run/pulse/native", os.Getuid())
want := fmt.Sprintf("unix:/run/user/%d/pulse/native unix:/tmp/pulse.sock unix:/run/pulse/native", os.Getuid())
if got := Server("", ""); got != want {
t.Fatalf("Server() = %q, want %q", got, want)
}