Skip to content

Commit 22dcd62

Browse files
committed
Add default value for audio driver
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 <[email protected]>
1 parent 118c249 commit 22dcd62

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

examples/default.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ audio:
297297
# QEMU audiodev, e.g., "none", "coreaudio", "pa", "alsa", "oss".
298298
# VZ driver, use "vz" as device name
299299
# Choosing "none" will mute the audio output, and not play any sound.
300+
# Choosing "default" will pick a suitable of: coreudio, pa, dsound, oss.
301+
# As of QEMU v6.2 the default is to create a disconnected sound device
302+
# that is still visible in the guest but not connected to the host.
300303
# 🟢 Builtin default: ""
301304
device: null
302305

pkg/qemu/qemu.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,19 @@ func qemuMachine(arch limayaml.Arch) string {
463463
return "virt"
464464
}
465465

466+
// audioDevice returns the default audio device.
467+
func audioDevice() string {
468+
switch runtime.GOOS {
469+
case "darwin":
470+
return "coreaudio"
471+
case "linux":
472+
return "pa" // pulseaudio
473+
case "windows":
474+
return "dsound"
475+
}
476+
return "oss"
477+
}
478+
466479
func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err error) {
467480
y := cfg.LimaYAML
468481
exe, args, err = Exe(*y.Arch)
@@ -762,6 +775,9 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
762775
id := "default"
763776
// audio device
764777
audiodev := *y.Audio.Device
778+
if audiodev == "default" {
779+
audiodev = audioDevice()
780+
}
765781
audiodev += fmt.Sprintf(",id=%s", id)
766782
args = append(args, "-audiodev", audiodev)
767783
// audio controller

0 commit comments

Comments
 (0)