From d807b2069af94ba12c5e817ab6a240b54727bb63 Mon Sep 17 00:00:00 2001 From: HugeFrog24 <62775760+HugeFrog24@users.noreply.github.com> Date: Sat, 17 Oct 2026 14:55:23 +0200 Subject: [PATCH] Fix recorded audio stutter by sizing the audio buffer like vanilla The game copies one FMOD block of 16-bit stereo samples into the audio direct buffer per write and never checks its capacity, and the encoder queues the whole buffer. Vanilla sizes that buffer from the 10th StartRecording argument (1024 bytes when set, 2048 otherwise); Canvas dropped the argument and always used 2048, so each 1024-byte block was queued with 1024 stale bytes. Forward the argument to createAudioCodec as vanilla 0.34.5 to 0.35.1 does. --- app/src/main/java/com/tgc/sky/SystemIO_android.java | 4 ++-- app/src/main/java/com/tgc/sky/ui/NtVideoRecorder.java | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/tgc/sky/SystemIO_android.java b/app/src/main/java/com/tgc/sky/SystemIO_android.java index 1beecc8..a47a72b 100644 --- a/app/src/main/java/com/tgc/sky/SystemIO_android.java +++ b/app/src/main/java/com/tgc/sky/SystemIO_android.java @@ -647,7 +647,7 @@ public boolean StartRecording(String str, int i, int i2, int i3, boolean z, int if (this.m_videoRecorder == null) { return false; } - return this.m_videoRecorder.startRecordingWithFilename(str, i, i2, str2, i4, z2, i5, z3); + return this.m_videoRecorder.startRecordingWithFilename(str, i, i2, str2, i4, z2, i5, z3, z4); } public boolean StartRecording(String str, int i, int i2, int i3, boolean z, int i4, boolean z2, int i5, boolean z3) { @@ -664,7 +664,7 @@ public boolean StartRecording(String str, int i, int i2, int i3, int i4, boolean if (this.m_videoRecorder == null) { return false; } - return this.m_videoRecorder.startRecordingWithFilename(str, i, i2, str2, i4, z, i5, z2); + return this.m_videoRecorder.startRecordingWithFilename(str, i, i2, str2, i4, z, i5, z2, false); } diff --git a/app/src/main/java/com/tgc/sky/ui/NtVideoRecorder.java b/app/src/main/java/com/tgc/sky/ui/NtVideoRecorder.java index 626b5a4..f7df2b3 100644 --- a/app/src/main/java/com/tgc/sky/ui/NtVideoRecorder.java +++ b/app/src/main/java/com/tgc/sky/ui/NtVideoRecorder.java @@ -280,13 +280,14 @@ private boolean createVideoCodec(String str, int i, int i2) { } } - private boolean createAudioCodec() { - this.m_audioByteBuffer = ByteBuffer.allocateDirect(2048); + private boolean createAudioCodec(boolean z) { + int i = z ? 1024 : 2048; + this.m_audioByteBuffer = ByteBuffer.allocateDirect(i); this.m_audioBufferInfo = new MediaCodec.BufferInfo(); MediaFormat createAudioFormat = MediaFormat.createAudioFormat("audio/mp4a-latm", 24000, 2); createAudioFormat.setInteger("bitrate", 768000); createAudioFormat.setInteger("aac-profile", 2); - createAudioFormat.setInteger("max-input-size", 2048); + createAudioFormat.setInteger("max-input-size", i); try { MediaCodec createEncoderByType = MediaCodec.createEncoderByType("audio/mp4a-latm"); this.m_audioCodec = createEncoderByType; @@ -297,7 +298,7 @@ private boolean createAudioCodec() { } } - public boolean startRecordingWithFilename(String str, int i, int i2, String str2, int i3, boolean z, int i4, boolean z2) { + public boolean startRecordingWithFilename(String str, int i, int i2, String str2, int i3, boolean z, int i4, boolean z2, boolean z3) { if (this.m_isRecording || str == null || !str.endsWith(".mp4")) { return false; } @@ -309,7 +310,7 @@ public boolean startRecordingWithFilename(String str, int i, int i2, String str2 if (findCurrentFileName == "" || !createOrRecreateFile(findCurrentFileName) || !createVideoCodec(findCurrentFileName, i3, i4)) { return false; } - if (this.m_isRecordAudio && !createAudioCodec()) { + if (this.m_isRecordAudio && !createAudioCodec(z3)) { return false; } this.m_videoCodec.start();