Просмотр исходного кода

config(qemu): add pcspk sound device

Resolves #5105
osy 2 лет назад
Родитель
Сommit
6008ec4320

+ 4 - 0
Configuration/QEMUConstantGenerated.swift

@@ -8836,6 +8836,7 @@ enum QEMUSoundDevice_i386: String, CaseIterable, QEMUSoundDevice {
     case AC97
     case intel_hda = "intel-hda"
     case ich9_intel_hda = "ich9-intel-hda"
+    case pcspk
     case adlib
     case usb_audio = "usb-audio"
 
@@ -8848,6 +8849,7 @@ enum QEMUSoundDevice_i386: String, CaseIterable, QEMUSoundDevice {
         case .AC97: return "Intel 82801AA AC97 Audio (AC97)"
         case .intel_hda: return "Intel HD Audio Controller (ich6) (intel-hda)"
         case .ich9_intel_hda: return "Intel HD Audio Controller (ich9) (ich9-intel-hda)"
+        case .pcspk: return "PC Speaker"
         case .adlib: return "Yamaha YM3812 (OPL2) (adlib)"
         case .usb_audio: return "usb-audio"
         }
@@ -9196,6 +9198,7 @@ enum QEMUSoundDevice_x86_64: String, CaseIterable, QEMUSoundDevice {
     case AC97
     case intel_hda = "intel-hda"
     case ich9_intel_hda = "ich9-intel-hda"
+    case pcspk
     case adlib
     case usb_audio = "usb-audio"
 
@@ -9208,6 +9211,7 @@ enum QEMUSoundDevice_x86_64: String, CaseIterable, QEMUSoundDevice {
         case .AC97: return "Intel 82801AA AC97 Audio (AC97)"
         case .intel_hda: return "Intel HD Audio Controller (ich6) (intel-hda)"
         case .ich9_intel_hda: return "Intel HD Audio Controller (ich9) (ich9-intel-hda)"
+        case .pcspk: return "PC Speaker"
         case .adlib: return "Yamaha YM3812 (OPL2) (adlib)"
         case .usb_audio: return "usb-audio"
         }

+ 15 - 2
Configuration/UTMQemuConfiguration+Arguments.swift

@@ -314,12 +314,17 @@ import Foundation
         let target = system.target.rawValue
         let architecture = system.architecture.rawValue
         var properties = qemu.machinePropertyOverride ?? ""
-        if target.hasPrefix("pc") || target.hasPrefix("q35") {
+        if target.hasPrefix("pc") || target.hasPrefix("q35") || target == "isapc" {
             properties = properties.appendingDefaultPropertyName("vmport", value: "off")
             // disable PS/2 emulation if we are not legacy input and it's not explicitly enabled
             if isUsbUsed && !qemu.hasPS2Controller {
                 properties = properties.appendingDefaultPropertyName("i8042", value: "off")
             }
+            #if os(macOS)
+            if sound.contains(where: { $0.hardware.rawValue == "pcspk" }) {
+                properties = properties.appendingDefaultPropertyName("pcspk-audiodev", value: "audio1")
+            }
+            #endif
         }
         if target == "virt" || target.hasPrefix("virt-") && !architecture.hasPrefix("riscv") {
             if #available(macOS 12.4, iOS 15.5, *, *) {
@@ -409,7 +414,8 @@ import Foundation
             "spice"
         }
         f("id=audio0")
-        for _sound in sound {
+        // screamer has no extra device, pcspk is handled in machineProperties
+        for _sound in sound.filter({ $0.hardware.rawValue != "screamer" && $0.hardware.rawValue != "pcspk" }) {
             f("-device")
             _sound.hardware
             if _sound.hardware.rawValue.contains("hda") {
@@ -419,6 +425,13 @@ import Foundation
             }
             f("audiodev=audio0")
         }
+        // pcspk doesn't work with SPICE audio
+        #if os(macOS)
+        if sound.contains(where: { $0.hardware.rawValue == "pcspk" }) {
+            f("-audiodev")
+            f("coreaudio,id=audio1")
+        }
+        #endif
     }
     
     @QEMUArgumentBuilder private var drivesArguments: [QEMUArgument] {

+ 6 - 0
Platform/Shared/VMConfigSoundView.swift

@@ -25,6 +25,12 @@ struct VMConfigSoundView: View {
             Form {
                 Section(header: Text("Hardware")) {
                     VMConfigConstantPicker("Emulated Audio Card", selection: $config.hardware, type: system.architecture.soundDeviceType)
+                    #if !os(macOS)
+                    if config.hardware.rawValue == "screamer" || config.hardware.rawValue == "pcspk" {
+                        Text("This audio card is not supported.")
+                            .foregroundColor(.red)
+                    }
+                    #endif
                 }
             }
         }

+ 1 - 1
Platform/Shared/VMSettingsAddDeviceMenuView.swift

@@ -68,7 +68,7 @@ struct VMSettingsAddDeviceMenuView: View {
                 config.sound.append(newSound!)
             } label: {
                 Label("Sound", systemImage: "speaker.wave.2")
-            }.disabled(config.system.architecture.soundDeviceType.allRawValues.isEmpty || config.sound.count >= 1)
+            }.disabled(config.system.architecture.soundDeviceType.allRawValues.isEmpty)
             #if os(iOS)
             Divider()
             Button {

+ 11 - 0
scripts/const-gen.py

@@ -57,6 +57,7 @@ DEFAULTS = {
 }
 
 AUDIO_SCREAMER = Device('screamer', 'macio', '', 'Screamer (Mac99 only)')
+AUDIO_PCSPK = Device('pcspk', 'macio', '', 'PC Speaker')
 DISPLAY_TCX = Device('tcx', 'none', '', 'Sun TCX')
 DISPLAY_CG3 = Device('cg3', 'none', '', 'Sun cgthree')
 NETWORK_LANCE = Device('lance', 'none', '', 'Lance (Am7990)')
@@ -81,6 +82,16 @@ ADD_DEVICES = {
             NETWORK_LANCE
         ])
     },
+    "i386": {
+        "Sound devices": set([
+            AUDIO_PCSPK
+        ])
+    },
+    "x86_64": {
+        "Sound devices": set([
+            AUDIO_PCSPK
+        ])
+    },
 }
 
 BLOCK_DEVICES = [