diff --git a/app/src/main/assets/pulseaudio.tzst b/app/src/main/assets/pulseaudio.tzst index 3d52e11413..388ea8933b 100644 Binary files a/app/src/main/assets/pulseaudio.tzst and b/app/src/main/assets/pulseaudio.tzst differ diff --git a/app/src/main/java/com/steamdeck/launcher/MainActivity.kt b/app/src/main/java/com/steamdeck/launcher/MainActivity.kt index 78e97c3043..7c35418067 100644 --- a/app/src/main/java/com/steamdeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/MainActivity.kt @@ -100,6 +100,7 @@ class MainActivity : ComponentActivity() { private var prootNoSeccomp by mutableStateOf(false) private var phantomWarning by mutableStateOf(null) private var directAudio by mutableStateOf(false) + private var clientDirectAudio by mutableStateOf(false) private var mic by mutableStateOf(false) private var linuxRows by mutableStateOf>(emptyList()) private var linuxSteam by mutableStateOf("") @@ -413,6 +414,7 @@ class MainActivity : ComponentActivity() { suspendPolicy = suspendPolicy, oscMode = if (mode == SessionService.MODE_STEAM) oscMode else null, directAudio = if (mode == SessionService.MODE_STEAM) directAudio else null, + clientDirectAudio = clientDirectAudio, mic = if (mode == SessionService.MODE_STEAM) mic else null, renderer = if (mode == SessionService.MODE_DESKTOP) renderer else null, gameStorage = if (mode == SessionService.MODE_STEAM) gameStorage else null, @@ -437,6 +439,7 @@ class MainActivity : ComponentActivity() { onSuspendPolicy = { policy -> SessionPrefs.setSuspendPolicy(this, mode, policy); suspendPolicy = policy }, onOsc = { o -> SessionPrefs.setOscMode(this, o); oscMode = o }, onDirectAudio = { on -> SessionPrefs.setDirectAudio(this, on); directAudio = on }, + onClientDirectAudio = { on -> SessionPrefs.setClientDirectAudio(this, on); clientDirectAudio = on }, onMic = { on -> SessionPrefs.setMicEnabled(this, on) mic = on @@ -528,6 +531,7 @@ class MainActivity : ComponentActivity() { suspendPolicy = SessionPrefs.suspendPolicy(this, mode) oscMode = SessionPrefs.oscMode(this) directAudio = SessionPrefs.directAudio(this) + clientDirectAudio = SessionPrefs.clientDirectAudio(this) mic = SessionPrefs.micEnabled(this) renderer = SessionPrefs.desktopRenderer(this) gameStorage = SessionPrefs.gameStorage(this) diff --git a/app/src/main/java/com/steamdeck/launcher/audio/DirectAudioRelayComponent.java b/app/src/main/java/com/steamdeck/launcher/audio/DirectAudioRelayComponent.java index ab7ee987d3..01d6e21524 100644 --- a/app/src/main/java/com/steamdeck/launcher/audio/DirectAudioRelayComponent.java +++ b/app/src/main/java/com/steamdeck/launcher/audio/DirectAudioRelayComponent.java @@ -91,6 +91,9 @@ public class DirectAudioRelayComponent extends SessionPart { StringBuilder command = new StringBuilder(binary.getAbsolutePath()); command.append(" --socket ").append(socketPath.getAbsolutePath()); + // Diagnostics into the session's audio.log: every 1000 callbacks the device buffer, + // Android's own xrun count and the ring's fill, plus every buffer change. + command.append(" --log"); if (micFifoPath != null) { // The helper creates the pipe if it is not there. PulseAudio is told the same path and // reads from the other end of it. diff --git a/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java b/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java index 4f3bd64bd4..c3b3e5abff 100644 --- a/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java +++ b/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java @@ -143,7 +143,8 @@ public class PulseAudioComponent extends SessionPart { config.add("load-module module-directaudio-sink sink_name=DirectAudio socket=\"" + relaySocketPath + "\" performance_mode=1 adaptive=1 volume=1.0"); config.add("set-default-sink DirectAudio"); } else { - config.add("load-module module-aaudio-sink sink_name=AAudioSink performance_mode=1 adaptive=1 volume=1.0"); + // The classic sink: the adaptive AAudio module 0.1.5 shipped, unchanged. + config.add("load-module module-aaudio-classic-sink sink_name=AAudioSink performance_mode=1 adaptive=1 volume=1.0"); config.add("set-default-sink AAudioSink"); } if (micFifoPath != null && !micFifoPath.isEmpty()) { @@ -164,7 +165,10 @@ public class PulseAudioComponent extends SessionPart { String command = workingDir.getAbsolutePath() + "/libpulseaudio.so" + " --system=false --disable-shm=true --fail=false" - + " -n --file=default.pa --daemonize=false --use-pid-file=false --exit-idle-time=-1"; + + " -n --file=default.pa --daemonize=false --use-pid-file=false --exit-idle-time=-1" + // Info level: the classic sink reports the stream Android granted (burst, capacity, + // starting buffer) only there, and that is what a stutter report needs. + + " --log-level=info"; // A module that refuses to load, a pipe that could not be made, the daemon exiting at // startup: all of it used to reach logcat and nothing else, so a user's folder said nothing // at all about sound. Four separate faults hid behind "no input device" in one night. diff --git a/app/src/main/java/com/steamdeck/launcher/core/DeviceReport.kt b/app/src/main/java/com/steamdeck/launcher/core/DeviceReport.kt index a23c364586..9c6c08300e 100644 --- a/app/src/main/java/com/steamdeck/launcher/core/DeviceReport.kt +++ b/app/src/main/java/com/steamdeck/launcher/core/DeviceReport.kt @@ -146,7 +146,8 @@ object DeviceReport { k("FEX preset", SessionPrefs.fexPreset(context).ifEmpty { "FEX defaults" }) k("Skip xalia", SessionPrefs.noXalia(context)) k("proot without seccomp", SessionPrefs.prootNoSeccomp(context)) - k("DirectAudio (games and client)", SessionPrefs.directAudio(context)) + k("DirectAudio for games", SessionPrefs.directAudio(context)) + k("Client audio", if (SessionPrefs.clientDirectAudio(context)) "DirectAudio" else "classic") k("Microphone", SessionPrefs.micEnabled(context)) k("On-screen controls", SessionPrefs.oscMode(context)) k("Touch mode", SessionPrefs.touchMode(context)) diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt index e2562ae89b..bb9191790f 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/SessionPrefs.kt @@ -69,8 +69,19 @@ object SessionPrefs { } /** - * DirectAudio: games' Wine audio driver and the client's own sound both go through the relay - * helper on this side. On unless the user turned it off; off, PulseAudio drives the device. + * The Steam client's own sound through the DirectAudio relay instead of the classic AAudio + * sink. Off by default: on an AYN Thor (Android 13, 20 ms bursts) the relay path stayed choppy + * where the classic sink - the one 0.1.5 shipped - was fine. + */ + fun clientDirectAudio(context: Context): Boolean = prefs(context).getBoolean("clientDirectAudio", false) + + fun setClientDirectAudio(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("clientDirectAudio", on).apply() + } + + /** + * DirectAudio for games: their Wine audio driver talks to the relay helper on this side. On + * unless the user turned it off. */ fun directAudio(context: Context): Boolean = prefs(context).getBoolean("directAudio", true) diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt index 9d509ad0a7..7670833caf 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt @@ -316,12 +316,14 @@ class SessionService : Service() { val pulse = PulseAudioComponent(this, micFifo?.absolutePath) // With DirectAudio on, the client's own sound goes through the relay too: the daemon // fills the relay's ring and the relay, outside proot, drives the device. - if (wantsDirectAudio) pulse.setRelaySocket(relaySocket.absolutePath) + // The client's own sound: the classic AAudio sink unless the user chose the relay. + val clientDirectAudio = SessionState.mode == MODE_STEAM && SessionPrefs.clientDirectAudio(this) + if (clientDirectAudio) pulse.setRelaySocket(relaySocket.absolutePath) pulse.setLogFile(audioLog) pulse.attach(this) guest.add("PULSE_SERVER=unix:" + pulse.socket().absolutePath) components.add(pulse) - if (wantsDirectAudio || wantsMic) { + if (wantsDirectAudio || wantsMic || clientDirectAudio) { // After the daemon in the list, so it can wait for the pipe the daemon makes. val relay = DirectAudioRelayComponent(relaySocket, micFifo) relay.setLogFile(audioLog) @@ -335,7 +337,7 @@ class SessionService : Service() { guest.add("BL_DIRECTAUDIO=/" + SessionFiles.DIRECTAUDIO_DIR) guest.add("BANNER_AUDIO_DIRECT_RELAY=" + relaySocket.absolutePath) } - Log.i(TAG, "audio: PulseAudio" + (if (wantsDirectAudio) " + DirectAudio for games" else "") + Log.i(TAG, "audio: client " + (if (clientDirectAudio) "DirectAudio" else "classic AAudio sink") + (if (wantsDirectAudio) " + DirectAudio for games" else "") + (if (wantsMic) " + microphone" else "") + (if (SessionPrefs.micEnabled(this) && !wantsMic) " (microphone wanted but RECORD_AUDIO not granted)" else "")) diff --git a/app/src/main/java/com/steamdeck/launcher/ui/ModeSettingsDialog.kt b/app/src/main/java/com/steamdeck/launcher/ui/ModeSettingsDialog.kt index 0243fee043..9f486328ef 100644 --- a/app/src/main/java/com/steamdeck/launcher/ui/ModeSettingsDialog.kt +++ b/app/src/main/java/com/steamdeck/launcher/ui/ModeSettingsDialog.kt @@ -30,6 +30,7 @@ class ModeSettings( /** Steam only. */ val oscMode: String?, val directAudio: Boolean?, + val clientDirectAudio: Boolean = false, val mic: Boolean?, val renderer: String?, val gameStorage: String? = null, @@ -61,6 +62,7 @@ class ModeSettingsActions( val onSuspendPolicy: (String) -> Unit, val onOsc: (String) -> Unit, val onDirectAudio: (Boolean) -> Unit, + val onClientDirectAudio: (Boolean) -> Unit = {}, val onMic: (Boolean) -> Unit, val onRenderer: (String) -> Unit, val onGameStorage: (path: String, label: String) -> Unit = { _, _ -> }, @@ -193,7 +195,12 @@ fun ModeSettingsPage(s: ModeSettings, a: ModeSettingsActions) { ) } if (steam && s.directAudio != null && s.mic != null) SettingsGroup("Audio") { - ToggleRow(host, "da", "DirectAudio", "Bypasses PulseAudio for lower latency, for games and the Steam client.", s.directAudio, onChange = a.onDirectAudio) + ToggleRow(host, "da", "DirectAudio for games", "Bypasses PulseAudio for lower latency in games.", s.directAudio, onChange = a.onDirectAudio) + ChoiceRow( + host, "clientAudio", "Steam client audio", "Classic is the AAudio sink from 0.1.5. DirectAudio goes through the relay. Applies next session.", + listOf("classic" to "Classic", "directaudio" to "DirectAudio"), if (s.clientDirectAudio) "directaudio" else "classic", + onPick = { id -> a.onClientDirectAudio(id == "directaudio") }, + ) ToggleRow(host, "mic", "Microphone", "Uses the device microphone for voice chat.", s.mic, onChange = a.onMic) } if (steam && s.gameStorage != null) SettingsGroup("Game storage") {