From d855038fd44052214a86c46abf823fe488946fa1 Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Sun, 21 Sep 2025 17:42:31 +0200 Subject: [PATCH] Fix incorrect MP3 frame size calculation (fixes #140) --- shared/mp3-misc.ts | 6 +++--- src/input-format.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shared/mp3-misc.ts b/shared/mp3-misc.ts index 9ab974a..19fd947 100644 --- a/shared/mp3-misc.ts +++ b/shared/mp3-misc.ts @@ -52,11 +52,11 @@ export const computeMp3FrameSize = ( if (layer === 0) { return 0; // Not expected that this is hit } else if (layer === 1) { - return Math.round(144 * bitrate / (sampleRate << lowSamplingFrequency)) + padding; + return Math.floor(144 * bitrate / (sampleRate << lowSamplingFrequency)) + padding; } else if (layer === 2) { - return Math.round(144 * bitrate / sampleRate) + padding; + return Math.floor(144 * bitrate / sampleRate) + padding; } else { // layer === 3 - return (Math.round(12 * bitrate / sampleRate) + padding) * 4; + return (Math.floor(12 * bitrate / sampleRate) + padding) * 4; } }; diff --git a/src/input-format.ts b/src/input-format.ts index 6d9c258..5cfe902 100644 --- a/src/input-format.ts +++ b/src/input-format.ts @@ -289,7 +289,7 @@ export class Mp3InputFormat extends InputFormat { return true; } - currentPos = firstResult.startPos += firstResult.header.totalSize; + currentPos = firstResult.startPos + firstResult.header.totalSize; // Fine, we found one frame header, but we're still not entirely sure this is MP3. Let's check if we can find // another header right after it: