From 6dc29725a121624357ec78c03fe5ae899d7b7d63 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Tue, 22 Jul 2025 14:04:01 +0200 Subject: [PATCH] SoX is of course right --- wav.hh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/wav.hh b/wav.hh index 614b964..d803eca 100644 --- a/wav.hh +++ b/wav.hh @@ -91,7 +91,7 @@ public: if (cmp4("data", Subchunk2ID)) return; int Subchunk2Size = readLE(4); - int overhead = bits_ == 32 ? 50 : 36; + int overhead = bits_ == 32 ? 58 : 44; if (Subchunk2Size + overhead > ChunkSize) return; if (Subchunk1Size == 16) @@ -228,16 +228,17 @@ public: } ~WriteWAV() { - int overhead = bytes == 4 ? 50 : 36; - int size = int(os.tellp()) - overhead; + int overhead = bytes == 4 ? 58 : 44; + int position = int(os.tellp()); + int size = position - overhead; os.seekp(4); - writeLE(overhead + size, 4); // ChunkSize + writeLE(position - 8, 4); // ChunkSize if (bytes == 4) { os.seekp(46); int frames = size / (bytes * channels_); writeLE(frames, 4); // FrameCount } - os.seekp(overhead + 4); + os.seekp(overhead - 4); writeLE(size, 4); // Subchunk2Size } void write(const TYPE *buf, int num, int stride = -1)