mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-29 20:03:48 +02:00
* Read ID3v2 tags from WAV file * remove js import Co-authored-by: David P. <[email protected]> * revert slicing in wave-demuxer.ts and add id3.ts for further sharing * Add `writeId3Tag` to the `WavOutputFormat` constructor options * add more context in private and public APIs that it's non-standard * compare actual values in the test with real file * remove unnecesarry double slice requesting * trim test audio file (i tried my best to preserve ID3, including artwork) * Couple of code cleanups * const -> using * Fix linting errors --------- Co-authored-by: David P. <[email protected]>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
/*!
|
|
* Copyright (c) 2025-present, Vanilagy and contributors
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
import { FRAME_HEADER_SIZE, FrameHeader, readFrameHeader } from '../../shared/mp3-misc';
|
|
import { Reader, readU32Be } from '../reader';
|
|
|
|
export const readNextFrameHeader = async (reader: Reader, startPos: number, until: number | null): Promise<{
|
|
header: FrameHeader;
|
|
startPos: number;
|
|
} | null> => {
|
|
let currentPos = startPos;
|
|
|
|
while (until === null || currentPos < until) {
|
|
let slice = reader.requestSlice(currentPos, FRAME_HEADER_SIZE);
|
|
if (slice instanceof Promise) slice = await slice;
|
|
if (!slice) break;
|
|
|
|
const word = readU32Be(slice);
|
|
|
|
const result = readFrameHeader(word, reader.fileSize !== null ? reader.fileSize - currentPos : null);
|
|
if (result.header) {
|
|
return { header: result.header, startPos: currentPos };
|
|
}
|
|
|
|
currentPos += result.bytesAdvanced;
|
|
}
|
|
|
|
return null;
|
|
};
|