Run a virtual iPhone on an Apple Silicon Mac.
Swift
Play through the raw speaker chain on a guest
Jackye7aa14d1751f
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex fe4d6143..7fdd77a5 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -2546,19 +2546,21 @@ The handler's volume-mode test (`and x28, x0, #0x1ffffffff` at 0xea3fc) isa branch between two builds of the route, not a precondition, and is nottouched.-## Guest audio through a Mac's microphone (2026-10-04)+## Guest audio through a Mac's microphone and speakers (2026-10-04)-An iPhone guest's audio node and tuning set are the D47's. Three changes take-out what they assume about its microphones; the measurements are in-`Research/Guest/virtio_sound_microphone.md` §7.+An iPhone guest's audio node and tuning set are the D47's. Four changes take+out what they assume about its hardware; the measurements are in+`Research/Guest/virtio_sound_microphone.md` §7 and+`Research/Guest/virtio_sound.md` §9.| Patch | Component | Effect || --- | --- | --- || `devicetree-cfw-product_audio_microphone_array` (new) | Every guest's DeviceTree, `fw patch` | Removes `supports-spatial-audio-capture` and `supports-audio-mix` from `/product/audio` (`DeviceTreePatcher.removeMicrophoneArrayClaims(from:)`). With them iOS 27's Voice Memos records through the four-microphone spatial route and the recording is silent. || `preboot-cfw-devicetree_microphone_array` (new) | Restored Preboot `devicetree.img4`, `cfw install` and `cfw update-environment`, every guest | The same removal for a VM patched before it (`vphone-cli cfw patch-dt-microphone-array`). || `system-virtualaudio-cfw-microphone_graph_chains` (new) | `/Library/Audio/Tunings/<AID>/VAD/graph_configurations.plist` and each `*_mic*_measurement.austrip` beside it | Every `<mic>_general` configuration with a `<mic>_measurement` sibling takes the sibling's `graph`, `austrip` and `propstrip` (`patch-virtualaudio-microphone-chains`), and every AUNBandEQ in those strips has its global gain set to 0 dB (`patch-virtualaudio-microphone-gain`; +18 dB on `bottom_mic_measurement`). A set with no such pair is left alone. |+| `system-virtualaudio-cfw-speaker_raw_chains` (new) | `/Library/Audio/Tunings/<AID>/VAD/graph_configurations.plist` | Every `speaker_*` configuration other than `speaker_raw` and `speaker_measurement` takes `speaker_raw`'s `graph`, `austrip`, `propstrip` and `volumeCommands` (`patch-virtualaudio-speaker-raw`). A set with no `speaker_raw` is left alone. |-All three are on in `standard`, need no firmware change, and are in the+All four are on in `standard`, need no firmware change, and are in theinstaller's late list, so `cfw update-environment` brings them to a VM whoseplan predates them. The tuning files themselves are untouched except for theone parameter word in each measurement strip; a strip whose saved state is@@ -2570,6 +2572,8 @@ plist reported `back_mic_general`, `beamformed_mic_general`,`bottom_mic2_general`, `bottom_mic_general` and `front_mic_general`, and asecond run none; `patch-virtualaudio-microphone-gain` on its`bottom_mic_measurement.austrip` reported `AUNBEQ_2 global gain 18.0 dB -> 0-dB`, changing one word of the saved state. After `cfw update-environment` and a+dB`, changing one word of the saved state; `patch-virtualaudio-speaker-raw`+reported eight speaker configurations. After `cfw update-environment` and aboot, audiomxd built the recording route with `DSP chain-'bottom_mic_measurement'`.+'bottom_mic_measurement'` and the guest's plist read back `speaker_general:+graph=speaker_raw austrip=speaker_measurement vol=["vugd"]`.diff --git a/Research/Guest/virtio_sound.md b/Research/Guest/virtio_sound.mdindex d715cd36..51f82b2f 100644--- a/Research/Guest/virtio_sound.md+++ b/Research/Guest/virtio_sound.md@@ -780,6 +780,42 @@ mismatch `kernel-boot-sandbox_ext` opens `proc_check_syscall_unix` for. Itneeds its own kernel-side change. The volume keys do not go through thatservice.+## 9. Playback sounded like wind: the speaker chain was the board's (2026-10-04)++With recordings on an iPhone guest matching the Mac's own (see+`virtio_sound_microphone.md` §7), playing one back in the guest still+sounded noisy. Every `speaker_*` configuration of the D47 tuning set+(AID8018) but two runs `speaker_general.dspg`: a loudness normalizer+(`AULDNM`), a DC blocker, a virtual bass (`AUVirtualBass`), rotation shading,+crosstalk cancellation, an equalizer, a volume taper, a multiband compressor,+a second equalizer, two `AUBuzzKill`s and a limiter — a small speaker's+correction. audiomxd's own level report across it, for a system sound:+`PreDSP … rms:[-52.6], peaks:[-35.4]`, `PostDSP … rms:[-26.5], peaks:[-7.8]`,+26 dB up. Through a Mac's speakers the quiet low end of a recording comes+out as noise.++`speaker_raw` is the same route with rotation shading, a volume+(`AUVolume`, driven by the `vugd` graph parameter rather than+`speaker_general`'s `vtvs`) and a limiter. `system-virtualaudio-cfw-speaker_raw_chains`+gives every `speaker_*` entry in `graph_configurations.plist` other than+`speaker_raw` and `speaker_measurement` the raw one's `graph`, `austrip`,+`propstrip` and `volumeCommands` (`vphone-cli cfw+patch-virtualaudio-speaker-raw`). It runs after `speaker_graph_chains`, which+is still what keeps the chain factory off the physical speaker.++Without the normalizer the middle of the volume slider was quiet: the route+sets the plugin's control in a straight line of decibels over its -36 dB+range, -20.2 dB at 7/16. The plugin now takes the control's position in its+range, squared, as the gain (`applyGain`): -14.4 dB at 7/16, -12 dB at half,+unity at the top. The control's decibels are what VirtualAudio reads back and+are unchanged.++Heard on `mictest-iphone` by the person testing: "much better" with the raw+chain, then "a little quiet", which the taper answers. Not measured: the+level across the raw chain, the volume keys after the change (the plugin's+log shows the value still arrives), and an iPad guest, whose tuning set this+patch also rewrites if it has a `speaker_raw`.+## Reveal and validation1. Kernel side present: `strings` on the decompressed kernelcache shows thediff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurations.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurations.swiftindex 9d4f8f94..052742b6 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurations.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurations.swift@@ -168,6 +168,98 @@ public enum CustomFirmwareVirtualAudioGraphConfigurations {return .rewritten(changed: changed)}+ // MARK: - Raw speaker chain++ /// The configuration whose chain is the speaker with nothing made for the+ /// board's own driver in it, and the keys that name a chain: its tuning+ /// files and the graph parameter the volume is sent to.+ static let rawSpeakerConfiguration = "speaker_raw"+ static let measurementSpeakerConfiguration = "speaker_measurement"+ static let chainKeys = ["graph", "austrip", "propstrip", "volumeCommands"]++ /// Give every `speaker_*` configuration at `url` the chain of+ /// `speaker_raw`, and return the ones that changed, sorted.+ ///+ /// `speaker_general` and the configurations built on it run a loudness+ /// normalizer, a virtual bass, crosstalk cancellation, two equalizers, a+ /// multiband compressor and a limiter, all tuned to the board's own+ /// speaker: on the D47 set they raise a system sound by 26 dB. Through+ /// the Mac's speakers that turns the quiet low end of a recording into+ /// noise. `speaker_raw` is the same route with only the volume and a+ /// limiter in it. `speaker_measurement` is left as it is, and so is a set+ /// with no `speaker_raw`.+ ///+ /// - Throws: ``PatcherError/invalidFormat(_:)`` when the file is not a+ /// plist, its root or `Configurations` is not a dictionary, or a+ /// speaker configuration is not a dictionary.+ @discardableResult+ public static func useRawSpeakerChain(+ at url: URL,+ dryRun: Bool = false,+ verbose: Bool = true,+ ) throws -> [String] {+ let data = try readFile(at: url)+ let format = detectFormat(data)+ guard+ var plist = (try? PropertyListSerialization.propertyList(from: data, options: [], format: nil)) as? [String: Any],+ var configurations = plist[configurationsKey] as? [String: Any]+ else {+ throw PatcherError.invalidFormat("no '\(configurationsKey)' dict present: \(url.path)")+ }+ guard let raw = configurations[rawSpeakerConfiguration] else {+ if verbose {+ print(" [.] \(url.lastPathComponent): no '\(rawSpeakerConfiguration)' configuration, left as it is")+ }+ return []+ }+ guard let raw = raw as? [String: Any] else {+ throw PatcherError.invalidFormat("configuration '\(rawSpeakerConfiguration)' is not a dict: \(url.path)")+ }++ var changed: [String] = []+ for name in configurations.keys.sorted()+ where name.hasPrefix("speaker_") && name != rawSpeakerConfiguration && name != measurementSpeakerConfiguration+ {+ guard var entry = configurations[name] as? [String: Any] else {+ throw PatcherError.invalidFormat("configuration '\(name)' is not a dict: \(url.path)")+ }+ var differs = false+ for key in chainKeys {+ let wanted = raw[key]+ let same = switch (entry[key], wanted) {+ case (nil, nil): true+ case let (have?, want?): (have as AnyObject).isEqual(want)+ default: false+ }+ guard !same else { continue }+ differs = true+ entry[key] = wanted+ }+ guard differs else { continue }+ configurations[name] = entry+ changed.append(name)+ if verbose {+ print(" [+] \(url.lastPathComponent): \(name) takes the chain of \(rawSpeakerConfiguration)")+ }+ }++ if changed.isEmpty {+ if verbose {+ print(" [.] \(url.lastPathComponent): speaker chains already '\(rawSpeakerConfiguration)'")+ }+ return []+ }+ if dryRun {+ if verbose {+ print(" [.] dry-run — not writing back")+ }+ return changed+ }+ plist[configurationsKey] = configurations+ try PropertyListSerialization.data(fromPropertyList: plist, format: format, options: 0).write(to: url)+ return changed+ }+// MARK: - Format detection/// XML plists start with `<?xml` or `<plist`; binary plists start withdiff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swiftindex 7517275e..7a3c38fd 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift@@ -253,6 +253,17 @@ public enum FirmwareGuestSystemPatchSet {""",target: .guestFile(path: "/Library/Audio/Tunings"),),+ VPhonePatchDeclaration(+ identifier: virtualAudioSpeakerRawChains,+ title: "VirtualAudio raw speaker chain",+ summary: """+ Gives every speaker_* entry in the tuning set's graph_configurations.plist the chain \+ of speaker_raw: the volume and a limiter. The general chain's loudness normalizer, \+ virtual bass, equalizers and compressor are tuned to the board's own speaker; \+ through the Mac's they turn the quiet low end of what plays into noise.+ """,+ target: .guestFile(path: "/Library/Audio/Tunings"),+ ),VPhonePatchDeclaration(identifier: virtualAudioMicrophoneChains,title: "VirtualAudio microphone chains",@@ -342,6 +353,10 @@ public enum FirmwareGuestSystemPatchSet {/// Speaker device a VM does not have.public static let virtualAudioGraphConfigurations = "system-virtualaudio-cfw-speaker_graph_chains"+ /// Every speaker chain in graph_configurations.plist, pointed at the raw+ /// one so playback is not shaped for a speaker the VM does not have.+ public static let virtualAudioSpeakerRawChains = "system-virtualaudio-cfw-speaker_raw_chains"+/// The general microphone chains in graph_configurations.plist, pointed at/// their measurement siblings so a recording is not pushed through/// dynamics tuned to a microphone the VM does not have.diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurationsTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurationsTests.swiftindex ee445edb..8cf43e41 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurationsTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurationsTests.swift@@ -154,4 +154,88 @@ struct CustomFirmwareVirtualAudioGraphConfigurationsTests {#expect(CustomFirmwareVirtualAudioGraphConfigurations.configurationsKey == "Configurations")#expect(CustomFirmwareVirtualAudioGraphConfigurations.chainTypeKey == "chainType")}++ // MARK: - Raw speaker chain++ /// The D47 set's speaker configurations: each names a chain by its+ /// tunings and by the graph parameter its volume goes to.+ static func speakerSet(raw: Bool = true) -> [String: Any] {+ func speaker(graph: String, austrip: String, volume: String) -> [String: Any] {+ ["chainType": "dflt", "graph": graph, "austrip": austrip, "propstrip": graph,+ "volumeCommands": [volume], "properties": [["ID": "spim"]]]+ }+ var configurations: [String: Any] = [+ "speaker_general": speaker(graph: "speaker_general", austrip: "speaker_general", volume: "vtvs"),+ "speaker_ringtone": speaker(graph: "speaker_general", austrip: "speaker_ringtone", volume: "vtvs"),+ "speaker_measurement": speaker(graph: "speaker_measurement", austrip: "speaker_measurement", volume: "vugd"),+ "bottom_mic_general": ["chainType": "dflt", "graph": "bottom_mic_general"],+ ]+ if raw {+ configurations["speaker_raw"] = speaker(graph: "speaker_raw", austrip: "speaker_measurement", volume: "vugd")+ }+ return ["Configurations": configurations]+ }++ static func configurations(at url: URL) throws -> [String: [String: Any]] {+ let plist = try PropertyListSerialization.propertyList(from: Data(contentsOf: url), format: nil)+ return try #require((plist as? [String: Any])?["Configurations"] as? [String: [String: Any]])+ }++ static func writeSpeakerSet(_ set: [String: Any]) throws -> URL {+ let url = FileManager.default.temporaryDirectory.appendingPathComponent("vphone-speaker-\(UUID().uuidString).plist")+ try PropertyListSerialization.data(fromPropertyList: set, format: .binary, options: 0).write(to: url)+ return url+ }++ @Test func `every speaker chain becomes the raw one`() throws {+ let url = try Self.writeSpeakerSet(Self.speakerSet())+ defer { try? FileManager.default.removeItem(at: url) }++ let changed = try CustomFirmwareVirtualAudioGraphConfigurations.useRawSpeakerChain(at: url, verbose: false)+ #expect(changed == ["speaker_general", "speaker_ringtone"])++ let patched = try Self.configurations(at: url)+ let original = try #require(Self.speakerSet()["Configurations"] as? [String: [String: Any]])+ for name in changed {+ #expect(patched[name]?["graph"] as? String == "speaker_raw")+ #expect(patched[name]?["austrip"] as? String == "speaker_measurement")+ #expect(patched[name]?["propstrip"] as? String == "speaker_raw")+ #expect(patched[name]?["volumeCommands"] as? [String] == ["vugd"])+ // What is not the chain stays the configuration's own.+ #expect((patched[name]?["properties"] as? [[String: Any]])?.count == 1)+ #expect(patched[name]?["chainType"] as? String == "dflt")+ }+ for name in ["speaker_raw", "speaker_measurement", "bottom_mic_general"] {+ #expect(NSDictionary(dictionary: try #require(patched[name])) == NSDictionary(dictionary: try #require(original[name])))+ }+ }++ @Test func `a second run on raw speaker chains writes nothing`() throws {+ let url = try Self.writeSpeakerSet(Self.speakerSet())+ defer { try? FileManager.default.removeItem(at: url) }+ try CustomFirmwareVirtualAudioGraphConfigurations.useRawSpeakerChain(at: url, verbose: false)+ let once = try Data(contentsOf: url)++ #expect(try CustomFirmwareVirtualAudioGraphConfigurations.useRawSpeakerChain(at: url, verbose: false).isEmpty)+ #expect(try Data(contentsOf: url) == once)+ }++ @Test func `a set with no raw speaker chain is left alone`() throws {+ let url = try Self.writeSpeakerSet(Self.speakerSet(raw: false))+ defer { try? FileManager.default.removeItem(at: url) }+ let before = try Data(contentsOf: url)++ #expect(try CustomFirmwareVirtualAudioGraphConfigurations.useRawSpeakerChain(at: url, verbose: false).isEmpty)+ #expect(try Data(contentsOf: url) == before)+ }++ @Test func `a dry run names the speaker chains and writes nothing`() throws {+ let url = try Self.writeSpeakerSet(Self.speakerSet())+ defer { try? FileManager.default.removeItem(at: url) }+ let before = try Data(contentsOf: url)++ let changed = try CustomFirmwareVirtualAudioGraphConfigurations.useRawSpeakerChain(at: url, dryRun: true, verbose: false)+ #expect(changed == ["speaker_general", "speaker_ringtone"])+ #expect(try Data(contentsOf: url) == before)+ }}diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swiftindex 5a43b6a5..41117af4 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift@@ -428,6 +428,11 @@ struct VPhoneCustomFirmwareInstaller {if plan?.isEnabled(FirmwareGuestSystemPatchSet.virtualAudioGraphConfigurations) ?? true {try patchVirtualAudioGraphConfigurations(system: system, work: work)}+ if plan?.isEnabled(FirmwareGuestSystemPatchSet.virtualAudioSpeakerRawChains) ?? true {+ try patchVirtualAudioGraphConfigurations(+ system: system, work: work, verb: "patch-virtualaudio-speaker-raw",+ )+ }if plan?.isEnabled(FirmwareGuestSystemPatchSet.virtualAudioMicrophoneChains) ?? true {try patchVirtualAudioGraphConfigurations(system: system, work: work, verb: "patch-virtualaudio-microphone-chains",@@ -757,6 +762,11 @@ struct VPhoneCustomFirmwareInstaller {if on(FirmwareGuestSystemPatchSet.virtualAudioGraphConfigurations) {try patchVirtualAudioGraphConfigurations(system: system, work: work)}+ if on(FirmwareGuestSystemPatchSet.virtualAudioSpeakerRawChains) {+ try patchVirtualAudioGraphConfigurations(+ system: system, work: work, verb: "patch-virtualaudio-speaker-raw",+ )+ }if on(FirmwareGuestSystemPatchSet.virtualAudioMicrophoneChains) {try patchVirtualAudioGraphConfigurations(system: system, work: work, verb: "patch-virtualaudio-microphone-chains",@@ -795,6 +805,7 @@ struct VPhoneCustomFirmwareInstaller {FirmwareGuestSystemPatchSet.virtualAudioSpeakerProtectionGate,FirmwareGuestSystemPatchSet.virtualAudioVolumeModePrecondition,FirmwareGuestSystemPatchSet.virtualAudioGraphConfigurations,+ FirmwareGuestSystemPatchSet.virtualAudioSpeakerRawChains,FirmwareGuestSystemPatchSet.virtualAudioMicrophoneChains,]diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swiftindex 1eeb4f3c..f5537521 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwarePatchCommand.swift@@ -252,6 +252,37 @@ struct VPhoneCustomFirmwarePatchVirtualAudioGraphConfigurationsCommand: Parsable}}+// MARK: - patch-virtualaudio-speaker-raw++struct VPhoneCustomFirmwarePatchVirtualAudioSpeakerRawCommand: ParsableCommand {+ static let configuration = CommandConfiguration(+ commandName: "patch-virtualaudio-speaker-raw",+ abstract: "Play through VirtualAudio's raw speaker chain",+ discussion: """+ Every speaker_* entry in graph_configurations.plist other than+ speaker_raw and speaker_measurement takes speaker_raw's graph, austrip,+ propstrip and volumeCommands. The general speaker chain is a loudness+ normalizer, a virtual bass, equalizers, a multiband compressor and a+ limiter tuned to the board's own speaker; through the Mac's speakers+ it turns the quiet low end of what plays into noise. The raw chain is+ the volume and a limiter.++ Idempotent — a re-run, or a set with no speaker_raw, reports and exits+ without rewriting.+ """,+ )++ @Argument(help: "Path to graph_configurations.plist", transform: URL.init(fileURLWithPath:))+ var plist: URL++ @Flag(name: .customLong("dry-run"), help: "Report what would change and exit")+ var dryRun = false++ func run() throws {+ try CustomFirmwareVirtualAudioGraphConfigurations.useRawSpeakerChain(at: plist, dryRun: dryRun, verbose: true)+ }+}+// MARK: - patch-virtualaudio-microphone-chainsstruct VPhoneCustomFirmwarePatchVirtualAudioMicrophoneChainsCommand: ParsableCommand {diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swiftindex 49b4b487..1f70fd80 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Restore/VPhoneRestoreCommand.swift@@ -182,6 +182,7 @@ struct VPhoneCustomFirmwareCommand: ParsableCommand {VPhoneCustomFirmwareInjectDylibCommand.self,VPhoneCustomFirmwarePatchBuildVersionCommand.self,VPhoneCustomFirmwarePatchVirtualAudioGraphConfigurationsCommand.self,+ VPhoneCustomFirmwarePatchVirtualAudioSpeakerRawCommand.self,VPhoneCustomFirmwarePatchVirtualAudioMicrophoneChainsCommand.self,VPhoneCustomFirmwarePatchVirtualAudioMicrophoneGainCommand.self,VPhoneCustomFirmwarePatchCampoEntitlementsCommand.self,diff --git a/VPhoneGuestComponents/VirtIOSound/VPVirtIOSoundPlugin.m b/VPhoneGuestComponents/VirtIOSound/VPVirtIOSoundPlugin.mindex 1a848ae5..00e09d87 100644--- a/VPhoneGuestComponents/VirtIOSound/VPVirtIOSoundPlugin.m+++ b/VPhoneGuestComponents/VirtIOSound/VPVirtIOSoundPlugin.m@@ -91,9 +91,9 @@ static const uint64_t kInputDumpMaximumBytes = 16 * 1024 * 1024;static const double kInputHighPassHertz = 120;/// The speaker volume control's range. VirtualAudio maps the guest's volume-/// onto it in a straight line, so the bottom decides how loud half volume-/// is: -18 dB here. The macOS plugin's -60 dB would put it at -30 dB, which-/// through a Mac's speakers is close to nothing.+/// onto it in a straight line and reads the decibels back, so the range is+/// only how the guest's volume reaches the plugin: `applyGain` takes the+/// position in it, not the decibels, as the gain.static const float kSpeakerMinimumDecibels = -36.0f;static const float kMicrophoneMinimumDecibels = -60.0f;@@ -2124,17 +2124,26 @@ static BOOL VPIsDeviceRateAddress(const AudioObjectPropertyAddress *address) {// MARK: Controls-/// The gain the streams apply: silence when muted, else the volume control's-/// decibels as a factor. At the bottom of its range the control means off.+/// The gain the streams apply: silence when muted or at the bottom of the+/// volume control's range, else the square of the control's position in it.+///+/// The guest's speaker chain is the raw one (`speaker_raw_chains`), with none+/// of the loudness the board's own chain adds at low volumes, so the control's+/// decibels taken as they are leave the middle of the slider quiet: -18 dB at+/// half. The square is the usual taper for a volume with nothing after it:+/// -12 dB at half, -24 dB at a quarter, and unity at the top.- (void)applyGain {float decibels = _volumeControl.decibelValue;- float gain = _muteState || decibels <= _volumeControl.minimumDecibelValue ? 0 : powf(10, decibels / 20);+ float minimum = _volumeControl.minimumDecibelValue;+ float position = minimum < 0 ? 1 - decibels / minimum : 1;+ position = fminf(fmaxf(position, 0), 1);+ float gain = _muteState ? 0 : position * position;for (VPVirtIOSoundStream *stream in _streams) {[stream setGain:gain];}- VPLogToFile("device %s: %s, %.1f dB, gain %.3f",+ VPLogToFile("device %s: %s, %.1f dB of %.0f, gain %.3f",_direction == ASDStreamDirectionInput ? "microphone" : "speaker",- _muteState ? "muted" : "unmuted", decibels, gain);+ _muteState ? "muted" : "unmuted", decibels, minimum, gain);}- (void)volumeChanged {