Compare commits

...
2 Commits
Author SHA1 Message Date
coder 9f3805733b fix: capture system audio as mono 2026-08-26 11:56:27 +02:00
coder 4e8fdc7603 fix: use delivered system audio format 2026-08-26 10:22:59 +02:00
3 changed files with 65 additions and 12 deletions
+4 -4
View File
@@ -276,7 +276,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 37;
CURRENT_PROJECT_VERSION = 39;
DEVELOPMENT_ASSET_PATHS = "\"meetingnotes/Preview Content\"";
DEVELOPMENT_TEAM = G9LVHZAJNX;
ENABLE_HARDENED_RUNTIME = YES;
@@ -290,7 +290,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 1.1.25;
MARKETING_VERSION = 1.1.27;
ONLY_ACTIVE_ARCH = NO;
OTHER_SWIFT_FLAGS = "$(inherited) -D ENABLE_TCC_SPI";
PRODUCT_BUNDLE_IDENTIFIER = net.jamesbone.meetingnotes;
@@ -312,7 +312,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 37;
CURRENT_PROJECT_VERSION = 39;
DEVELOPMENT_ASSET_PATHS = "\"meetingnotes/Preview Content\"";
DEVELOPMENT_TEAM = G9LVHZAJNX;
ENABLE_HARDENED_RUNTIME = YES;
@@ -326,7 +326,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 1.1.25;
MARKETING_VERSION = 1.1.27;
ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "$(inherited) -D ENABLE_TCC_SPI";
PRODUCT_BUNDLE_IDENTIFIER = net.jamesbone.meetingnotes;
+42 -1
View File
@@ -116,6 +116,47 @@ extension AudioObjectID {
try read(kAudioTapPropertyFormat, defaultValue: AudioStreamBasicDescription())
}
/// Reads the virtual format of the first input stream exposed by this device.
///
/// An aggregate device can adapt a tap to the active output hardware. Its
/// input stream format is therefore the format delivered to the I/O proc,
/// which can differ from the tap object's originally advertised format.
func readInputStreamBasicDescription() throws -> AudioStreamBasicDescription {
var streamsAddress = AudioObjectPropertyAddress(
mSelector: kAudioDevicePropertyStreams,
mScope: kAudioObjectPropertyScopeGlobal,
mElement: kAudioObjectPropertyElementMain
)
var dataSize: UInt32 = 0
var status = AudioObjectGetPropertyDataSize(self, &streamsAddress, 0, nil, &dataSize)
guard status == noErr else {
throw "Error reading device stream list size: \(status)"
}
var streamIDs = [AudioObjectID](
repeating: .unknown,
count: Int(dataSize) / MemoryLayout<AudioObjectID>.size
)
status = AudioObjectGetPropertyData(self, &streamsAddress, 0, nil, &dataSize, &streamIDs)
guard status == noErr else {
throw "Error reading device stream list: \(status)"
}
for streamID in streamIDs {
let direction: UInt32 = try streamID.read(
kAudioStreamPropertyDirection,
defaultValue: 0
)
guard direction == 1 else { continue }
return try streamID.read(
kAudioStreamPropertyVirtualFormat,
defaultValue: AudioStreamBasicDescription()
)
}
throw "Device has no input stream."
}
private func requireSystemObject() throws {
if self != .system { throw "Only supported for the system object." }
}
@@ -307,4 +348,4 @@ extension AudioObjectID {
func getDeviceName() throws -> String {
return try readString(kAudioDevicePropertyDeviceNameCFString)
}
}
}
+19 -7
View File
@@ -138,11 +138,11 @@ final class ProcessTap {
tapDescription = CATapDescription(stereoMixdownOfProcesses: [process.objectID])
logger.debug("Configuring tap for single process objectID: \(process.objectID)")
case .systemAudio:
// Keep the HAL tap's buffer layout consistent with the default
// output stream. AudioManager performs the stereo-to-mono mix when
// it converts the captured audio to the 16 kHz transcription file.
tapDescription = CATapDescription(stereoGlobalTapButExcludeProcesses: [])
logger.debug("Configuring a stereo global system audio tap.")
// The transcription file is mono, so ask Core Audio for a mono
// mixdown at the source. This avoids interpreting a stereo HAL
// buffer as half as many frames before the 16 kHz conversion.
tapDescription = CATapDescription(monoGlobalTapButExcludeProcesses: [])
logger.info("Configuring a mono global system audio tap.")
}
tapDescription.uuid = UUID()
@@ -248,8 +248,20 @@ final class ProcessTap {
do {
logger.debug("Attempting to read audio tap stream basic description for tapID #\(tapID)...")
self.tapStreamDescription = try tapID.readAudioTapStreamBasicDescription()
logger.debug("Successfully read tap stream description: \(String(describing: self.tapStreamDescription))")
let advertisedDescription = try tapID.readAudioTapStreamBasicDescription()
// The aggregate device may adapt the tap to the active hardware's
// sample rate. Its input stream is the format actually delivered
// to the I/O proc, so use that rather than the tap's pre-aggregate
// advertisement. Using the latter can halve the written duration
// when, for example, a 48 kHz tap is delivered at 24 kHz.
do {
self.tapStreamDescription = try aggregateDeviceID.readInputStreamBasicDescription()
logger.info("Using aggregate input stream description: \(String(describing: self.tapStreamDescription), privacy: .public); tap advertised: \(String(describing: advertisedDescription), privacy: .public)")
} catch {
self.tapStreamDescription = advertisedDescription
logger.warning("Could not read aggregate input stream format; using tap format: \(error, privacy: .public)")
}
} catch {
logger.error("Failed to read audio tap stream basic description for tapID #\(tapID): \(error)")
throw error // Propagate error