From f6c56ed8eb7d7d166459373ccb51e7c7734ca91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 19 Feb 2024 18:26:31 +0100 Subject: [PATCH] Add option to disable audio pass-though (#728) --- Sources/tart/Commands/Run.swift | 6 +++++- Sources/tart/VM.swift | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Sources/tart/Commands/Run.swift b/Sources/tart/Commands/Run.swift index 1810399..a8499e2 100644 --- a/Sources/tart/Commands/Run.swift +++ b/Sources/tart/Commands/Run.swift @@ -36,6 +36,9 @@ struct Run: AsyncParsableCommand { @Flag(help: ArgumentHelp("Force open a UI window, even when VNC is enabled.", visibility: .hidden)) var graphics: Bool = false + @Flag(help: "Disable audio pass-through to host.") + var noAudio: Bool = false + #if arch(arm64) @Flag(help: "Boot into recovery mode") #endif @@ -210,7 +213,8 @@ struct Run: AsyncParsableCommand { additionalStorageDevices: additionalDiskAttachments, directorySharingDevices: directoryShares() + rosettaDirectoryShare(), serialPorts: serialPorts, - suspendable: suspendable + suspendable: suspendable, + audio: !noAudio ) let vncImpl: VNC? = try { diff --git a/Sources/tart/VM.swift b/Sources/tart/VM.swift index 901d113..a129d92 100644 --- a/Sources/tart/VM.swift +++ b/Sources/tart/VM.swift @@ -45,7 +45,8 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { additionalStorageDevices: [VZStorageDeviceConfiguration] = [], directorySharingDevices: [VZDirectorySharingDeviceConfiguration] = [], serialPorts: [VZSerialPortConfiguration] = [], - suspendable: Bool = false + suspendable: Bool = false, + audio: Bool = true ) throws { name = vmDir.name config = try VMConfig.init(fromURL: vmDir.configURL) @@ -61,7 +62,8 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { network: network, additionalStorageDevices: additionalStorageDevices, directorySharingDevices: directorySharingDevices, serialPorts: serialPorts, - suspendable: suspendable + suspendable: suspendable, + audio: audio ) virtualMachine = VZVirtualMachine(configuration: configuration) @@ -274,7 +276,8 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { additionalStorageDevices: [VZStorageDeviceConfiguration], directorySharingDevices: [VZDirectorySharingDeviceConfiguration], serialPorts: [VZSerialPortConfiguration], - suspendable: Bool = false + suspendable: Bool = false, + audio: Bool = true ) throws -> VZVirtualMachineConfiguration { let configuration = VZVirtualMachineConfiguration() @@ -292,7 +295,7 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { configuration.graphicsDevices = [vmConfig.platform.graphicsDevice(vmConfig: vmConfig)] // Audio - if !suspendable { + if audio && !suspendable { let soundDeviceConfiguration = VZVirtioSoundDeviceConfiguration() let inputAudioStreamConfiguration = VZVirtioSoundDeviceInputStreamConfiguration() inputAudioStreamConfiguration.source = VZHostAudioInputStreamSource()