Skip to content

Commit d1568f0

Browse files
committed
Add audio device to limayaml and qemu
Signed-off-by: Anders F Björklund <[email protected]>
1 parent f70a609 commit d1568f0

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

examples/default.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ firmware:
244244
# 🟢 Builtin default: false
245245
legacyBIOS: null
246246

247+
audio:
248+
# QEMU audiodev, e.g., "none", "coreaudio", "pa", "alsa", "oss".
249+
# Choosing "none" will mute the audio output, and not play any sound.
250+
# 🟢 Builtin default: ""
251+
device: null
252+
247253
video:
248254
# QEMU display, e.g., "none", "cocoa", "sdl", "gtk", "vnc", "default".
249255
# Choosing "none" will hide the video output, and not show any window.

pkg/limayaml/defaults.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
199199

200200
y.AdditionalDisks = append(append(o.AdditionalDisks, y.AdditionalDisks...), d.AdditionalDisks...)
201201

202+
if y.Audio.Device == nil {
203+
y.Audio.Device = d.Audio.Device
204+
}
205+
if o.Audio.Device != nil {
206+
y.Audio.Device = o.Audio.Device
207+
}
208+
if y.Audio.Device == nil {
209+
y.Audio.Device = pointer.String("")
210+
}
211+
202212
if y.Video.Display == nil {
203213
y.Video.Display = d.Video.Display
204214
}

pkg/limayaml/defaults_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ func TestFillDefault(t *testing.T) {
7777
Firmware: Firmware{
7878
LegacyBIOS: pointer.Bool(false),
7979
},
80+
Audio: Audio{
81+
Device: pointer.String(""),
82+
},
8083
Video: Video{
8184
Display: pointer.String("none"),
8285
VNC: VNCOptions{
@@ -281,6 +284,9 @@ func TestFillDefault(t *testing.T) {
281284
Firmware: Firmware{
282285
LegacyBIOS: pointer.Bool(true),
283286
},
287+
Audio: Audio{
288+
Device: pointer.String("coreaudio"),
289+
},
284290
Video: Video{
285291
Display: pointer.String("cocoa"),
286292
VNC: VNCOptions{
@@ -449,6 +455,9 @@ func TestFillDefault(t *testing.T) {
449455
Firmware: Firmware{
450456
LegacyBIOS: pointer.Bool(true),
451457
},
458+
Audio: Audio{
459+
Device: pointer.String("coreaudio"),
460+
},
452461
Video: Video{
453462
Display: pointer.String("cocoa"),
454463
VNC: VNCOptions{

pkg/limayaml/limayaml.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type LimaYAML struct {
1919
MountType *MountType `yaml:"mountType,omitempty" json:"mountType,omitempty"`
2020
SSH SSH `yaml:"ssh,omitempty" json:"ssh,omitempty"` // REQUIRED (FIXME)
2121
Firmware Firmware `yaml:"firmware,omitempty" json:"firmware,omitempty"`
22+
Audio Audio `yaml:"audio,omitempty" json:"audio,omitempty"`
2223
Video Video `yaml:"video,omitempty" json:"video,omitempty"`
2324
Provision []Provision `yaml:"provision,omitempty" json:"provision,omitempty"`
2425
Containerd Containerd `yaml:"containerd,omitempty" json:"containerd,omitempty"`
@@ -122,6 +123,11 @@ type Firmware struct {
122123
LegacyBIOS *bool `yaml:"legacyBIOS,omitempty" json:"legacyBIOS,omitempty"`
123124
}
124125

126+
type Audio struct {
127+
// Device is a QEMU audiodev string
128+
Device *string `yaml:"device,omitempty" json:"device,omitempty"`
129+
}
130+
125131
type VNCOptions struct {
126132
Display *string `yaml:"display,omitempty" json:"display,omitempty"`
127133
}

pkg/qemu/qemu.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,9 @@ func Cmdline(cfg Config) (string, []string, error) {
378378
// https://qemu-project.gitlab.io/qemu/system/invocation.html?highlight=tcg%20opts
379379
// this will make sure each vCPU will be backed by 1 host user thread.
380380
args = appendArgsIfNoConflict(args, "-accel", "tcg,thread=multi,tb-size=512")
381-
// This will disable CPU S3 state.
381+
// This will disable CPU S3/S4 state.
382382
args = append(args, "-global", "ICH9-LPC.disable_s3=1")
383+
args = append(args, "-global", "ICH9-LPC.disable_s4=1")
383384
} else if runtime.GOOS == "windows" && accel == "whpx" {
384385
// whpx: injection failed, MSI (0, 0) delivery: 0, dest_mode: 0, trigger mode: 0, vector: 0
385386
args = appendArgsIfNoConflict(args, "-machine", "q35,accel="+accel+",kernel-irqchip=off")
@@ -589,6 +590,18 @@ func Cmdline(cfg Config) (string, []string, error) {
589590
// virtio-rng-pci accelerates starting up the OS, according to https://wiki.gentoo.org/wiki/QEMU/Options
590591
args = append(args, "-device", "virtio-rng-pci")
591592

593+
// Sound
594+
if *y.Audio.Device != "" {
595+
id := "default"
596+
// audio device
597+
audiodev := *y.Audio.Device
598+
audiodev += fmt.Sprintf(",id=%s", id)
599+
args = append(args, "-audiodev", audiodev)
600+
// audio controller
601+
args = append(args, "-device", "ich9-intel-hda")
602+
// audio codec
603+
args = append(args, "-device", fmt.Sprintf("hda-output,audiodev=%s", id))
604+
}
592605
// Graphics
593606
if *y.Video.Display != "" {
594607
display := *y.Video.Display

0 commit comments

Comments
 (0)