Skip to content

Commit

Permalink
Add default value for audio driver
Browse files Browse the repository at this point in the history
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 <anders.f.bjorklund@gmail.com>
  • Loading branch information
afbjorklund committed Jul 2, 2024
1 parent bb9e31b commit f6ea584
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions pkg/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f6ea584

Please sign in to comment.