Compare commits

..
1 Commits
Author SHA1 Message Date
coder 66447b2510 fix: count Core Audio callback frames explicitly 2026-08-26 14:36:32 +02:00
2 changed files with 29 additions and 21 deletions
+4 -4
View File
@@ -276,7 +276,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 39; CURRENT_PROJECT_VERSION = 40;
DEVELOPMENT_ASSET_PATHS = "\"meetingnotes/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"meetingnotes/Preview Content\"";
DEVELOPMENT_TEAM = G9LVHZAJNX; DEVELOPMENT_TEAM = G9LVHZAJNX;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
@@ -290,7 +290,7 @@
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 15.0; MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 1.1.27; MARKETING_VERSION = 1.1.28;
ONLY_ACTIVE_ARCH = NO; ONLY_ACTIVE_ARCH = NO;
OTHER_SWIFT_FLAGS = "$(inherited) -D ENABLE_TCC_SPI"; OTHER_SWIFT_FLAGS = "$(inherited) -D ENABLE_TCC_SPI";
PRODUCT_BUNDLE_IDENTIFIER = net.jamesbone.meetingnotes; PRODUCT_BUNDLE_IDENTIFIER = net.jamesbone.meetingnotes;
@@ -312,7 +312,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 39; CURRENT_PROJECT_VERSION = 40;
DEVELOPMENT_ASSET_PATHS = "\"meetingnotes/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"meetingnotes/Preview Content\"";
DEVELOPMENT_TEAM = G9LVHZAJNX; DEVELOPMENT_TEAM = G9LVHZAJNX;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
@@ -326,7 +326,7 @@
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 15.0; MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 1.1.27; MARKETING_VERSION = 1.1.28;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "$(inherited) -D ENABLE_TCC_SPI"; OTHER_SWIFT_FLAGS = "$(inherited) -D ENABLE_TCC_SPI";
PRODUCT_BUNDLE_IDENTIFIER = net.jamesbone.meetingnotes; PRODUCT_BUNDLE_IDENTIFIER = net.jamesbone.meetingnotes;
+25 -17
View File
@@ -443,14 +443,15 @@ final class AudioManager: NSObject, ObservableObject {
let channelCount = buffers.reduce(UInt32(0)) { $0 + $1.mNumberChannels } let channelCount = buffers.reduce(UInt32(0)) { $0 + $1.mNumberChannels }
guard channelCount > 0 else { return nil } guard channelCount > 0 else { return nil }
// HAL tap metadata can advertise interleaved stereo while the callback // HAL I/O proc samples use the canonical Float32 representation. The
// supplies one mono buffer per channel (or the reverse). Constructing a // tap's stream description can advertise a different common format;
// PCM buffer with that mismatched layout halves its frame count and // using that to interpret the callback bytes can halve the frame count
// produces 2x-speed system audio. The callback's AudioBufferList is the // (for example, treating four-byte Float32 samples as eight-byte
// authoritative layout for the memory we are copying. // Float64 samples). The callback's AudioBufferList is authoritative for
// its channel layout, while its sample rate comes from the input stream.
let isInterleaved = buffers.count == 1 && channelCount > 1 let isInterleaved = buffers.count == 1 && channelCount > 1
return AVAudioFormat( return AVAudioFormat(
commonFormat: advertisedFormat.commonFormat, commonFormat: .pcmFormatFloat32,
sampleRate: advertisedFormat.sampleRate, sampleRate: advertisedFormat.sampleRate,
channels: AVAudioChannelCount(channelCount), channels: AVAudioChannelCount(channelCount),
interleaved: isInterleaved interleaved: isInterleaved
@@ -461,20 +462,27 @@ final class AudioManager: NSObject, ObservableObject {
from inputData: UnsafePointer<AudioBufferList>, from inputData: UnsafePointer<AudioBufferList>,
format: AVAudioFormat format: AVAudioFormat
) -> AVAudioPCMBuffer? { ) -> AVAudioPCMBuffer? {
guard let borrowedBuffer = AVAudioPCMBuffer(
pcmFormat: format,
bufferListNoCopy: inputData,
deallocator: nil
), borrowedBuffer.frameLength > 0,
let ownedBuffer = AVAudioPCMBuffer(
pcmFormat: format,
frameCapacity: borrowedBuffer.frameLength
) else { return nil }
ownedBuffer.frameLength = borrowedBuffer.frameLength
let sourceBuffers = UnsafeMutableAudioBufferListPointer( let sourceBuffers = UnsafeMutableAudioBufferListPointer(
UnsafeMutablePointer(mutating: inputData) UnsafeMutablePointer(mutating: inputData)
) )
let frameLengths = sourceBuffers.compactMap { source -> AVAudioFrameCount? in
let bytesPerFrame = Int(source.mNumberChannels) * MemoryLayout<Float32>.size
guard bytesPerFrame > 0,
Int(source.mDataByteSize).isMultiple(of: bytesPerFrame) else { return nil }
return AVAudioFrameCount(Int(source.mDataByteSize) / bytesPerFrame)
}
guard frameLengths.count == sourceBuffers.count,
let frameLength = frameLengths.first,
frameLength > 0,
frameLengths.allSatisfy({ $0 == frameLength }),
let ownedBuffer = AVAudioPCMBuffer(
pcmFormat: format,
frameCapacity: frameLength
) else { return nil }
// Set the frame count explicitly instead of asking AVAudioPCMBuffer to
// infer it from potentially inconsistent tap metadata.
ownedBuffer.frameLength = frameLength
let destinationBuffers = UnsafeMutableAudioBufferListPointer( let destinationBuffers = UnsafeMutableAudioBufferListPointer(
ownedBuffer.mutableAudioBufferList ownedBuffer.mutableAudioBufferList
) )