From f6ea5842d261b1906bf233cea059ceeec86784f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 30 Jun 2024 12:53:56 +0200 Subject: [PATCH] Add default value for audio driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Can now use .audio.device=default similar to .video.display=default You can still pick another driver, such as alsa or oss, if you want. Signed-off-by: Anders F Björklund --- examples/default.yaml | 3 +++ pkg/qemu/qemu.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/examples/default.yaml b/examples/default.yaml index 8c354e2cf096..b471f4fed148 100644 --- a/examples/default.yaml +++ b/examples/default.yaml @@ -297,6 +297,9 @@ audio: # QEMU audiodev, e.g., "none", "coreaudio", "pa", "alsa", "oss". # VZ driver, use "vz" as device name # Choosing "none" will mute the audio output, and not play any sound. + # Choosing "default" will pick a suitable of: coreudio, pa, dsound, oss. + # As of QEMU v6.2 the default is to create a disconnected sound device + # that is still visible in the guest but not connected to the host. # 🟢 Builtin default: "" device: null diff --git a/pkg/qemu/qemu.go b/pkg/qemu/qemu.go index 5fe853323733..43362261b3c4 100644 --- a/pkg/qemu/qemu.go +++ b/pkg/qemu/qemu.go @@ -463,6 +463,19 @@ func qemuMachine(arch limayaml.Arch) string { return "virt" } +// audioDevice returns the default audio device. +func audioDevice() string { + switch runtime.GOOS { + case "darwin": + return "coreaudio" + case "linux": + return "pa" // pulseaudio + case "windows": + return "dsound" + } + return "oss" +} + func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err error) { y := cfg.LimaYAML exe, args, err = Exe(*y.Arch) @@ -762,6 +775,9 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er id := "default" // audio device audiodev := *y.Audio.Device + if audiodev == "default" { + audiodev = audioDevice() + } audiodev += fmt.Sprintf(",id=%s", id) args = append(args, "-audiodev", audiodev) // audio controller