Create polished demo videos without editing skills. Mac/Windows/Linux
Bound gap recovery work and tighten alignment checks
webadderall9fc4df1bdbc9
diff --git a/electron/native/AudioSampleQueue.test.ts b/electron/native/AudioSampleQueue.test.tsindex b746274e..f43989a1 100644--- a/electron/native/AudioSampleQueue.test.ts+++ b/electron/native/AudioSampleQueue.test.ts@@ -160,10 +160,12 @@ done.wait()])("keeps %s audio one second long and its later tone aligned", (name) => {expect(results[name].frames / 48_000).toBeCloseTo(1, 1);expect(results[name].marker).toBeCloseTo(0.7, 1);+ expect(results[name].marker - results.contiguous.marker).toBeCloseTo(0, 2);});it("keeps later speech aligned after sustained overload exceeds the queue limit", () => {expect(results.overflow.frames / 48_000).toBeCloseTo(4, 1);expect(results.overflow.marker).toBeCloseTo(3.7, 1);+ expect(results.overflow.marker - results.contiguous.marker).toBeCloseTo(3, 2);});it("preserves an actual missing interval as silence", () => {expect(results.gap.silentGap).toBe(true);diff --git a/electron/native/ScreenCaptureKitRecorder.swift b/electron/native/ScreenCaptureKitRecorder.swiftindex b7c89d4d..9bc551d3 100644--- a/electron/native/ScreenCaptureKitRecorder.swift+++ b/electron/native/ScreenCaptureKitRecorder.swift@@ -66,7 +66,7 @@ final class AudioSampleQueue {let format = buffer.formatDescription,let asbd = format.audioStreamBasicDescription,asbd.mFormatID == kAudioFormatLinearPCM,- asbd.mSampleRate.isFinite, asbd.mSampleRate > 0,+ asbd.mSampleRate.isFinite, asbd.mSampleRate > 0, asbd.mSampleRate <= Double(Int32.max),time.isValid, time.seconds.isFinite else {failure = failure ?? audioError("Invalid PCM audio buffer")return@@ -133,7 +133,7 @@ final class AudioSampleQueue {guard fillSilence(to: next.time, format: format) else { return }guard failure == nil, isReady() else { return }// Trim overlapping or repeated samples instead of writing time twice.- let overlap = max(0, Int(((endTime - next.time).seconds * asbd.mSampleRate).rounded()))+ let overlap = Int(min(Double(next.buffer.numSamples), max(0, ((endTime - next.time).seconds * asbd.mSampleRate).rounded())))let skip = overlap <= 1 ? 0 : overlap // CMTime(seconds:) can round adjacent timestamps by one frame.if skip < next.buffer.numSamples {do {@@ -169,7 +169,7 @@ final class AudioSampleQueue {var chunksRemaining = 16while isReady(), failure == nil, chunksRemaining > 0 {chunksRemaining -= 1- let frames = min(4096, Int64(((target - endTime).seconds * asbd.mSampleRate).rounded()))+ let frames = Int64(min(4096, max(0, ((target - endTime).seconds * asbd.mSampleRate).rounded())))guard frames > 0 else {// Avoid sub-sample rounding leaving finish in a retry loop.if target > endTime { endTime = target }