Fix potential crashes and silent failures in audio recording: guard against division by zero in audio metering, check ExtAudioFileWrite return status, and safely unwrap downloads directory
This commit is contained in:
parent
c530367a04
commit
8fce0475a5
@ -586,11 +586,14 @@ final class CoreAudioRecorder {
|
||||
|
||||
private func calculateMeters(from bufferList: inout AudioBufferList, frameCount: UInt32) {
|
||||
guard let data = bufferList.mBuffers.mData else { return }
|
||||
guard frameCount > 0 else { return }
|
||||
|
||||
let samples = data.assumingMemoryBound(to: Float32.self)
|
||||
let channelCount = Int(deviceFormat.mChannelsPerFrame)
|
||||
let totalSamples = Int(frameCount) * channelCount
|
||||
|
||||
guard totalSamples > 0 else { return }
|
||||
|
||||
var sum: Float = 0.0
|
||||
var peak: Float = 0.0
|
||||
|
||||
@ -683,7 +686,10 @@ final class CoreAudioRecorder {
|
||||
)
|
||||
)
|
||||
|
||||
ExtAudioFileWrite(file, outputFrameCount, &outputBufferList)
|
||||
let writeStatus = ExtAudioFileWrite(file, outputFrameCount, &outputBufferList)
|
||||
if writeStatus != noErr {
|
||||
logger.error("🎙️ ExtAudioFileWrite failed with status: \(writeStatus)")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Device Info Logging
|
||||
|
||||
@ -101,7 +101,9 @@ final class LogExporter {
|
||||
let fileName = "VoiceInk_Logs_\(timestamp).log"
|
||||
|
||||
// Get Downloads folder
|
||||
let downloadsURL = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first!
|
||||
guard let downloadsURL = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first else {
|
||||
throw NSError(domain: "LogExporter", code: 1, userInfo: [NSLocalizedDescriptionKey: "Downloads directory unavailable"])
|
||||
}
|
||||
let fileURL = downloadsURL.appendingPathComponent(fileName)
|
||||
|
||||
let content = logs.joined(separator: "\n")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user