From ba9ceeea90c1a5d34ca6f9a0eea6fbad539bcd96 Mon Sep 17 00:00:00 2001 From: locpham Date: Tue, 18 Aug 2026 17:35:54 +0700 Subject: [PATCH] fix(bridge): WAV header data_size for IEEE float32 (was 16-bit byte count) - finishWav call sites accumulated n*4 (stereo 16-bit) but float32 writer emits n*8 bytes -> RIFF/data chunk sizes half the real value; players and soundfile truncated renders to half length - gate test now asserts file size == 44 + data_size to catch this --- native_bridge/src/RenderFxJob.cpp | 2 +- native_bridge/src/RenderJob.cpp | 2 +- tests/test_lossless_compliance.py | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/native_bridge/src/RenderFxJob.cpp b/native_bridge/src/RenderFxJob.cpp index 82faa88..dcf9092 100644 --- a/native_bridge/src/RenderFxJob.cpp +++ b/native_bridge/src/RenderFxJob.cpp @@ -881,7 +881,7 @@ int run_render_fx_job(const std::string& jobPath, const std::string& inPath, for (uint64_t pos = 0; pos < in.L.size(); pos += chunk) { const uint32_t n = (uint32_t)std::min(chunk, in.L.size() - pos); writeFrames(wav, in.L.data() + pos, in.R.data() + pos, n); - dataBytes += (uint64_t)n * 4; + dataBytes += (uint64_t)n * 8; // stereo float32: 2ch * 4B } finishWav(wav, dataBytes); wav.close(); diff --git a/native_bridge/src/RenderJob.cpp b/native_bridge/src/RenderJob.cpp index 65c8aee..9b8dd84 100644 --- a/native_bridge/src/RenderJob.cpp +++ b/native_bridge/src/RenderJob.cpp @@ -388,7 +388,7 @@ int run_render_job(const std::string& jobPath, const std::string& outPath) { const uint32_t n = (uint32_t)(to - from); mgr.renderAll(L.data(), R.data(), n); writeFrames(wav, L.data(), R.data(), n); - dataBytes += (uint64_t)n * 4; + dataBytes += (uint64_t)n * 8; // stereo float32: 2ch * 4B }; while (pos < totalNeeded) { const uint64_t chunkEnd = std::min(pos + chunk, (uint64_t)totalNeeded); diff --git a/tests/test_lossless_compliance.py b/tests/test_lossless_compliance.py index c2b8011..00d643f 100644 --- a/tests/test_lossless_compliance.py +++ b/tests/test_lossless_compliance.py @@ -43,6 +43,8 @@ def wav_format_info(path): with open(path, "rb") as f: b = f.read(44) assert b[:4] == b"RIFF" and b[8:12] == b"WAVE", "not RIFF/WAVE" + data_size = struct.unpack_from("